diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/CreateInfoAuctionDto.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/CreateInfoAuctionDto.java index a86d23dcf..f044074a1 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/CreateInfoAuctionDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/CreateInfoAuctionDto.java @@ -1,11 +1,12 @@ package com.ddang.ddang.auction.application.dto; import com.ddang.ddang.auction.domain.Auction; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; public record CreateInfoAuctionDto( Long id, String title, - Long auctionImageId, + String auctionStoreName, int startPrice ) { @@ -13,7 +14,7 @@ public static CreateInfoAuctionDto from(final Auction auction) { return new CreateInfoAuctionDto( auction.getId(), auction.getTitle(), - auction.getAuctionImages().get(0).getId(), + ImageStoreNameProcessor.process(auction.getAuctionImages().get(0)), auction.getStartPrice().getValue() ); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java index d5be76317..e56decd82 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java @@ -3,8 +3,7 @@ import com.ddang.ddang.auction.domain.Auction; import com.ddang.ddang.auction.domain.AuctionStatus; import com.ddang.ddang.bid.domain.Bid; -import com.ddang.ddang.image.application.util.ImageIdProcessor; -import com.ddang.ddang.image.domain.AuctionImage; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import java.time.LocalDateTime; import java.util.List; @@ -20,12 +19,12 @@ public record ReadAuctionDto( LocalDateTime registerTime, LocalDateTime closingTime, List auctionRegions, - List auctionImageIds, + List auctionImageStoreNames, int auctioneerCount, String mainCategory, String subCategory, Long sellerId, - Long sellerProfileId, + String sellerProfileImageStoreName, String sellerName, double sellerReliability, boolean isSellerDeleted, @@ -45,12 +44,12 @@ public static ReadAuctionDto of(final Auction auction, final LocalDateTime targe auction.getCreatedTime(), auction.getClosingTime(), convertReadRegionsDto(auction), - convertImageIds(auction), + convertImageStoreNames(auction), auction.getAuctioneerCount(), auction.getSubCategory().getMainCategory().getName(), auction.getSubCategory().getName(), auction.getSeller().getId(), - ImageIdProcessor.process(auction.getSeller().getProfileImage()), + ImageStoreNameProcessor.process(auction.getSeller().getProfileImage()), auction.getSeller().getName(), auction.getSeller().getReliability().getValue(), auction.getSeller().isDeleted(), @@ -59,10 +58,10 @@ public static ReadAuctionDto of(final Auction auction, final LocalDateTime targe ); } - private static List convertImageIds(final Auction auction) { + private static List convertImageStoreNames(final Auction auction) { return auction.getAuctionImages() .stream() - .map(AuctionImage::getId) + .map(ImageStoreNameProcessor::process) .toList(); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepository.java index 8ccb8660f..b4a9271ee 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/JpaAuctionRepository.java @@ -19,7 +19,8 @@ public interface JpaAuctionRepository extends JpaRepository { LEFT JOIN FETCH a.lastBid JOIN FETCH a.subCategory sc JOIN FETCH sc.mainCategory - JOIN FETCH a.seller + JOIN FETCH a.seller seller + LEFT JOIN FETCH seller.profileImage WHERE a.deleted = false AND a.id = :id """) Optional findTotalAuctionById(final Long id); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepository.java index 4ef4f2d15..b919e9f32 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/infrastructure/persistence/QuerydslAuctionRepository.java @@ -148,6 +148,7 @@ private List findAuctionsByIdsAndOrderSpecifiers( .join(auction.subCategory, category).fetchJoin() .join(category.mainCategory).fetchJoin() .join(auction.seller).fetchJoin() + .join(auction.seller.profileImage).fetchJoin() .where(auction.id.in(targetIds.toArray(Long[]::new))) .orderBy(orderSpecifiers.toArray(OrderSpecifier[]::new)) .fetch(); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/AuctionDetailResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/AuctionDetailResponse.java index b4092b2e5..689c548e8 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/AuctionDetailResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/AuctionDetailResponse.java @@ -57,9 +57,9 @@ public static AuctionDetailResponse from(final ReadAuctionDto dto) { } private static List convertImageFullUrls(final ReadAuctionDto dto) { - return dto.auctionImageIds() + return dto.auctionImageStoreNames() .stream() - .map(id -> ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, id)) + .map(imageStoreName -> ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, imageStoreName)) .toList(); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/CreateAuctionResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/CreateAuctionResponse.java index 2f3c0c9d2..19d4d087e 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/CreateAuctionResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/CreateAuctionResponse.java @@ -18,14 +18,14 @@ public static CreateAuctionResponse from(final CreateInfoAuctionDto dto) { return new CreateAuctionResponse( dto.id(), dto.title(), - convertAuctionImageUrl(dto.auctionImageId()), + convertAuctionImageUrl(dto.auctionStoreName()), dto.startPrice(), AuctionStatus.UNBIDDEN.name(), 0 ); } - private static String convertAuctionImageUrl(final Long id) { - return ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, id); + private static String convertAuctionImageUrl(final String storeName) { + return ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, storeName); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadAuctionResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadAuctionResponse.java index 4eee887ff..035e1cd63 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadAuctionResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadAuctionResponse.java @@ -17,7 +17,7 @@ public static ReadAuctionResponse from(final ReadAuctionDto dto) { return new ReadAuctionResponse( dto.id(), dto.title(), - ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, dto.auctionImageIds().get(0)), + ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, dto.auctionImageStoreNames().get(0)), processAuctionPrice(dto.startPrice(), dto.lastBidPrice()), dto.auctionStatus().name(), dto.auctioneerCount() diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadUserInAuctionQuestionResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadUserInAuctionQuestionResponse.java index 336306eb2..e637071aa 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadUserInAuctionQuestionResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ReadUserInAuctionQuestionResponse.java @@ -11,7 +11,7 @@ public static ReadUserInAuctionQuestionResponse from(final ReadUserInQnaDto writ return new ReadUserInAuctionQuestionResponse( writerDto.id(), NameProcessor.process(writerDto.isDeleted(), writerDto.name()), - ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, writerDto.profileImageId()) + ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, writerDto.profileImageStoreName()) ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/SellerResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/SellerResponse.java index 3e6c432bd..7118ded9d 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/SellerResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/SellerResponse.java @@ -16,7 +16,7 @@ public record SellerResponse( public static SellerResponse from(final ReadAuctionDto auctionDto) { return new SellerResponse( auctionDto.sellerId(), - ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, auctionDto.sellerProfileId()), + ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, auctionDto.sellerProfileImageStoreName()), NameProcessor.process(auctionDto.isSellerDeleted(), auctionDto.sellerName()), ReliabilityProcessor.process(auctionDto.sellerReliability()) ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java b/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java index d4cf89c82..ecb82854f 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java @@ -1,14 +1,14 @@ package com.ddang.ddang.bid.application.dto; import com.ddang.ddang.bid.domain.Bid; -import com.ddang.ddang.image.application.util.ImageIdProcessor; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; import java.time.LocalDateTime; public record ReadBidDto( String name, - Long profileImageId, + String profileImageStoreName, boolean isDeletedUser, int price, LocalDateTime bidTime @@ -19,7 +19,7 @@ public static ReadBidDto from(final Bid bid) { return new ReadBidDto( bidder.getName(), - ImageIdProcessor.process(bidder.getProfileImage()), + ImageStoreNameProcessor.process(bidder.getProfileImage()), bidder.isDeleted(), bid.getPrice().getValue(), bid.getCreatedTime() diff --git a/backend/ddang/src/main/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepository.java index 9c3a2e690..bf5f9824d 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/bid/infrastructure/persistence/JpaBidRepository.java @@ -10,6 +10,13 @@ public interface JpaBidRepository extends JpaRepository { + @Query(""" + SELECT bid + FROM Bid bid + JOIN FETCH bid.bidder bidder + LEFT JOIN FETCH bidder.profileImage + WHERE bid.auction.id = :auctionId ORDER BY bid.id ASC + """) List findAllByAuctionIdOrderByIdAsc(final Long auctionId); @Query("SELECT b FROM Bid b WHERE b.auction.id = :auctionId ORDER BY b.id DESC LIMIT 1") diff --git a/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java index 6f75d741f..2edc112b9 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java @@ -23,7 +23,7 @@ public static ReadBidResponse from(final ReadBidDto dto) { final String name = NameProcessor.process(dto.isDeletedUser(), dto.name()); return new ReadBidResponse( name, - ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, dto.profileImageId()), + ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, dto.profileImageStoreName()), dto.price(), dto.bidTime() ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java index 9d9045ecb..39e1498db 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java @@ -38,7 +38,7 @@ public Long create(final CreateMessageDto dto, final String profileImageAbsolute final ChatRoom chatRoom = chatRoomRepository.findById(dto.chatRoomId()) .orElseThrow(() -> new ChatRoomNotFoundException( "지정한 아이디에 대한 채팅방을 찾을 수 없습니다.")); - final User writer = userRepository.findById(dto.writerId()) + final User writer = userRepository.findByIdWithProfileImage(dto.writerId()) .orElseThrow(() -> new UserNotFoundException( "지정한 아이디에 대한 발신자를 찾을 수 없습니다.")); final User receiver = userRepository.findById(dto.receiverId()) diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadAuctionInChatRoomDto.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadAuctionInChatRoomDto.java index 233215c83..b39489800 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadAuctionInChatRoomDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadAuctionInChatRoomDto.java @@ -2,13 +2,14 @@ import com.ddang.ddang.auction.domain.Auction; import com.ddang.ddang.bid.domain.Bid; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.image.domain.AuctionImage; public record ReadAuctionInChatRoomDto( Long id, String title, Integer lastBidPrice, - Long thumbnailImageId + String thumbnailImageStoreName ) { public static ReadAuctionInChatRoomDto of(final Auction auction, final AuctionImage thumbnailImage) { @@ -16,7 +17,7 @@ public static ReadAuctionInChatRoomDto of(final Auction auction, final AuctionIm auction.getId(), auction.getTitle(), convertPrice(auction.getLastBid()), - thumbnailImage.getId() + ImageStoreNameProcessor.process(thumbnailImage) ); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java index 604827146..40c76de30 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java @@ -1,15 +1,15 @@ package com.ddang.ddang.chat.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; -public record ReadUserInChatRoomDto(Long id, String name, Long profileImageId, double reliability, boolean isDeleted) { +public record ReadUserInChatRoomDto(Long id, String name, String profileImageStoreName, double reliability, boolean isDeleted) { public static ReadUserInChatRoomDto from(final User user) { return new ReadUserInChatRoomDto( user.getId(), user.getName(), - ImageIdProcessor.process(user.getProfileImage()), + ImageStoreNameProcessor.process(user.getProfileImage()), user.getReliability().getValue(), user.isDeleted() ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndImageRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndImageRepository.java index cfdd83e9e..6c74526ed 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndImageRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndImageRepository.java @@ -25,9 +25,10 @@ public Optional findChatRoomById(final Long chatRoomId) { final ChatRoomAndImageQueryProjectionDto chatRoomAndImageQueryProjectionDto = queryFactory.select(new QChatRoomAndImageQueryProjectionDto(chatRoom, auctionImage)) .from(chatRoom) - .leftJoin(chatRoom.buyer).fetchJoin() - .leftJoin(chatRoom.auction, auction).fetchJoin() - .leftJoin(auction.seller).fetchJoin() + .join(chatRoom.buyer).fetchJoin() + .join(chatRoom.auction, auction).fetchJoin() + .join(auction.seller).fetchJoin() + .leftJoin(auction.seller.profileImage).fetchJoin() .leftJoin(auctionImage).on(auctionImage.id.eq( JPAExpressions .select(auctionImage.id.min()) @@ -35,7 +36,7 @@ public Optional findChatRoomById(final Long chatRoomId) { .where(auctionImage.auction.id.eq(auction.id)) .groupBy(auctionImage.auction.id) )).fetchJoin() - .leftJoin(auction.lastBid).fetchJoin() + .join(auction.lastBid).fetchJoin() .where(chatRoom.id.eq(chatRoomId)) .fetchOne(); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepository.java index 1a6e3b4d8..35b342770 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/infrastructure/persistence/QuerydslChatRoomAndMessageAndImageRepository.java @@ -35,9 +35,10 @@ public List findAllChatRoomInfoByUserIdOrderByLas auctionImage, countUnreadMessages(userId, chatRoom.id) )).from(chatRoom) - .leftJoin(chatRoom.buyer).fetchJoin() - .leftJoin(chatRoom.auction, auction).fetchJoin() - .leftJoin(auction.seller).fetchJoin() + .join(chatRoom.buyer).fetchJoin() + .join(chatRoom.auction, auction).fetchJoin() + .join(auction.seller).fetchJoin() + .leftJoin(auction.seller.profileImage).fetchJoin() .leftJoin(auctionImage).on(auctionImage.id.eq( JPAExpressions .select(auctionImage.id.min()) @@ -45,7 +46,7 @@ public List findAllChatRoomInfoByUserIdOrderByLas .where(auctionImage.auction.id.eq(auction.id)) .groupBy(auctionImage.auction.id) )).fetchJoin() - .leftJoin(auction.lastBid).fetchJoin() + .join(auction.lastBid).fetchJoin() .leftJoin(message).on(message.id.eq( JPAExpressions .select(message.id.max()) diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadAuctionInChatRoomResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadAuctionInChatRoomResponse.java index be45b0034..3f5d27c00 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadAuctionInChatRoomResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadAuctionInChatRoomResponse.java @@ -7,7 +7,7 @@ public record ReadAuctionInChatRoomResponse(Long id, String title, String image, int price) { public static ReadAuctionInChatRoomResponse from(final ReadAuctionInChatRoomDto dto) { - final String thumbNailImageUrl = ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, dto.thumbnailImageId()); + final String thumbNailImageUrl = ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, dto.thumbnailImageStoreName()); return new ReadAuctionInChatRoomResponse(dto.id(), dto.title(), thumbNailImageUrl, dto.lastBidPrice()); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java index 2a2daab62..95b540d68 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java @@ -13,7 +13,7 @@ public static ReadChatPartnerResponse from(final ReadUserInChatRoomDto dto) { return new ReadChatPartnerResponse( dto.id(), name, - ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, dto.profileImageId()) + ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, dto.profileImageStoreName()) ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/application/ImageService.java b/backend/ddang/src/main/java/com/ddang/ddang/image/application/ImageService.java index 7b9f240e3..8b2a11c3a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/application/ImageService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/application/ImageService.java @@ -1,7 +1,5 @@ package com.ddang.ddang.image.application; -import com.ddang.ddang.image.domain.AuctionImage; -import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.domain.repository.AuctionImageRepository; import com.ddang.ddang.image.domain.repository.ProfileImageRepository; import lombok.RequiredArgsConstructor; @@ -25,28 +23,22 @@ public class ImageService { private final ProfileImageRepository profileImageRepository; private final AuctionImageRepository auctionImageRepository; - public Resource readProfileImage(final Long id) throws MalformedURLException { - final ProfileImage profileImage = profileImageRepository.findById(id) - .orElse(null); - - if (profileImage == null) { + public Resource readProfileImage(final String storeName) throws MalformedURLException { + if (!profileImageRepository.existsByStoreName(storeName)) { return null; } - final String fullPath = findFullPath(profileImage.getImage().getStoreName()); + final String fullPath = findFullPath(storeName); return new UrlResource(FILE_PROTOCOL_PREFIX + fullPath); } - public Resource readAuctionImage(final Long id) throws MalformedURLException { - final AuctionImage auctionImage = auctionImageRepository.findById(id) - .orElse(null); - - if (auctionImage == null) { + public Resource readAuctionImage(final String storeName) throws MalformedURLException { + if (!auctionImageRepository.existsByStoreName(storeName)) { return null; } - final String fullPath = findFullPath(auctionImage.getImage().getStoreName()); + final String fullPath = findFullPath(storeName); return new UrlResource(FILE_PROTOCOL_PREFIX + fullPath); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageIdProcessor.java b/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageIdProcessor.java deleted file mode 100644 index 4492fb6f2..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageIdProcessor.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.ddang.ddang.image.application.util; - -import com.ddang.ddang.image.domain.AuctionImage; -import com.ddang.ddang.image.domain.ProfileImage; - -public final class ImageIdProcessor { - - private ImageIdProcessor() { - } - - public static Long process(final ProfileImage profileImage) { - if (profileImage == null) { - return null; - } - - return profileImage.getId(); - } - - public static Long process(final AuctionImage auctionImage) { - if (auctionImage == null) { - return null; - } - - return auctionImage.getId(); - } -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageStoreNameProcessor.java b/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageStoreNameProcessor.java new file mode 100644 index 000000000..1b59b36ea --- /dev/null +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageStoreNameProcessor.java @@ -0,0 +1,26 @@ +package com.ddang.ddang.image.application.util; + +import com.ddang.ddang.image.domain.AuctionImage; +import com.ddang.ddang.image.domain.ProfileImage; + +public final class ImageStoreNameProcessor { + + private ImageStoreNameProcessor() { + } + + public static String process(final ProfileImage profileImage) { + if (profileImage == null) { + return null; + } + + return profileImage.getImage().getStoreName(); + } + + public static String process(final AuctionImage auctionImage) { + if (auctionImage == null) { + return null; + } + + return auctionImage.getImage().getStoreName(); + } +} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/domain/ProfileImage.java b/backend/ddang/src/main/java/com/ddang/ddang/image/domain/ProfileImage.java index d85c01c1e..e45936a8c 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/domain/ProfileImage.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/domain/ProfileImage.java @@ -19,8 +19,6 @@ public class ProfileImage { public static final String DEFAULT_PROFILE_IMAGE_STORE_NAME = "default_profile_image.png"; - // TODO: 10/13/23 앞으로 id가 아닌 store name으로 진행하기로 했는데, 임시로 해둡니다. 추후 삭제해주시면 감사하겠습니다. - public static final String DEFAULT_PROFILE_IMAGE_ID = "1"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/AuctionImageRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/AuctionImageRepository.java index 586bca166..8fb1333c1 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/AuctionImageRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/AuctionImageRepository.java @@ -1,10 +1,6 @@ package com.ddang.ddang.image.domain.repository; -import com.ddang.ddang.image.domain.AuctionImage; - -import java.util.Optional; - public interface AuctionImageRepository { - Optional findById(final Long id); + boolean existsByStoreName(final String storeName); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/ProfileImageRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/ProfileImageRepository.java index b0491a5d6..5fde626b0 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/ProfileImageRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/domain/repository/ProfileImageRepository.java @@ -1,12 +1,6 @@ package com.ddang.ddang.image.domain.repository; -import com.ddang.ddang.image.domain.ProfileImage; - -import java.util.Optional; - public interface ProfileImageRepository { - Optional findById(final Long id); - - Optional findByStoreName(final String storeName); + boolean existsByStoreName(final String storeName); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImpl.java b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImpl.java index c24799bca..913ac97d2 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImpl.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImpl.java @@ -1,12 +1,9 @@ package com.ddang.ddang.image.infrastructure.persistence; -import com.ddang.ddang.image.domain.AuctionImage; import com.ddang.ddang.image.domain.repository.AuctionImageRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; -import java.util.Optional; - @Repository @RequiredArgsConstructor public class AuctionImageRepositoryImpl implements AuctionImageRepository { @@ -14,7 +11,7 @@ public class AuctionImageRepositoryImpl implements AuctionImageRepository { private final JpaAuctionImageRepository jpaAuctionImageRepository; @Override - public Optional findById(final Long id) { - return jpaAuctionImageRepository.findById(id); + public boolean existsByStoreName(final String storeName) { + return jpaAuctionImageRepository.existsByStoreName(storeName); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepository.java index 87f345983..fe0210243 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepository.java @@ -2,6 +2,14 @@ import com.ddang.ddang.image.domain.AuctionImage; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface JpaAuctionImageRepository extends JpaRepository { + + @Query(""" + SELECT COUNT(auction_image) > 0 + FROM AuctionImage auction_image + WHERE auction_image.image.storeName = :storeName + """) + boolean existsByStoreName(final String storeName); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepository.java index 39b321bad..21f4e73e5 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepository.java @@ -4,10 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import java.util.Optional; - public interface JpaProfileImageRepository extends JpaRepository { - @Query("SELECT i FROM ProfileImage i WHERE i.image.storeName = :storeName") - Optional findByStoreName(final String storeName); + @Query(""" + SELECT COUNT(profile_image) > 0 + FROM ProfileImage profile_image + WHERE profile_image.image.storeName = :storeName + """) + boolean existsByStoreName(final String storeName); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImpl.java b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImpl.java index 12fa367f7..69fb884c4 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImpl.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImpl.java @@ -1,12 +1,9 @@ package com.ddang.ddang.image.infrastructure.persistence; -import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.domain.repository.ProfileImageRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; -import java.util.Optional; - @Repository @RequiredArgsConstructor public class ProfileImageRepositoryImpl implements ProfileImageRepository { @@ -14,12 +11,7 @@ public class ProfileImageRepositoryImpl implements ProfileImageRepository { private final JpaProfileImageRepository jpaProfileImageRepository; @Override - public Optional findById(final Long id) { - return jpaProfileImageRepository.findById(id); - } - - @Override - public Optional findByStoreName(final String storeName) { - return jpaProfileImageRepository.findByStoreName(storeName); + public boolean existsByStoreName(final String storeName) { + return jpaProfileImageRepository.existsByStoreName(storeName); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/ImageController.java b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/ImageController.java index 16ace8049..12a12e401 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/ImageController.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/ImageController.java @@ -1,7 +1,6 @@ package com.ddang.ddang.image.presentation; import com.ddang.ddang.image.application.ImageService; -import java.net.MalformedURLException; import lombok.RequiredArgsConstructor; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; @@ -12,27 +11,29 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +import java.net.MalformedURLException; + @RestController @RequiredArgsConstructor public class ImageController { private final ImageService imageService; - @GetMapping("/users/images/{id}") - public ResponseEntity downloadProfileImage(@PathVariable Long id) throws MalformedURLException { - final Resource resource = imageService.readProfileImage(id); + @GetMapping("/users/images/{storeName}") + public ResponseEntity downloadProfileImage(@PathVariable final String storeName) throws MalformedURLException { + final Resource resource = imageService.readProfileImage(storeName); - HttpHeaders headers = new HttpHeaders(); + final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_JPEG); return new ResponseEntity<>(resource, headers, HttpStatus.OK); } - @GetMapping("/auctions/images/{id}") - public ResponseEntity downloadAuctionImage(@PathVariable Long id) throws MalformedURLException { - final Resource resource = imageService.readAuctionImage(id); + @GetMapping("/auctions/images/{storeName}") + public ResponseEntity downloadAuctionImage(@PathVariable final String storeName) throws MalformedURLException { + final Resource resource = imageService.readAuctionImage(storeName); - HttpHeaders headers = new HttpHeaders(); + final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_JPEG); return new ResponseEntity<>(resource, headers, HttpStatus.OK); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java index 374a03459..bc1019357 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java @@ -7,21 +7,21 @@ public final class ImageUrlCalculator { private ImageUrlCalculator() { } - public static String calculateBy(final ImageRelativeUrl imageRelativeUrl, final Long id) { + public static String calculateBy(final ImageRelativeUrl imageRelativeUrl, final String storeName) { final String absoluteUrl = imageRelativeUrl.calculateAbsoluteUrl(); - if (id == null && imageRelativeUrl == ImageRelativeUrl.USER) { - return absoluteUrl + ProfileImage.DEFAULT_PROFILE_IMAGE_ID; + if (storeName == null && imageRelativeUrl == ImageRelativeUrl.USER) { + return absoluteUrl + ProfileImage.DEFAULT_PROFILE_IMAGE_STORE_NAME; } - return absoluteUrl + id; + return absoluteUrl + storeName; } - public static String calculateBy(final String imageAbsoluteUrl, final Long id) { - if (id == null && imageAbsoluteUrl.contains(ImageRelativeUrl.USER.getValue())) { - return imageAbsoluteUrl + ProfileImage.DEFAULT_PROFILE_IMAGE_ID; + public static String calculateBy(final String imageAbsoluteUrl, final String storeName) { + if (storeName == null && imageAbsoluteUrl.contains(ImageRelativeUrl.USER.getValue())) { + return imageAbsoluteUrl + ProfileImage.DEFAULT_PROFILE_IMAGE_STORE_NAME; } - return imageAbsoluteUrl + id; + return imageAbsoluteUrl + storeName; } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/notification/application/NotificationEventListener.java b/backend/ddang/src/main/java/com/ddang/ddang/notification/application/NotificationEventListener.java index 1a06f1125..2839f60cd 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/notification/application/NotificationEventListener.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/notification/application/NotificationEventListener.java @@ -5,6 +5,7 @@ import com.ddang.ddang.bid.application.event.BidNotificationEvent; import com.ddang.ddang.chat.application.event.MessageNotificationEvent; import com.ddang.ddang.chat.domain.Message; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.image.domain.AuctionImage; import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.presentation.util.ImageUrlCalculator; @@ -44,7 +45,7 @@ public void sendMessageNotification(final MessageNotificationEvent messageNotifi message.getWriter().getName(), message.getContents(), calculateRedirectUrl(MESSAGE_NOTIFICATION_REDIRECT_URI, message.getChatRoom().getId()), - ImageUrlCalculator.calculateBy(messageNotificationEvent.profileImageAbsoluteUrl(), profileImage.getId()) + ImageUrlCalculator.calculateBy(messageNotificationEvent.profileImageAbsoluteUrl(), ImageStoreNameProcessor.process(profileImage)) ); notificationService.send(createNotificationDto); } catch (final FirebaseMessagingException ex) { @@ -64,7 +65,7 @@ public void sendBidNotification(final BidNotificationEvent bidNotificationEvent) auction.getTitle(), BID_NOTIFICATION_MESSAGE_FORMAT, calculateRedirectUrl(AUCTION_DETAIL_URI, auction.getId()), - ImageUrlCalculator.calculateBy(bidDto.auctionImageAbsoluteUrl(), auctionImage.getId()) + ImageUrlCalculator.calculateBy(bidDto.auctionImageAbsoluteUrl(), ImageStoreNameProcessor.process(auctionImage)) ); notificationService.send(createNotificationDto); } catch (final FirebaseMessagingException ex) { @@ -84,7 +85,7 @@ public void sendQuestionNotification(final QuestionNotificationEvent questionNot auction.getTitle(), question.getContent(), calculateRedirectUrl(AUCTION_DETAIL_URI, auction.getId()), - ImageUrlCalculator.calculateBy(questionNotificationEvent.absoluteImageUrl(), auctionImage.getId()) + ImageUrlCalculator.calculateBy(questionNotificationEvent.absoluteImageUrl(), ImageStoreNameProcessor.process(auctionImage)) ); notificationService.send(createNotificationDto); } catch (final FirebaseMessagingException ex) { @@ -105,7 +106,7 @@ public void sendAnswerNotification(final AnswerNotificationEvent answerNotificat question.getContent(), answer.getContent(), calculateRedirectUrl(AUCTION_DETAIL_URI, auction.getId()), - ImageUrlCalculator.calculateBy(answerNotificationEvent.absoluteImageUrl(), auctionImage.getId()) + ImageUrlCalculator.calculateBy(answerNotificationEvent.absoluteImageUrl(), ImageStoreNameProcessor.process(auctionImage)) ); notificationService.send(createNotificationDto); } catch (final FirebaseMessagingException ex) { diff --git a/backend/ddang/src/main/java/com/ddang/ddang/qna/application/dto/ReadUserInQnaDto.java b/backend/ddang/src/main/java/com/ddang/ddang/qna/application/dto/ReadUserInQnaDto.java index a75d44558..c3d73e9cf 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/qna/application/dto/ReadUserInQnaDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/qna/application/dto/ReadUserInQnaDto.java @@ -1,11 +1,12 @@ package com.ddang.ddang.qna.application.dto; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; public record ReadUserInQnaDto( Long id, String name, - Long profileImageId, + String profileImageStoreName, double reliability, String oauthId, boolean isDeleted @@ -14,7 +15,7 @@ public static ReadUserInQnaDto from(final User writer) { return new ReadUserInQnaDto( writer.getId(), writer.getName(), - writer.getProfileImage().getId(), + ImageStoreNameProcessor.process(writer.getProfileImage()), writer.getReliability().getValue(), writer.getOauthInformation().getOauthId(), writer.isDeleted() diff --git a/backend/ddang/src/main/java/com/ddang/ddang/qna/infrastructure/JpaQuestionRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/qna/infrastructure/JpaQuestionRepository.java index 11de78514..ae6585356 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/qna/infrastructure/JpaQuestionRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/qna/infrastructure/JpaQuestionRepository.java @@ -14,10 +14,12 @@ public interface JpaQuestionRepository extends JpaRepository { @Query(""" SELECT q FROM Question q - JOIN FETCH q.writer + JOIN FETCH q.writer w + LEFT JOIN FETCH w.profileImage LEFT JOIN FETCH q.answer JOIN FETCH q.auction a - JOIN FETCH a.seller + JOIN FETCH a.seller s + JOIN FETCH s.profileImage WHERE q.deleted = false AND a.id = :auctionId """) List findAllByAuctionId(final Long auctionId); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java index 09e21af9e..5e5847b29 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java @@ -1,15 +1,15 @@ package com.ddang.ddang.report.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; -public record ReadReporterDto(Long id, String name, Long profileImageId, double reliability, boolean isDeleted) { +public record ReadReporterDto(Long id, String name, String profileImageStoreName, double reliability, boolean isDeleted) { public static ReadReporterDto from(final User reporter) { return new ReadReporterDto( reporter.getId(), reporter.getName(), - ImageIdProcessor.process(reporter.getProfileImage()), + ImageStoreNameProcessor.process(reporter.getProfileImage()), reporter.getReliability().getValue(), reporter.isDeleted() ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java index cd4fbd220..119fe432a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java @@ -1,12 +1,12 @@ package com.ddang.ddang.report.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; public record ReadUserInReportDto( Long id, String name, - Long profileImageId, + String profileImageStoreName, double reliability, String oauthId, boolean isSellerDeleted @@ -16,7 +16,7 @@ public static ReadUserInReportDto from(final User user) { return new ReadUserInReportDto( user.getId(), user.getName(), - ImageIdProcessor.process(user.getProfileImage()), + ImageStoreNameProcessor.process(user.getProfileImage()), user.getReliability().getValue(), user.getOauthInformation().getOauthId(), user.isDeleted() diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAnswerReportRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAnswerReportRepository.java index 2be18d491..b4614a8fa 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAnswerReportRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAnswerReportRepository.java @@ -13,11 +13,11 @@ public interface JpaAnswerReportRepository extends JpaRepository findAll(); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAuctionReportRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAuctionReportRepository.java index 5fa4e4186..dfff156f8 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAuctionReportRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaAuctionReportRepository.java @@ -13,9 +13,11 @@ public interface JpaAuctionReportRepository extends JpaRepository findAll(); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepository.java index c41258456..6f1bd65f4 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaChatRoomReportRepository.java @@ -13,11 +13,14 @@ public interface JpaChatRoomReportRepository extends JpaRepository findAll(); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaQuestionReportRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaQuestionReportRepository.java index deaf6e349..caad0fd2e 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaQuestionReportRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/infrastructure/persistence/JpaQuestionReportRepository.java @@ -13,8 +13,11 @@ public interface JpaQuestionReportRepository extends JpaRepository findAll(); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/review/application/dto/ReadUserInReviewDto.java b/backend/ddang/src/main/java/com/ddang/ddang/review/application/dto/ReadUserInReviewDto.java index bb0fa0927..25c446c0f 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/review/application/dto/ReadUserInReviewDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/review/application/dto/ReadUserInReviewDto.java @@ -1,14 +1,15 @@ package com.ddang.ddang.review.application.dto; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; -public record ReadUserInReviewDto(Long id, String name, Long profileImageId, double reliability, String oauthId) { +public record ReadUserInReviewDto(Long id, String name, String profileImageStoreName, double reliability, String oauthId) { public static ReadUserInReviewDto from(final User user) { return new ReadUserInReviewDto( user.getId(), user.getName(), - user.getProfileImage().getId(), + ImageStoreNameProcessor.process(user.getProfileImage()), user.getReliability().getValue(), user.getOauthInformation().getOauthId() ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepository.java index 5462534d6..c1be24a3d 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/review/infrastructure/persistence/JpaReviewRepository.java @@ -14,6 +14,7 @@ public interface JpaReviewRepository extends JpaRepository { @Query(""" SELECT r FROM Review r JOIN FETCH r.writer w + LEFT JOIN FETCH w.profileImage JOIN FETCH r.target t WHERE t.id = :targetId ORDER BY r.id DESC diff --git a/backend/ddang/src/main/java/com/ddang/ddang/review/presentation/dto/response/ReadUserInReviewResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/review/presentation/dto/response/ReadUserInReviewResponse.java index 328ed847c..720a923d0 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/review/presentation/dto/response/ReadUserInReviewResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/review/presentation/dto/response/ReadUserInReviewResponse.java @@ -10,7 +10,7 @@ public static ReadUserInReviewResponse from(final ReadUserInReviewDto userDto) { return new ReadUserInReviewResponse( userDto.id(), userDto.name(), - ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, userDto.profileImageId()) + ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, userDto.profileImageStoreName()) ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java b/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java index c0cc24705..9b299d407 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java @@ -21,7 +21,7 @@ public class UserService { private final StoreImageProcessor imageProcessor; public ReadUserDto readById(final Long userId) { - final User user = userRepository.findById(userId) + final User user = userRepository.findByIdWithProfileImage(userId) .orElseThrow(() -> new UserNotFoundException("사용자 정보를 사용할 수 없습니다.")); return ReadUserDto.from(user); @@ -29,7 +29,7 @@ public ReadUserDto readById(final Long userId) { @Transactional public ReadUserDto updateById(final Long userId, final UpdateUserDto userDto) { - final User user = userRepository.findById(userId) + final User user = userRepository.findByIdWithProfileImage(userId) .orElseThrow(() -> new UserNotFoundException("사용자 정보를 사용할 수 없습니다.")); updateUserByRequest(userDto, user); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java b/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java index 015310258..282c580eb 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java @@ -1,12 +1,12 @@ package com.ddang.ddang.user.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; +import com.ddang.ddang.image.application.util.ImageStoreNameProcessor; import com.ddang.ddang.user.domain.User; public record ReadUserDto( Long id, String name, - Long profileImageId, + String profileImageStoreName, double reliability, String oauthId, boolean isDeleted @@ -16,7 +16,7 @@ public static ReadUserDto from(final User user) { return new ReadUserDto( user.getId(), user.getName(), - ImageIdProcessor.process(user.getProfileImage()), + ImageStoreNameProcessor.process(user.getProfileImage()), user.getReliability().getValue(), user.getOauthInformation().getOauthId(), user.isDeleted() diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/domain/repository/UserRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/user/domain/repository/UserRepository.java index bf909cb60..b4bc93c92 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/domain/repository/UserRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/domain/repository/UserRepository.java @@ -10,6 +10,8 @@ public interface UserRepository { Optional findById(final Long id); + Optional findByIdWithProfileImage(final Long id); + Optional findByOauthId(final String oauthId); boolean existsByIdAndDeletedIsTrue(final Long id); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java index a703d934b..809eead49 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java @@ -15,6 +15,14 @@ public interface JpaUserRepository extends JpaRepository { """) Optional findById(final Long id); + @Query(""" + SELECT u + FROM User u + LEFT JOIN FETCH u.profileImage + WHERE u.deleted = false AND u.id = :id + """) + Optional findByIdWithProfileImage(final Long id); + @Query(""" SELECT u FROM User u diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImpl.java b/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImpl.java index 1cff56988..9f42c37b7 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImpl.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImpl.java @@ -23,6 +23,11 @@ public Optional findById(final Long id) { return jpaUserRepository.findById(id); } + @Override + public Optional findByIdWithProfileImage(final Long id) { + return jpaUserRepository.findByIdWithProfileImage(id); + } + @Override public Optional findByOauthId(final String oauthId) { return jpaUserRepository.findByOauthId(oauthId); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/ReadUserResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/ReadUserResponse.java new file mode 100644 index 000000000..e69de29bb diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/AuctionDetailResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/AuctionDetailResponse.java index d7fa2befd..8b8b0d1e8 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/AuctionDetailResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/AuctionDetailResponse.java @@ -56,9 +56,9 @@ public static AuctionDetailResponse from(final ReadAuctionDto dto) { } private static List convertImageFullUrls(final ReadAuctionDto dto) { - return dto.auctionImageIds() + return dto.auctionImageStoreNames() .stream() - .map(id -> ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, id)) + .map(storeName -> ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, storeName)) .toList(); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionDetailResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionDetailResponse.java index 05b142a7b..3595e11a3 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionDetailResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionDetailResponse.java @@ -18,7 +18,10 @@ public static ReadAuctionDetailResponse of( final AuthenticationUserInfo userInfo ) { final AuctionDetailResponse auctionDetailResponse = AuctionDetailResponse.from(dto.auctionDto()); - final String profileImageUrl = ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, dto.auctionDto().sellerId()); + final String profileImageUrl = ImageUrlCalculator.calculateBy( + ImageRelativeUrl.USER, + dto.auctionDto().sellerProfileImageStoreName() + ); final Float reliability = ReliabilityProcessor.process(dto.auctionDto().sellerReliability()); final SellerResponse sellerResponse = new SellerResponse( diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionResponse.java index 4db39f7f5..0cca8926d 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadAuctionResponse.java @@ -25,9 +25,9 @@ public static ReadAuctionResponse from(final ReadAuctionDto dto) { } private static String calculateThumbnailImageUrl(final ReadAuctionDto dto) { - final Long thumbnailAuctionImage = dto.auctionImageIds().get(0); + final String thumbnailAuctionImageStoreName = dto.auctionImageStoreNames().get(0); - return ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, thumbnailAuctionImage); + return ImageUrlCalculator.calculateBy(ImageRelativeUrl.AUCTION, thumbnailAuctionImageStoreName); } private static int processAuctionPrice(final Integer startPrice, final Integer lastBidPrice) { diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java index 9294e5024..e9be32709 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java @@ -11,7 +11,7 @@ public record ReadUserResponse(String name, String profileImage, Float reliabili public static ReadUserResponse from(final ReadUserDto readUserDto) { return new ReadUserResponse( NameProcessor.process(readUserDto.isDeleted(), readUserDto.name()), - ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, readUserDto.profileImageId()), + ImageUrlCalculator.calculateBy(ImageRelativeUrl.USER, readUserDto.profileImageStoreName()), ReliabilityProcessor.process(readUserDto.reliability()) ); } diff --git a/backend/ddang/src/main/resources/static/docs/docs.html b/backend/ddang/src/main/resources/static/docs/docs.html index 4cf03fadb..7b5494805 100644 --- a/backend/ddang/src/main/resources/static/docs/docs.html +++ b/backend/ddang/src/main/resources/static/docs/docs.html @@ -913,6 +913,9 @@

요청

} +
+

Unresolved directive in docs.adoc - include::/Users/kwon-yejin/GitHub/2023-3-ddang/backend/ddang/build/generated-snippets/authentication-controller-test/ouath2-type과_access-token과_refresh-token을_전달하면_탈퇴한다/path-parameters.adoc[]

+
@@ -1006,7 +1009,7 @@

응답

{ "name" : "사용자1", - "profileImage" : "http://localhost:8080/users/images/1", + "profileImage" : "http://localhost:8080/users/images/profile_image.png", "reliability" : 4.6 } @@ -1065,7 +1068,7 @@

응답

{ "name" : "updateName", - "profileImage" : "http://localhost:8080/users/images/1", + "profileImage" : "http://localhost:8080/users/images/profile_image.png", "reliability" : 4.6 } @@ -1525,7 +1528,7 @@

응답

{ "id" : 1, "title" : "제목", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 0 @@ -1643,14 +1646,14 @@

응답

"auctions" : [ { "id" : 2, "title" : "경매 상품 1", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 2 }, { "id" : 1, "title" : "경매 상품 1", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 2 @@ -1785,14 +1788,14 @@

응답

"auctions" : [ { "id" : 2, "title" : "경매 상품 2", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 2 }, { "id" : 1, "title" : "경매 상품 1", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 2 @@ -1927,14 +1930,14 @@

응답

"auctions" : [ { "id" : 2, "title" : "경매 상품 2", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 2 }, { "id" : 1, "title" : "경매 상품 1", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "auctionPrice" : 1000, "status" : "UNBIDDEN", "auctioneerCount" : 2 @@ -2065,7 +2068,7 @@

응답

{ "auction" : { "id" : 1, - "images" : [ "http://localhost:8080/auctions/images/1" ], + "images" : [ "http://localhost:8080/auctions/images/auction_image.png" ], "title" : "경매 상품 1", "category" : { "main" : "main", @@ -2087,7 +2090,7 @@

응답

}, "seller" : { "id" : 1, - "image" : "http://localhost:8080/users/images/1", + "image" : "http://localhost:8080/users/images/profile_image.png", "nickname" : "판매자", "reliability" : 3.5 }, @@ -2603,7 +2606,7 @@

응답

"writer" : { "id" : 1, "name" : "질문자", - "image" : "http://localhost:8080/users/images/1" + "image" : "http://localhost:8080/users/images/profile_image1.png" }, "createdTime" : "2023-10-31T16:59:34", "content" : "질문1", @@ -2614,7 +2617,7 @@

응답

"writer" : { "id" : 2, "name" : "판매자", - "image" : "http://localhost:8080/users/images/2" + "image" : "http://localhost:8080/users/images/profile_image2.png" }, "createdTime" : "2023-10-31T16:59:34", "content" : "답변1" @@ -2625,7 +2628,7 @@

응답

"writer" : { "id" : 1, "name" : "질문자", - "image" : "http://localhost:8080/users/images/1" + "image" : "http://localhost:8080/users/images/profile_image1.png" }, "createdTime" : "2023-10-31T16:59:34", "content" : "질문2", @@ -2636,7 +2639,7 @@

응답

"writer" : { "id" : 2, "name" : "판매자", - "image" : "http://localhost:8080/users/images/2" + "image" : "http://localhost:8080/users/images/profile_image2.png" }, "createdTime" : "2023-10-31T16:59:34", "content" : "답변1" @@ -2849,12 +2852,12 @@

응답

[ { "name" : "사용자1", - "profileImage" : "http://localhost:8080/users/images/1", + "profileImage" : "http://localhost:8080/users/images/profile_image1.png", "price" : 10000, "bidTime" : "2023-10-31T16:59:40" }, { "name" : "사용자2", - "profileImage" : "http://localhost:8080/users/images/2", + "profileImage" : "http://localhost:8080/users/images/profile_image2.png", "price" : 12000, "bidTime" : "2023-10-31T16:59:40" } ] @@ -3041,12 +3044,12 @@

응답

"chatPartner" : { "id" : 2, "name" : "구매자1", - "profileImage" : "http://localhost:8080/users/images/2" + "profileImage" : "http://localhost:8080/users/images/profile_image.png" }, "auction" : { "id" : 1, "title" : "경매1", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "price" : 10000 }, "lastMessage" : { @@ -3059,12 +3062,12 @@

응답

"chatPartner" : { "id" : 3, "name" : "구매자2", - "profileImage" : "http://localhost:8080/users/images/3" + "profileImage" : "http://localhost:8080/users/images/profile_image.png" }, "auction" : { "id" : 2, "title" : "경매2", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "price" : 20000 }, "lastMessage" : { @@ -3229,12 +3232,12 @@

응답

"chatPartner" : { "id" : 1, "name" : "판매자", - "profileImage" : "http://localhost:8080/users/images/1" + "profileImage" : "http://localhost:8080/users/images/profile_image.png" }, "auction" : { "id" : 1, "title" : "경매1", - "image" : "http://localhost:8080/auctions/images/1", + "image" : "http://localhost:8080/auctions/images/auction_image.png", "price" : 10000 }, "isChatAvailable" : true @@ -4570,7 +4573,7 @@

응답

"writer" : { "id" : 2, "name" : "판매자2", - "profileImage" : "http://localhost:8080/users/images/2" + "profileImage" : "http://localhost:8080/users/images/profile_image2.png" }, "content" : "친절하다.", "score" : 5.0, @@ -4580,7 +4583,7 @@

응답

"writer" : { "id" : 1, "name" : "판매자1", - "profileImage" : "http://localhost:8080/users/images/1" + "profileImage" : "http://localhost:8080/users/images/profile_image1.png" }, "content" : "친절하다.", "score" : 5.0, diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionControllerFixture.java index b92c77e17..d5951dfc4 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionControllerFixture.java @@ -11,12 +11,13 @@ import com.ddang.ddang.authentication.infrastructure.jwt.PrivateClaims; import com.ddang.ddang.configuration.CommonControllerSliceTest; import com.fasterxml.jackson.core.JsonProcessingException; -import java.time.LocalDateTime; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; +import java.time.LocalDateTime; +import java.util.List; + @SuppressWarnings("NonAsciiCharacters") public class AuctionControllerFixture extends CommonControllerSliceTest { @@ -39,7 +40,7 @@ public class AuctionControllerFixture extends CommonControllerSliceTest { protected CreateInfoAuctionDto 경매_등록_결과_dto = new CreateInfoAuctionDto( 1L, "제목", - 1L, + "auction_image.png", 1_000 ); protected ReadChatRoomDto 쪽지방_dto = new ReadChatRoomDto(1L, true); @@ -148,12 +149,12 @@ void fixtureSetUp() throws JsonProcessingException { LocalDateTime.now(), LocalDateTime.now(), List.of(서울특별시_강서구_역삼동), - List.of(1L), + List.of("auction_image.png"), 2, "main", "sub", 1L, - 1L, + "profile_image.png", "판매자", 3.5d, false, @@ -172,12 +173,12 @@ void fixtureSetUp() throws JsonProcessingException { LocalDateTime.now(), LocalDateTime.now(), List.of(서울특별시_강서구_역삼동), - List.of(1L), + List.of("auction_image.png"), 2, "main", "sub", 1L, - 1L, + "profile_image.png", "판매자", 3.5d, false, @@ -196,12 +197,12 @@ void fixtureSetUp() throws JsonProcessingException { LocalDateTime.now(), LocalDateTime.now(), List.of(서울특별시_강서구_역삼동), - List.of(1L), + List.of("auction_image.png"), 2, "main", "sub", 1L, - 1L, + "profile_image.png", "판매자", 3.5d, false, diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionQuestionControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionQuestionControllerFixture.java index 588ae7036..538d8f08c 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionQuestionControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionQuestionControllerFixture.java @@ -21,7 +21,7 @@ public class AuctionQuestionControllerFixture extends CommonControllerSliceTest protected ReadUserInQnaDto 질문자_정보_dto = new ReadUserInQnaDto( 1L, "질문자", - 1L, + "profile_image1.png", 4.5d, "12345", false @@ -29,7 +29,7 @@ public class AuctionQuestionControllerFixture extends CommonControllerSliceTest protected ReadUserInQnaDto 판매자_정보_dto = new ReadUserInQnaDto( 2L, "판매자", - 2L, + "profile_image2.png", 4.5d, "12346", false diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionReviewControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionReviewControllerFixture.java index b0fbbf4f8..142df2be0 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionReviewControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/fixture/AuctionReviewControllerFixture.java @@ -15,8 +15,8 @@ public class AuctionReviewControllerFixture extends CommonControllerSliceTest { protected String 액세스_토큰 = "Bearer accessToken"; protected PrivateClaims 유효한_작성자_비공개_클레임 = new PrivateClaims(유효한_평가_작성자_아이디); protected Long 유효한_경매_아이디 = 1L; - protected Long 판매자_프로필_이미지_아이디 = 1L; - protected ReadUserInReviewDto 판매자 = new ReadUserInReviewDto(1L, "판매자", 판매자_프로필_이미지_아이디, 5.0d, "12347"); + protected String 판매자_프로필_이미지_저장_이름 = "profile_image.png"; + protected ReadUserInReviewDto 판매자 = new ReadUserInReviewDto(1L, "판매자", 판매자_프로필_이미지_저장_이름, 5.0d, "12347"); protected Long 구매자가_판매자에게_받은_평가_아이디 = 1L; protected ReadReviewDto 구매자가_판매자1에게_받은_평가 = new ReadReviewDto(구매자가_판매자에게_받은_평가_아이디, 판매자, "친절하다.", 5.0d, LocalDateTime.now()); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/fixture/BidControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/fixture/BidControllerFixture.java index 1e28b17b7..0219c3ba7 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/fixture/BidControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/fixture/BidControllerFixture.java @@ -26,6 +26,6 @@ public class BidControllerFixture extends CommonControllerSliceTest { protected static CreateBidRequest 입찰액이_양수가_아닌_입찰_request1 = new CreateBidRequest(1L, -1); protected static CreateBidRequest 입찰액이_양수가_아닌_입찰_request2 = new CreateBidRequest(1L, 0); - protected ReadBidDto 입찰_정보_dto1 = new ReadBidDto("사용자1", 1L, false, 10_000, LocalDateTime.now()); - protected ReadBidDto 입찰_정보_dto2 = new ReadBidDto("사용자2", 2L, false, 12_000, LocalDateTime.now()); + protected ReadBidDto 입찰_정보_dto1 = new ReadBidDto("사용자1", "profile_image1.png", false, 10_000, LocalDateTime.now()); + protected ReadBidDto 입찰_정보_dto2 = new ReadBidDto("사용자2", "profile_image2.png", false, 12_000, LocalDateTime.now()); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java index d0f948c66..5d9f61dcb 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java @@ -241,20 +241,14 @@ void setUp() { .andExpectAll( status().isOk(), jsonPath("$.[0].id", is(조회용_채팅방1.id()), Long.class), - jsonPath("$.[0].chatPartner.name", is(조회용_채팅방1.partnerDto() - .name())), - jsonPath("$.[0].auction.title", is(조회용_채팅방1.auctionDto() - .title())), - jsonPath("$.[0].lastMessage.contents", is(조회용_채팅방1.lastMessageDto() - .contents())), + jsonPath("$.[0].chatPartner.name", is(조회용_채팅방1.partnerDto().name())), + jsonPath("$.[0].auction.title", is(조회용_채팅방1.auctionDto().title())), + jsonPath("$.[0].lastMessage.contents", is(조회용_채팅방1.lastMessageDto().contents())), jsonPath("$.[0].unreadMessageCount", is(조회용_채팅방1.unreadMessageCount()), Long.class), jsonPath("$.[1].id", is(조회용_채팅방2.id()), Long.class), - jsonPath("$.[1].chatPartner.name", is(조회용_채팅방2.partnerDto() - .name())), - jsonPath("$.[1].auction.title", is(조회용_채팅방2.auctionDto() - .title())), - jsonPath("$.[1].lastMessage.contents", is(조회용_채팅방2.lastMessageDto() - .contents())), + jsonPath("$.[1].chatPartner.name", is(조회용_채팅방2.partnerDto().name())), + jsonPath("$.[1].auction.title", is(조회용_채팅방2.auctionDto().title())), + jsonPath("$.[1].lastMessage.contents", is(조회용_채팅방2.lastMessageDto().contents())), jsonPath("$.[1].unreadMessageCount", is(조회용_채팅방1.unreadMessageCount()), Long.class) ); readAllParticipatingChatRooms_문서화(resultActions); @@ -288,10 +282,8 @@ void setUp() { .andExpectAll( status().isOk(), jsonPath("$.id", is(조회용_참가중인_채팅방.id()), Long.class), - jsonPath("$.chatPartner.name", is(조회용_참가중인_채팅방.partnerDto() - .name())), - jsonPath("$.auction.title", is(조회용_참가중인_채팅방.auctionDto() - .title())) + jsonPath("$.chatPartner.name", is(조회용_참가중인_채팅방.partnerDto().name())), + jsonPath("$.auction.title", is(조회용_참가중인_채팅방.auctionDto().title())) ); readChatRoom_문서화(resultActions); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/fixture/ChatRoomControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/fixture/ChatRoomControllerFixture.java index 6d83db0e4..39e081602 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/fixture/ChatRoomControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/fixture/ChatRoomControllerFixture.java @@ -18,11 +18,11 @@ public class ChatRoomControllerFixture extends CommonControllerSliceTest { private Long 탈퇴한_사용자_아이디 = 5L; protected PrivateClaims 사용자_ID_클레임 = new PrivateClaims(1L); - protected ReadUserInChatRoomDto 판매자 = new ReadUserInChatRoomDto(1L, "판매자", 1L, 5.0d, false); - private ReadUserInChatRoomDto 구매자1 = new ReadUserInChatRoomDto(2L, "구매자1", 2L, 5.0d, false); - private ReadUserInChatRoomDto 구매자2 = new ReadUserInChatRoomDto(3L, "구매자2", 3L, 5.0d, false); - private ReadAuctionInChatRoomDto 조회용_경매1 = new ReadAuctionInChatRoomDto(1L, "경매1", 10_000, 1L); - private ReadAuctionInChatRoomDto 조회용_경매2 = new ReadAuctionInChatRoomDto(2L, "경매2", 20_000, 1L); + protected ReadUserInChatRoomDto 판매자 = new ReadUserInChatRoomDto(1L, "판매자", "profileImage1.png", 5.0d, false); + private ReadUserInChatRoomDto 구매자1 = new ReadUserInChatRoomDto(2L, "구매자1", "profileImage2.png", 5.0d, false); + private ReadUserInChatRoomDto 구매자2 = new ReadUserInChatRoomDto(3L, "구매자2", "profileImage3.png", 5.0d, false); + private ReadAuctionInChatRoomDto 조회용_경매1 = new ReadAuctionInChatRoomDto(1L, "경매1", 10_000, "auctionImage1.png"); + private ReadAuctionInChatRoomDto 조회용_경매2 = new ReadAuctionInChatRoomDto(2L, "경매2", 20_000, "auctionImage2.png"); protected ReadChatRoomWithLastMessageDto 조회용_채팅방1 = new ReadChatRoomWithLastMessageDto(1L, 조회용_경매1, 구매자1, new ReadLastMessageDto(1L, LocalDateTime.now(), 판매자, 구매자1, "메시지1"), 1L, true); protected ReadChatRoomWithLastMessageDto 조회용_채팅방2 = new ReadChatRoomWithLastMessageDto(2L, 조회용_경매2, 구매자2, new ReadLastMessageDto(1L, LocalDateTime.now(), 판매자, 구매자2, "메시지2"), 1L, true); protected CreateMessageRequest 메시지_생성_요청 = new CreateMessageRequest(1L, "메시지 내용"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/application/ImageServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/application/ImageServiceTest.java index e2044c85c..b86351be2 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/application/ImageServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/application/ImageServiceTest.java @@ -24,7 +24,7 @@ class ImageServiceTest extends ImageServiceFixture { @Test void 지정한_아이디에_해당하는_프로필_이미지를_조회한다() throws Exception { // when - final Resource actual = imageService.readProfileImage(프로필_이미지.getId()); + final Resource actual = imageService.readProfileImage(프로필_이미지.getImage().getStoreName()); // then assertThat(actual.getFilename()).isEqualTo(프로필_이미지_파일명); @@ -33,7 +33,7 @@ class ImageServiceTest extends ImageServiceFixture { @Test void 지정한_아이디에_해당하는_프로필_이미지가_없는_경우_null을_반환한다() throws MalformedURLException { // when - final Resource actual = imageService.readProfileImage(존재하지_않는_프로필_이미지_아이디); + final Resource actual = imageService.readProfileImage(존재하지_않는_프로필_이미지_이름); // then assertThat(actual).isNull(); @@ -42,7 +42,7 @@ class ImageServiceTest extends ImageServiceFixture { @Test void 지정한_아이디에_해당하는_경매_이미지를_조회한다() throws Exception { // when - final Resource actual = imageService.readAuctionImage(경매_이미지.getId()); + final Resource actual = imageService.readAuctionImage(경매_이미지.getImage().getStoreName()); // then assertThat(actual.getFilename()).isEqualTo(경매_이미지_파일명); @@ -51,7 +51,7 @@ class ImageServiceTest extends ImageServiceFixture { @Test void 지정한_아이디에_해당하는_경매_이미지가_없는_경우_null을_반환한다() throws MalformedURLException { // when - final Resource actual = imageService.readAuctionImage(존재하지_않는_경매_이미지_아이디); + final Resource actual = imageService.readAuctionImage(존재하지_않는_경매_이미지_이름); // then assertThat(actual).isNull(); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/application/fixture/ImageServiceFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/application/fixture/ImageServiceFixture.java index c70725205..02232306a 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/application/fixture/ImageServiceFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/application/fixture/ImageServiceFixture.java @@ -16,8 +16,8 @@ public class ImageServiceFixture { @Autowired private JpaAuctionImageRepository auctionImageRepository; - protected Long 존재하지_않는_프로필_이미지_아이디 = -999L; - protected Long 존재하지_않는_경매_이미지_아이디 = -999L; + protected String 존재하지_않는_프로필_이미지_이름 = "invalid_profile.png"; + protected String 존재하지_않는_경매_이미지_이름 = "invalid_auction.png"; protected ProfileImage 프로필_이미지; protected String 프로필_이미지_파일명; diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/ImageIdProcessorTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/ImageStoreNameProcessorTest.java similarity index 57% rename from backend/ddang/src/test/java/com/ddang/ddang/image/application/util/ImageIdProcessorTest.java rename to backend/ddang/src/test/java/com/ddang/ddang/image/application/util/ImageStoreNameProcessorTest.java index a016206cd..6f3b80589 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/ImageIdProcessorTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/ImageStoreNameProcessorTest.java @@ -1,6 +1,6 @@ package com.ddang.ddang.image.application.util; -import com.ddang.ddang.image.application.util.fixture.ImageIdProcessorFixture; +import com.ddang.ddang.image.application.util.fixture.ImageStoreNameProcessorFixture; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -10,24 +10,24 @@ @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") -class ImageIdProcessorTest extends ImageIdProcessorFixture { +class ImageStoreNameProcessorTest extends ImageStoreNameProcessorFixture { @Test void 경매_이미지가_null이_아니라면_경매_이미지_아이디를_반환한다() { // given - given(경매_이미지.getId()).willReturn(경매_이미지_아이디); + given(경매_이미지.getImage()).willReturn(경매_이미지_데이터_VO); // when - final Long actual = ImageIdProcessor.process(경매_이미지); + final String actual = ImageStoreNameProcessor.process(경매_이미지); // then - assertThat(actual).isEqualTo(경매_이미지_아이디); + assertThat(actual).isEqualTo(경매_이미지_저장_이름); } @Test void 경매_이미지가_null이면_경매_이미지_아이디를_null로_반환한다() { // when - final Long actual = ImageIdProcessor.process(null인_경매_이미지); + final String actual = ImageStoreNameProcessor.process(null인_경매_이미지); // then assertThat(actual).isNull(); @@ -36,19 +36,19 @@ class ImageIdProcessorTest extends ImageIdProcessorFixture { @Test void 프로필_이미지가_null이_아니라면_프로필_이미지_아이디를_반환한다() { // given - given(프로필_이미지.getId()).willReturn(프로필_이미지_아이디); + given(프로필_이미지.getImage()).willReturn(프로필_이미지_데이터_VO); // when - final Long actual = ImageIdProcessor.process(프로필_이미지); + final String actual = ImageStoreNameProcessor.process(프로필_이미지); // then - assertThat(actual).isEqualTo(프로필_이미지_아이디); + assertThat(actual).isEqualTo(프로필_이미지_저장_이름); } @Test void 프로필_이미지가_null이면_프로필_이미지_아이디를_null로_반환한다() { // when - final Long actual = ImageIdProcessor.process(null인_프로필_이미지); + final String actual = ImageStoreNameProcessor.process(null인_프로필_이미지); // then assertThat(actual).isNull(); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/fixture/ImageIdProcessorFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/fixture/ImageStoreNameProcessorFixture.java similarity index 52% rename from backend/ddang/src/test/java/com/ddang/ddang/image/application/util/fixture/ImageIdProcessorFixture.java rename to backend/ddang/src/test/java/com/ddang/ddang/image/application/util/fixture/ImageStoreNameProcessorFixture.java index 3fa95dbd4..d4c67a8f8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/fixture/ImageIdProcessorFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/application/util/fixture/ImageStoreNameProcessorFixture.java @@ -1,18 +1,20 @@ package com.ddang.ddang.image.application.util.fixture; import com.ddang.ddang.image.domain.AuctionImage; +import com.ddang.ddang.image.domain.Image; import com.ddang.ddang.image.domain.ProfileImage; import static org.mockito.Mockito.mock; @SuppressWarnings("NonAsciiCharacters") -public class ImageIdProcessorFixture { +public class ImageStoreNameProcessorFixture { protected AuctionImage 경매_이미지 = mock(AuctionImage.class); protected AuctionImage null인_경매_이미지 = null; - protected Long 경매_이미지_아이디 = 1L; - protected ProfileImage 프로필_이미지 = mock(ProfileImage.class); protected ProfileImage null인_프로필_이미지 = null; - protected Long 프로필_이미지_아이디 = 1L; + protected String 경매_이미지_저장_이름 = "auction_image.png"; + protected String 프로필_이미지_저장_이름 = "profile_image.png"; + protected Image 프로필_이미지_데이터_VO = new Image("upload.png", 프로필_이미지_저장_이름); + protected Image 경매_이미지_데이터_VO = new Image("upload.png", 경매_이미지_저장_이름); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImplTest.java index a77fea90e..bb97c2993 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImplTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/AuctionImageRepositoryImplTest.java @@ -1,7 +1,6 @@ package com.ddang.ddang.image.infrastructure.persistence; import com.ddang.ddang.configuration.QuerydslConfiguration; -import com.ddang.ddang.image.domain.AuctionImage; import com.ddang.ddang.image.domain.repository.AuctionImageRepository; import com.ddang.ddang.image.infrastructure.persistence.fixture.AuctionImageRepositoryImplFixture; import org.junit.jupiter.api.BeforeEach; @@ -12,8 +11,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.util.Optional; - import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @@ -30,11 +27,20 @@ void setUp(@Autowired final JpaAuctionImageRepository jpaAuctionImageRepository) } @Test - void 경매_이미지를_아이디를_통해_조회한다() { + void 경매_이미지_이름에_해당하는_경매_이미지가_존재하면_참을_반환한다() { + // when + final boolean actual = auctionImageRepository.existsByStoreName(존재하는_경매_이미지_이름); + + // then + assertThat(actual).isTrue(); + } + + @Test + void 경매_이미지_이름에_해당하는_경매_이미지가_존재하지_않으면_거짓을_반환한다() { // when - final Optional actual = auctionImageRepository.findById(경매_이미지.getId()); + final boolean actual = auctionImageRepository.existsByStoreName(존재하지_않는_경매_이미지_이름); // then - assertThat(actual).contains(경매_이미지); + assertThat(actual).isFalse(); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepositoryTest.java index 3689fd8be..809345b48 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaAuctionImageRepositoryTest.java @@ -3,8 +3,6 @@ import com.ddang.ddang.configuration.QuerydslConfiguration; import com.ddang.ddang.image.domain.AuctionImage; import com.ddang.ddang.image.infrastructure.persistence.fixture.JpaAuctionImageRepositoryFixture; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -12,8 +10,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.util.Optional; - import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @@ -22,9 +18,6 @@ @SuppressWarnings("NonAsciiCharacters") class JpaAuctionImageRepositoryTest extends JpaAuctionImageRepositoryFixture { - @PersistenceContext - EntityManager em; - @Autowired JpaAuctionImageRepository auctionImageRepository; @@ -37,27 +30,24 @@ class JpaAuctionImageRepositoryTest extends JpaAuctionImageRepositoryFixture { final AuctionImage actual = auctionImageRepository.save(auctionImage); // then - em.flush(); - em.clear(); - assertThat(actual.getId()).isPositive(); } @Test - void 지정한_아이디에_해당하는_경매_이미지를_조회한다() { + void 경매_이미지_이름에_해당하는_경매_이미지가_존재하면_참을_반환한다() { // when - final Optional actual = auctionImageRepository.findById(경매_이미지.getId()); + final boolean actual = auctionImageRepository.existsByStoreName(존재하는_경매_이미지_이름); // then - assertThat(actual).contains(경매_이미지); + assertThat(actual).isTrue(); } @Test - void 지정한_아이디에_해당하는_경매_이미지가_없는_경우_빈_Optional을_반환한다() { + void 경매_이미지_이름에_해당하는_경매_이미지가_존재하지_않으면_거짓을_반환한다() { // when - final Optional actual = auctionImageRepository.findById(존재하지_않는_경매_이미지_아이디); + final boolean actual = auctionImageRepository.existsByStoreName(존재하지_않는_경매_이미지_이름); // then - assertThat(actual).isEmpty(); + assertThat(actual).isFalse(); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepositoryTest.java index 59db38093..72a9e6fc6 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/JpaProfileImageRepositoryTest.java @@ -4,8 +4,6 @@ import com.ddang.ddang.configuration.QuerydslConfiguration; import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.infrastructure.persistence.fixture.JpaProfileImageRepositoryFixture; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -13,8 +11,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.util.Optional; - import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @@ -23,9 +19,6 @@ @SuppressWarnings("NonAsciiCharacters") class JpaProfileImageRepositoryTest extends JpaProfileImageRepositoryFixture { - @PersistenceContext - EntityManager em; - @Autowired JpaProfileImageRepository profileImageRepository; @@ -37,37 +30,25 @@ class JpaProfileImageRepositoryTest extends JpaProfileImageRepositoryFixture { // when final ProfileImage actual = profileImageRepository.save(profileImage); - em.flush(); - em.clear(); - // then assertThat(actual.getId()).isPositive(); } @Test - void 지정한_아이디에_해당하는_이미지를_조회한다() { - // when - final Optional actual = profileImageRepository.findById(프로필_이미지.getId()); - - // then - assertThat(actual).contains(프로필_이미지); - } - - @Test - void 지정한_아이디에_해당하는_이미지가_없는_경우_빈_Optional을_반환한다() { + void 프로필을_이미지_이름에_해당하는_프로필_이미지가_존재하면_참을_반환한다() { // when - final Optional actual = profileImageRepository.findById(존재하지_않는_프로필_이미지_아이디); + final boolean actual = profileImageRepository.existsByStoreName(존재하는_프로필_이미지_이름); // then - assertThat(actual).isEmpty(); + assertThat(actual).isTrue(); } @Test - void 저장된_이름에_해당하는_이미지를_반환한다() { + void 프로필을_이미지_이름에_해당하는_프로필_이미지가_존재하지_않으면_참을_반환한다() { // when - final Optional actual = profileImageRepository.findByStoreName(저장된_이미지_파일명); + final boolean actual = profileImageRepository.existsByStoreName(존재하지_않는_프로필_이미지_이름); // then - assertThat(actual).contains(프로필_이미지); + assertThat(actual).isFalse(); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImplTest.java index 7f733ae97..804c98876 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImplTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/ProfileImageRepositoryImplTest.java @@ -1,7 +1,6 @@ package com.ddang.ddang.image.infrastructure.persistence; import com.ddang.ddang.configuration.QuerydslConfiguration; -import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.domain.repository.ProfileImageRepository; import com.ddang.ddang.image.infrastructure.persistence.fixture.ProfileImageRepositoryImplFixture; import org.junit.jupiter.api.BeforeEach; @@ -12,8 +11,6 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; -import java.util.Optional; - import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @@ -30,20 +27,20 @@ void setUp(@Autowired final JpaProfileImageRepository jpaProfileImageRepository) } @Test - void 프로필을_이미지를_아이디를_통해_조회한다() { + void 프로필을_이미지_이름에_해당하는_프로필_이미지가_존재하면_참을_반환한다() { // when - final Optional actual = profileImageRepository.findById(프로필_이미지.getId()); + final boolean actual = profileImageRepository.existsByStoreName(존재하는_프로필_이미지_이름); // then - assertThat(actual).contains(프로필_이미지); + assertThat(actual).isTrue(); } @Test - void 프로필을_이미지를_저장_이미지를_통해_조회한다() { + void 프로필을_이미지_이름에_해당하는_프로필_이미지가_존재하지_않으면_참을_반환한다() { // when - final Optional actual = profileImageRepository.findByStoreName(프로필_이미지.getImage().getStoreName()); + final boolean actual = profileImageRepository.existsByStoreName(존재하지_않는_프로필_이미지_이름); // then - assertThat(actual).contains(프로필_이미지); + assertThat(actual).isFalse(); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/AuctionImageRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/AuctionImageRepositoryImplFixture.java index a3a88d949..e04980bc3 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/AuctionImageRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/AuctionImageRepositoryImplFixture.java @@ -2,29 +2,22 @@ import com.ddang.ddang.image.domain.AuctionImage; import com.ddang.ddang.image.infrastructure.persistence.JpaAuctionImageRepository; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; @SuppressWarnings("NonAsciiCharacters") public class AuctionImageRepositoryImplFixture { - @PersistenceContext - private EntityManager em; - @Autowired private JpaAuctionImageRepository jpaAuctionImageRepository; - protected AuctionImage 경매_이미지; + protected String 존재하는_경매_이미지_이름 = "경매이미지.png"; + protected String 존재하지_않는_경매_이미지_이름 = "invalid.png"; @BeforeEach void fixtureSetUp() { - 경매_이미지 = new AuctionImage("경매이미지.png", "경매이미지.png"); + final AuctionImage 경매_이미지 = new AuctionImage("경매이미지.png", 존재하는_경매_이미지_이름); jpaAuctionImageRepository.save(경매_이미지); - - em.flush(); - em.clear(); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaAuctionImageRepositoryFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaAuctionImageRepositoryFixture.java index a92e8ec51..2f4a7d66d 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaAuctionImageRepositoryFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaAuctionImageRepositoryFixture.java @@ -18,13 +18,13 @@ public class JpaAuctionImageRepositoryFixture { protected String 업로드_이미지_파일명 = "uploadName"; protected String 저장된_이미지_파일명 = "storeName"; - protected Long 존재하지_않는_경매_이미지_아이디 = -999L; - protected AuctionImage 경매_이미지; + protected String 존재하는_경매_이미지_이름 = "경매이미지.png"; + protected String 존재하지_않는_경매_이미지_이름 = "invalid.png"; @BeforeEach void setUp() { - 경매_이미지 = new AuctionImage(업로드_이미지_파일명, 저장된_이미지_파일명); + final AuctionImage 경매_이미지 = new AuctionImage("경매이미지.png", 존재하는_경매_이미지_이름); auctionImageRepository.save(경매_이미지); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaProfileImageRepositoryFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaProfileImageRepositoryFixture.java index 1bf175301..2a855e0ed 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaProfileImageRepositoryFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/JpaProfileImageRepositoryFixture.java @@ -18,13 +18,12 @@ public class JpaProfileImageRepositoryFixture { protected String 업로드_이미지_파일명 = "uploadName"; protected String 저장된_이미지_파일명 = "storeName"; - protected Long 존재하지_않는_프로필_이미지_아이디 = -999L; - - protected ProfileImage 프로필_이미지; + protected String 존재하는_프로필_이미지_이름 = "프로필이미지.png"; + protected String 존재하지_않는_프로필_이미지_이름 = "invalid.png"; @BeforeEach void setUp() { - 프로필_이미지 = new ProfileImage("uploadName", "storeName"); + final ProfileImage 프로필_이미지 = new ProfileImage("프로필이미지.png", 존재하는_프로필_이미지_이름); profileImageRepository.save(프로필_이미지); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/ProfileImageRepositoryImplFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/ProfileImageRepositoryImplFixture.java index 719737f47..04a5ce2cd 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/ProfileImageRepositoryImplFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/infrastructure/persistence/fixture/ProfileImageRepositoryImplFixture.java @@ -2,29 +2,22 @@ import com.ddang.ddang.image.domain.ProfileImage; import com.ddang.ddang.image.infrastructure.persistence.JpaProfileImageRepository; -import jakarta.persistence.EntityManager; -import jakarta.persistence.PersistenceContext; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; @SuppressWarnings("NonAsciiCharacters") public class ProfileImageRepositoryImplFixture { - @PersistenceContext - private EntityManager em; - @Autowired private JpaProfileImageRepository profileImageRepository; - protected ProfileImage 프로필_이미지; + protected String 존재하는_프로필_이미지_이름 = "프로필이미지.png"; + protected String 존재하지_않는_프로필_이미지_이름 = "invalid.png"; @BeforeEach void fixtureSetUp() { - 프로필_이미지 = new ProfileImage("프로필이미지.png", "프로필이미지.png"); + final ProfileImage 프로필_이미지 = new ProfileImage("프로필이미지.png", 존재하는_프로필_이미지_이름); profileImageRepository.save(프로필_이미지); - - em.flush(); - em.clear(); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/ImageControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/ImageControllerTest.java index 2b5a9978e..178ac5a21 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/ImageControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/ImageControllerTest.java @@ -12,7 +12,7 @@ import java.net.MalformedURLException; -import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @@ -35,10 +35,10 @@ void setUp() { @Test void 지정한_사용자_아이디에_대한_사용자_이미지를_조회한다() throws Exception { // given - given(imageService.readProfileImage(anyLong())).willReturn(이미지_파일_리소스); + given(imageService.readProfileImage(anyString())).willReturn(이미지_파일_리소스); // when & then - mockMvc.perform(RestDocumentationRequestBuilders.get("/users/images/{id}", 프로필_이미지_아이디)) + mockMvc.perform(RestDocumentationRequestBuilders.get("/users/images/{storeName}", 프로필_이미지_이름)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.IMAGE_JPEG)) .andExpect(content().bytes(이미지_파일_바이트)); @@ -47,10 +47,10 @@ void setUp() { @Test void 사용자_이미지_조회시_지정한_아이디에_대한_이미지가_없는_경우_404를_반환한다() throws Exception { // given - given(imageService.readProfileImage(anyLong())).willThrow(new ImageNotFoundException("지정한 이미지를 찾을 수 없습니다.")); + given(imageService.readProfileImage(anyString())).willThrow(new ImageNotFoundException("지정한 이미지를 찾을 수 없습니다.")); // when & then - mockMvc.perform(RestDocumentationRequestBuilders.get("/users/images/{id}", 존재하지_않는_프로필_이미지_아이디)) + mockMvc.perform(RestDocumentationRequestBuilders.get("/users/images/{storeName}", 존재하지_않는_프로필_이미지_이름)) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.message").exists()); } @@ -58,10 +58,10 @@ void setUp() { @Test void 사용자_이미지_조회시_유효한_프로토콜이나_URL이_아닌_경우_500을_반환한다() throws Exception { // given - given(imageService.readProfileImage(anyLong())).willThrow(new MalformedURLException()); + given(imageService.readProfileImage(anyString())).willThrow(new MalformedURLException()); // when & then - mockMvc.perform(RestDocumentationRequestBuilders.get("/users/images/{id}", 프로필_이미지_아이디)) + mockMvc.perform(RestDocumentationRequestBuilders.get("/users/images/{storeName}", 프로필_이미지_이름)) .andExpect(status().isInternalServerError()) .andExpect(jsonPath("$.message").exists()); } @@ -69,10 +69,10 @@ void setUp() { @Test void 지정한_아이디에_대한_경매_이미지를_조회한다() throws Exception { // given - given(imageService.readAuctionImage(anyLong())).willReturn(이미지_파일_리소스); + given(imageService.readAuctionImage(anyString())).willReturn(이미지_파일_리소스); // when & then - mockMvc.perform(RestDocumentationRequestBuilders.get("/auctions/images/{id}", 경매_이미지_아이디)) + mockMvc.perform(RestDocumentationRequestBuilders.get("/auctions/images/{storeName}", 경매_이미지_이름)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.IMAGE_JPEG)) .andExpect(content().bytes(이미지_파일_바이트)); @@ -81,10 +81,10 @@ void setUp() { @Test void 경매_이미지_조회시_지정한_아이디에_대한_이미지가_없는_경우_404를_반환한다() throws Exception { // given - given(imageService.readAuctionImage(anyLong())).willThrow(new ImageNotFoundException("지정한 이미지를 찾을 수 없습니다.")); + given(imageService.readAuctionImage(anyString())).willThrow(new ImageNotFoundException("지정한 이미지를 찾을 수 없습니다.")); // when & then - mockMvc.perform(RestDocumentationRequestBuilders.get("/auctions/images/{id}", 존재하지_않는_경매_이미지_아이디)) + mockMvc.perform(RestDocumentationRequestBuilders.get("/auctions/images/{storeName}", 존재하지_않는_경매_이미지_이름)) .andExpect(status().isNotFound()) .andExpect(jsonPath("$.message").exists()); } @@ -92,10 +92,10 @@ void setUp() { @Test void 경매_이미지_조회시_유효한_프로토콜이나_URL이_아닌_경우_500을_반환한다() throws Exception { // given - given(imageService.readAuctionImage(anyLong())).willThrow(new MalformedURLException()); + given(imageService.readAuctionImage(anyString())).willThrow(new MalformedURLException()); // when & then - mockMvc.perform(RestDocumentationRequestBuilders.get("/auctions/images/{id}", 경매_이미지_아이디)) + mockMvc.perform(RestDocumentationRequestBuilders.get("/auctions/images/{storeName}", 경매_이미지_이름)) .andExpect(status().isInternalServerError()) .andExpect(jsonPath("$.message").exists()); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/fixture/ImageControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/fixture/ImageControllerFixture.java index dbac712ed..9fe6ed49e 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/fixture/ImageControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/fixture/ImageControllerFixture.java @@ -9,8 +9,8 @@ public class ImageControllerFixture extends CommonControllerSliceTest { protected byte[] 이미지_파일_바이트 = "이것은 이미지 파일의 바이트 코드입니다.".getBytes(); protected Resource 이미지_파일_리소스 = new ByteArrayResource(이미지_파일_바이트); - protected Long 프로필_이미지_아이디 = 1L; - protected Long 존재하지_않는_프로필_이미지_아이디 = -999L; - protected Long 경매_이미지_아이디 = 1L; - protected Long 존재하지_않는_경매_이미지_아이디 = -999L; + protected String 프로필_이미지_이름 = "profile_image.png"; + protected String 존재하지_않는_프로필_이미지_이름 = "invalid_profile_image.png"; + protected String 경매_이미지_이름 = "auction_image.png"; + protected String 존재하지_않는_경매_이미지_이름 = "invalid_auction_image.png"; } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculatorTest.java b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculatorTest.java index 491761182..13f22b1f9 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculatorTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculatorTest.java @@ -16,43 +16,43 @@ class ImageUrlCalculatorTest extends ImageUrlCalculatorFixture { @Test void 프로필_사진의_상대_URL로_절대_경로를_계산한다() { // when - final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_상대_URL, 프로필_이미지_아이디); + final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_상대_URL, 프로필_이미지_저장_이름); // then - assertThat(actual).contains(프로필_이미지_전체_URL); + assertThat(actual).contains(프로필_이미지_저장_이름_기반_전체_URL); } @Test void 프로필_사진의_아이디가_null인_경우_기본_이미지의_상대_URL로_절대_경로를_계산한다() { // when - final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_상대_URL, 프로필_이미지_아이디가_null); + final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_상대_URL, 프로필_이미지_저장_이름이_null); // then - assertThat(actual).contains(프로필_기본_이미지_전체_URL); + assertThat(actual).contains(이미지_저장_이름_기반_프로필_기본_이미지_전체_URL); } @Test void 경매_대표_이미지의_상대_URL로_절대_경로를_계산한다() { // when - final String actual = ImageUrlCalculator.calculateBy(경매_이미지_상대_URL, 경매_이미지_아이디); + final String actual = ImageUrlCalculator.calculateBy(경매_이미지_상대_URL, 경매_이미지_저장_이름); // then - assertThat(actual).contains(경매_이미지_전체_URL); + assertThat(actual).contains(경매_이미지_저장_이름_기반_전체_URL); } @Test void 프로필_사진의_절대_URL로_절대_경로를_계산한다() { // when - final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_절대_URL, 프로필_이미지_아이디); + final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_절대_URL, 프로필_이미지_저장_이름); // then - assertThat(actual).isEqualTo(프로필_이미지_전체_URL); + assertThat(actual).isEqualTo(프로필_이미지_저장_이름_기반_전체_URL); } @Test void 프로필_사진의_아이디가_null인_경우_기본_이미지의_절대_URL로_절대_경로를_계산한다() { // when - final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_절대_URL, 프로필_이미지_아이디가_null); + final String actual = ImageUrlCalculator.calculateBy(프로필_이미지_절대_URL, 프로필_이미지_저장_이름이_null); // then assertThat(actual).isEqualTo(프로필_기본_이미지_전체_URL); @@ -61,9 +61,9 @@ class ImageUrlCalculatorTest extends ImageUrlCalculatorFixture { @Test void 경매_대표_이미지의_절대_URL로_절대_경로를_계산한다() { // when - final String actual = ImageUrlCalculator.calculateBy(경매_이미지_절대_URL, 경매_이미지_아이디); + final String actual = ImageUrlCalculator.calculateBy(경매_이미지_절대_URL, 경매_이미지_저장_이름); // then - assertThat(actual).isEqualTo(경매_이미지_전체_URL); + assertThat(actual).isEqualTo(경매_이미지_저장_이름_기반_전체_URL); } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/fixture/ImageUrlCalculatorFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/fixture/ImageUrlCalculatorFixture.java index abdeaf933..89db85cee 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/fixture/ImageUrlCalculatorFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/image/presentation/util/fixture/ImageUrlCalculatorFixture.java @@ -9,11 +9,12 @@ public class ImageUrlCalculatorFixture { protected ImageRelativeUrl 경매_이미지_상대_URL = ImageRelativeUrl.AUCTION; protected String 프로필_이미지_절대_URL = "/users/images/"; - protected Long 프로필_이미지_아이디 = 2L; - protected Long 프로필_이미지_아이디가_null = null; - protected String 프로필_이미지_전체_URL = 프로필_이미지_절대_URL + 프로필_이미지_아이디; - protected String 프로필_기본_이미지_전체_URL = 프로필_이미지_절대_URL + "1"; + protected String 프로필_기본_이미지_전체_URL = 프로필_이미지_절대_URL + "default_profile_image.png"; + protected String 프로필_이미지_저장_이름 = "profile_image_store_name.png"; + protected String 프로필_이미지_저장_이름이_null = null; + protected String 프로필_이미지_저장_이름_기반_전체_URL = 프로필_이미지_절대_URL + 프로필_이미지_저장_이름; + protected String 이미지_저장_이름_기반_프로필_기본_이미지_전체_URL = 프로필_이미지_절대_URL + "default_profile_image.png"; protected String 경매_이미지_절대_URL = "/auctions/images/"; - protected Long 경매_이미지_아이디 = 1L; - protected String 경매_이미지_전체_URL = 경매_이미지_절대_URL + 경매_이미지_아이디; + protected String 경매_이미지_저장_이름 = "auction_image_store_name.png"; + protected String 경매_이미지_저장_이름_기반_전체_URL = 경매_이미지_절대_URL + 경매_이미지_저장_이름; } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/fixture/ReportControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/fixture/ReportControllerFixture.java index ae67ccf80..c69f9dbf8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/fixture/ReportControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/fixture/ReportControllerFixture.java @@ -35,7 +35,7 @@ public class ReportControllerFixture extends CommonControllerSliceTest { protected CreateAuctionReportRequest 경매_아이디가_음수인_신고_request = new CreateAuctionReportRequest(-999L, "신고합니다"); protected static CreateAuctionReportRequest 신고_내용이_null인_경매_신고_request = new CreateAuctionReportRequest(1L, null); protected static CreateAuctionReportRequest 신고_내용이_빈값인_경매_신고_request = new CreateAuctionReportRequest(1L, ""); - private ReadUserInReportDto 판매자_정보_dto = new ReadUserInReportDto(1L, "판매자", 1L, 4.0d, "12345", false); + private ReadUserInReportDto 판매자_정보_dto = new ReadUserInReportDto(1L, "판매자", "profile_image.png", 4.0d, "12345", false); private ReadAuctionInReportDto 신고할_경매_정보_dto = new ReadAuctionInReportDto( 1L, 판매자_정보_dto, @@ -49,21 +49,21 @@ public class ReportControllerFixture extends CommonControllerSliceTest { ); protected ReadAuctionReportDto 경매_신고_dto1 = new ReadAuctionReportDto( 1L, - new ReadReporterDto(2L, "회원1", 2L, 5.0, false), + new ReadReporterDto(2L, "회원1", "profile_image.png", 5.0, false), LocalDateTime.now(), 신고할_경매_정보_dto, "신고합니다." ); protected ReadAuctionReportDto 경매_신고_dto2 = new ReadAuctionReportDto( 2L, - new ReadReporterDto(3L, "회원2", 3L, 5.0, false), + new ReadReporterDto(3L, "회원2", "profile_image.png", 5.0, false), LocalDateTime.now(), 신고할_경매_정보_dto, "신고합니다." ); protected ReadAuctionReportDto 경매_신고_dto3 = new ReadAuctionReportDto( 3L, - new ReadReporterDto(4L, "회원3", 4L, 5.0, false), + new ReadReporterDto(4L, "회원3", "profile_image.png", 5.0, false), LocalDateTime.now(), 신고할_경매_정보_dto, "신고합니다." @@ -86,8 +86,8 @@ public class ReportControllerFixture extends CommonControllerSliceTest { LocalDateTime.now().plusDays(2), 2 ); - private ReadUserInReportDto 구매자_정보_dto1 = new ReadUserInReportDto(2L, "구매자1", 2L, 4.0d, "12346", false); - private ReadReporterDto 신고자_정보_dto1 = new ReadReporterDto(2L, "구매자1", 2L, 4.0d, false); + private ReadUserInReportDto 구매자_정보_dto1 = new ReadUserInReportDto(2L, "구매자1", "profile_image.png", 4.0d, "12346", false); + private ReadReporterDto 신고자_정보_dto1 = new ReadReporterDto(2L, "구매자1", "profile_image.png", 4.0d, false); protected ReadChatRoomReportDto 채팅방_신고_dto1 = new ReadChatRoomReportDto( 1L, 신고자_정보_dto1, @@ -106,8 +106,8 @@ public class ReportControllerFixture extends CommonControllerSliceTest { LocalDateTime.now().plusDays(2), 2 ); - private ReadUserInReportDto 구매자_정보_dto2 = new ReadUserInReportDto(3L, "구매자2", 3L, 4.0d, "12347", false); - private ReadReporterDto 신고자_정보_dto2 = new ReadReporterDto(3L, "구매자2", 3L, 4.0d, false); + private ReadUserInReportDto 구매자_정보_dto2 = new ReadUserInReportDto(3L, "구매자2", "profile_image.png", 4.0d, "12347", false); + private ReadReporterDto 신고자_정보_dto2 = new ReadReporterDto(3L, "구매자2", "profile_image.png", 4.0d, false); protected ReadChatRoomReportDto 채팅방_신고_dto2 = new ReadChatRoomReportDto( 2L, 신고자_정보_dto2, @@ -126,8 +126,8 @@ public class ReportControllerFixture extends CommonControllerSliceTest { LocalDateTime.now().plusDays(2), 2 ); - private ReadUserInReportDto 구매자_정보_dto3 = new ReadUserInReportDto(3L, "구매자2", 3L, 4.0d, "12347", false); - private ReadReporterDto 신고자_정보_dto3 = new ReadReporterDto(3L, "구매자2", 3L, 4.0d, false); + private ReadUserInReportDto 구매자_정보_dto3 = new ReadUserInReportDto(3L, "구매자2", "profile_image.png", 4.0d, "12347", false); + private ReadReporterDto 신고자_정보_dto3 = new ReadReporterDto(3L, "구매자2", "profile_image.png", 4.0d, false); protected ReadChatRoomReportDto 채팅방_신고_dto3 = new ReadChatRoomReportDto( 3L, 신고자_정보_dto3, @@ -147,7 +147,7 @@ public class ReportControllerFixture extends CommonControllerSliceTest { protected static CreateQuestionReportRequest 신고_내용이_null인_질문_신고_request = new CreateQuestionReportRequest(1L, 1L, null); protected static CreateQuestionReportRequest 신고_내용이_빈값인_질문_신고_request = new CreateQuestionReportRequest(1L, 1L, ""); - private ReadUserInReportDto 질문자_dto = new ReadUserInReportDto(1L, "사용자", 1L, 5.0d, "12345", false); + private ReadUserInReportDto 질문자_dto = new ReadUserInReportDto(1L, "사용자", "profile_image.png", 5.0d, "12345", false); private ReadQuestionInReportDto 질문_dto1 = new ReadQuestionInReportDto(1L, 질문자_dto, "질문드립니다.", LocalDateTime.now()); private ReadQuestionInReportDto 질문_dto2 = new ReadQuestionInReportDto(2L, 질문자_dto, "질문드립니다.", LocalDateTime.now()); private ReadQuestionInReportDto 질문_dto3 = new ReadQuestionInReportDto(3L, 질문자_dto, "질문드립니다.", LocalDateTime.now()); @@ -165,12 +165,11 @@ public class ReportControllerFixture extends CommonControllerSliceTest { protected CreateAnswerReportRequest 답변_아이디가_음수인_질문_신고_request = new CreateAnswerReportRequest(1L, -1L, "신고합니다."); protected static CreateAnswerReportRequest 신고_내용이_null인_답변_신고_request = new CreateAnswerReportRequest(1L, 1L, null); protected static CreateAnswerReportRequest 신고_내용이_빈값인_답변_신고_request = new CreateAnswerReportRequest(1L, 1L, ""); - private ReadUserInReportDto 답변자_dto = new ReadUserInReportDto(1L, "사용자", 1L, 5.0d, "12345", false); + private ReadUserInReportDto 답변자_dto = new ReadUserInReportDto(1L, "사용자", "profile_image.png", 5.0d, "12345", false); private ReadAnswerInReportDto 답변_dto1 = new ReadAnswerInReportDto(1L, 답변자_dto, "답변드립니다.", LocalDateTime.now()); private ReadAnswerInReportDto 답변_dto2 = new ReadAnswerInReportDto(2L, 답변자_dto, "답변드립니다.", LocalDateTime.now()); private ReadAnswerInReportDto 답변_dto3 = new ReadAnswerInReportDto(3L, 답변자_dto, "답변드립니다.", LocalDateTime.now()); protected ReadAnswerReportDto 답변_신고_dto1 = new ReadAnswerReportDto(1L, 신고자_정보_dto1, LocalDateTime.now(), 답변_dto1, "신고합니다."); protected ReadAnswerReportDto 답변_신고_dto2 = new ReadAnswerReportDto(2L, 신고자_정보_dto1, LocalDateTime.now(), 답변_dto2, "신고합니다."); protected ReadAnswerReportDto 답변_신고_dto3 = new ReadAnswerReportDto(3L, 신고자_정보_dto1, LocalDateTime.now(), 답변_dto3, "신고합니다."); - } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/review/presentation/fixture/ReviewControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/review/presentation/fixture/ReviewControllerFixture.java index d34dce198..89427b623 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/review/presentation/fixture/ReviewControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/review/presentation/fixture/ReviewControllerFixture.java @@ -16,12 +16,12 @@ public class ReviewControllerFixture extends CommonControllerSliceTest { private Long 유효한_평가_대상_아이디 = 2L; private Long 유효한_경매_아이디 = 1L; private Long 사용자가_이미_평가한_경매_아이디 = 2L; - private Long 판매자1_프로필_이미지_아이디 = 1L; - private Long 판매자2_프로필_이미지_아이디 = 2L; - private Long 구매자_프로필_이미지_아이디 = 3L; - private ReadUserInReviewDto 판매자1 = new ReadUserInReviewDto(1L, "판매자1", 판매자1_프로필_이미지_아이디, 5.0d, "12347"); - private ReadUserInReviewDto 판매자2 = new ReadUserInReviewDto(2L, "판매자2", 판매자2_프로필_이미지_아이디, 5.0d, "12348"); - protected ReadUserInReviewDto 구매자 = new ReadUserInReviewDto(3L, "구매자", 구매자_프로필_이미지_아이디, 5.0d, "12349"); + private String 판매자1_프로필_이미지_저장_이름 = "profile_image1.png"; + private String 판매자2_프로필_이미지_저장_이름 = "profile_image2.png"; + private String 구매자_프로필_이미지_저장_이름 = "profile_image3.png"; + private ReadUserInReviewDto 판매자1 = new ReadUserInReviewDto(1L, "판매자1", 판매자1_프로필_이미지_저장_이름, 5.0d, "12347"); + private ReadUserInReviewDto 판매자2 = new ReadUserInReviewDto(2L, "판매자2", 판매자2_프로필_이미지_저장_이름, 5.0d, "12348"); + protected ReadUserInReviewDto 구매자 = new ReadUserInReviewDto(3L, "구매자", 구매자_프로필_이미지_저장_이름, 5.0d, "12349"); protected String 액세스_토큰 = "Bearer accessToken"; protected PrivateClaims 유효한_작성자_비공개_클레임 = new PrivateClaims(유효한_평가_작성자_아이디); protected CreateReviewRequest 사용자_평가_등록_요청 = diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java index c68ffc576..11db5551e 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java @@ -36,7 +36,7 @@ class UserServiceTest extends UserServiceFixture { // then SoftAssertions.assertSoftly(softAssertions -> { softAssertions.assertThat(actual.name()).isEqualTo(사용자.getName()); - softAssertions.assertThat(actual.profileImageId()).isEqualTo(사용자.getProfileImage().getId()); + softAssertions.assertThat(actual.profileImageStoreName()).isEqualTo(사용자.getProfileImage().getImage().getStoreName()); softAssertions.assertThat(actual.reliability()).isEqualTo(사용자.getReliability().getValue()); }); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java index d907a04fd..7ce64a559 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java @@ -60,6 +60,24 @@ class JpaUserRepositoryTest extends JpaUserRepositoryFixture { assertThat(actual).isEmpty(); } + @Test + void 존재하는_사용자_아이디를_전달하면_해당_사용자를_Optional로_감싸_반환하고_프로필_이미지도_한번에_조회한다() { + // when + final Optional actual = userRepository.findByIdWithProfileImage(사용자.getId()); + + // then + assertThat(actual).contains(사용자); + } + + @Test + void 존재하지_않는_사용자_아이디를_전달하면_빈_Optional을_반환하고_프로필_이미지도_한번에_조회한다() { + // when + final Optional actual = userRepository.findByIdWithProfileImage(존재하지_않는_사용자_아이디); + + // then + assertThat(actual).isEmpty(); + } + @Test void 회원탈퇴한_사용자의_id를_전달하면_빈_Optional을_반환한다() { // when diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImplTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImplTest.java index 775126096..2e8e2c5df 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImplTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/UserRepositoryImplTest.java @@ -66,6 +66,24 @@ void setUp(@Autowired final JpaUserRepository jpaUserRepository) { assertThat(actual).isEmpty(); } + @Test + void 존재하는_사용자_아이디를_전달하면_해당_사용자를_Optional로_감싸_반환하고_프로필_이미지도_한번에_조회한다() { + // when + final Optional actual = userRepository.findByIdWithProfileImage(사용자.getId()); + + // then + assertThat(actual).contains(사용자); + } + + @Test + void 존재하지_않는_사용자_아이디를_전달하면_빈_Optional을_반환하고_프로필_이미지도_한번에_조회한다() { + // when + final Optional actual = userRepository.findByIdWithProfileImage(존재하지_않는_사용자_아이디); + + // then + assertThat(actual).isEmpty(); + } + @Test void 회원탈퇴한_사용자의_id를_전달하면_빈_Optional을_반환한다() { // when diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserAuctionControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserAuctionControllerFixture.java index eb2731dc4..75f1ceef6 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserAuctionControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserAuctionControllerFixture.java @@ -35,12 +35,12 @@ public class UserAuctionControllerFixture extends CommonControllerSliceTest { LocalDateTime.now(), LocalDateTime.now(), List.of(직거래_지역_정보_dto), - List.of(1L), + List.of("auction_image.png"), 2, "main1", "sub1", 1L, - 1L, + "profile_image.png", "판매자", 3.5d, false, @@ -58,12 +58,12 @@ public class UserAuctionControllerFixture extends CommonControllerSliceTest { LocalDateTime.now(), LocalDateTime.now(), List.of(직거래_지역_정보_dto), - List.of(1L), + List.of("auction_image.png"), 2, "main2", "sub2", 1L, - 1L, + "profile_image.png", "판매자", 3.5d, false, diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserControllerFixture.java b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserControllerFixture.java index fa46afbd5..0976a80e1 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserControllerFixture.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/fixture/UserControllerFixture.java @@ -17,10 +17,10 @@ public class UserControllerFixture extends CommonControllerSliceTest { protected PrivateClaims 존재하지_않는_사용자_ID_클레임 = new PrivateClaims(999L); protected String 탈퇴한_사용자_이름 = "알 수 없음"; - protected ReadUserDto 사용자_정보_조회_dto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345", false); - protected ReadUserDto 탈퇴한_사용자_정보_조회_dto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345", true); + protected ReadUserDto 사용자_정보_조회_dto = new ReadUserDto(1L, "사용자1", "profile_image.png", 4.6d, "12345", false); + protected ReadUserDto 탈퇴한_사용자_정보_조회_dto = new ReadUserDto(1L, "사용자1", "profile_image.png", 4.6d, "12345", true); protected UpdateUserRequest 수정할_이름_request = new UpdateUserRequest("updateName"); - protected ReadUserDto 수정후_사용자_정보_조회_dto = new ReadUserDto(1L, 수정할_이름_request.name(), 1L, 4.6d, "12345", false); + protected ReadUserDto 수정후_사용자_정보_조회_dto = new ReadUserDto(1L, 수정할_이름_request.name(), "profile_image.png", 4.6d, "12345", false); private String json = "{\"name\":\"" + 수정할_이름_request.name() + "\"}"; private byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8); protected MockMultipartFile 수정할_이름 = new MockMultipartFile(
Table 2. /oauth2/withdrawal/{oauth2Type}