Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이미지url에 id 대신 파일 이름을 사용하도록 변경 #717

Merged
merged 17 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f1fff59
refactor: 이미지 상대 url 기반으로 url을 계산하는 메서드 파라미터로 이미지 id 대신 이미지 이름을 받도록 변경
kwonyj1022 Oct 18, 2023
0c7b648
refactor: 이미지 절대 url 기반으로 url을 계산하는 메서드 파라미터로 이미지 id 대신 이미지 이름을 받도록 변경
kwonyj1022 Oct 18, 2023
1375972
refactor: 경매 조회 시 판매자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
fd9e440
refactor: 입찰 목록 조회 시 입찰자 정보 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
05b09e2
refactor: 채팅방 관련 조회 시 참여자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
69a134f
refactor: qna 관련 조회 시 사용자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
a02c1d6
refactor: 신고 관련 조회 시 사용자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
c98c3a7
refactor: 평가 관련 조회 시 사용자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
7ad27b7
refactor: 사용자 정보 조회 시 사용자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
f6c2d4e
refactor: 메시지 알림 시 작성자 프로필 이미지 조회로 인한 n+1 개선
kwonyj1022 Oct 18, 2023
5aa95a9
feat: 이미지 이름이 포함된 url로 조회 시 이미지 파일을 반환하는 기능 추가
kwonyj1022 Oct 18, 2023
f66f23e
docs: 문서 최신화
kwonyj1022 Oct 18, 2023
d56bda4
style: 개행 수정 및 누락된 final 추가
kwonyj1022 Nov 3, 2023
0cf6634
ci: 브랜치 최신화
kwonyj1022 Nov 3, 2023
e5e8cad
rename: test에 사용되는 fixture 클래스 이름 변경
kwonyj1022 Nov 3, 2023
0195e3d
ci: 브랜치 최신화
kwonyj1022 Nov 17, 2023
beebe84
ci: 충돌 해결
kwonyj1022 Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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
) {

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()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,12 +19,12 @@ public record ReadAuctionDto(
LocalDateTime registerTime,
LocalDateTime closingTime,
List<ReadRegionsDto> auctionRegions,
List<Long> auctionImageIds,
List<String> auctionImageStoreNames,
int auctioneerCount,
String mainCategory,
String subCategory,
Long sellerId,
Long sellerProfileId,
String sellerProfileImageStoreName,
String sellerName,
double sellerReliability,
boolean isSellerDeleted,
Expand All @@ -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(),
Expand All @@ -59,10 +58,10 @@ public static ReadAuctionDto of(final Auction auction, final LocalDateTime targe
);
}

private static List<Long> convertImageIds(final Auction auction) {
private static List<String> convertImageStoreNames(final Auction auction) {
return auction.getAuctionImages()
.stream()
.map(AuctionImage::getId)
.map(ImageStoreNameProcessor::process)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public interface JpaAuctionRepository extends JpaRepository<Auction, Long> {
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<Auction> findTotalAuctionById(final Long id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private List<Auction> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static AuctionDetailResponse from(final ReadAuctionDto dto) {
}

private static List<String> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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()),
floatReliability
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

public interface JpaBidRepository extends JpaRepository<Bid, Long> {

@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<Bid> findAllByAuctionIdOrderByIdAsc(final Long auctionId);

@Query("SELECT b FROM Bid b WHERE b.auction.id = :auctionId ORDER BY b.id DESC LIMIT 1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

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) {
return new ReadAuctionInChatRoomDto(
auction.getId(),
auction.getTitle(),
convertPrice(auction.getLastBid()),
thumbnailImage.getId()
ImageStoreNameProcessor.process(thumbnailImage)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ public Optional<ChatRoomAndImageDto> 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(
Comment on lines -28 to 32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

칭찬

👍👍👍

JPAExpressions
.select(auctionImage.id.min())
.from(auctionImage)
.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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ public List<ChatRoomAndMessageAndImageDto> findAllChatRoomInfoByUserIdOrderByLas
final List<ChatRoomAndMessageAndImageQueryProjectionDto> unsortedDtos =
queryFactory.select(new QChatRoomAndMessageAndImageQueryProjectionDto(chatRoom, message, 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())
.from(auctionImage)
.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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Comment on lines -22 to -23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

칭찬

잊지않고 해주셨군요 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

칭찬

훌륭합니다 👍


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Loading