Skip to content

Commit

Permalink
feat: 가게당 이미지 3개까지 추가 가능하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
eckrin committed Nov 16, 2023
1 parent 236e3bc commit 5a68e75
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
6 changes: 6 additions & 0 deletions src/main/generated/com/kusitms/jipbap/order/QOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class QOrder extends EntityPathBase<Order> {

public final NumberPath<Long> orderCount = createNumber("orderCount", Long.class);

public final NumberPath<Long> regionId = createNumber("regionId", Long.class);

public final EnumPath<OrderStatus> status = createEnum("status", OrderStatus.class);

public final NumberPath<Long> totalPrice = createNumber("totalPrice", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;

Expand Down
7 changes: 7 additions & 0 deletions src/main/generated/com/kusitms/jipbap/store/QStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public class QStore extends EntityPathBase<Store> {

public final StringPath description = createString("description");

public final com.kusitms.jipbap.user.entity.QGlobalRegion globalRegion;

public final NumberPath<Long> id = createNumber("id", Long.class);

public final StringPath image = createString("image");

public final StringPath image2 = createString("image2");

public final StringPath image3 = createString("image3");

public final BooleanPath koreanYn = createBoolean("koreanYn");

public final NumberPath<Long> minOrderAmount = createNumber("minOrderAmount", Long.class);
Expand Down Expand Up @@ -70,6 +76,7 @@ public QStore(PathMetadata metadata, PathInits inits) {

public QStore(Class<? extends Store> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.globalRegion = inits.isInitialized("globalRegion") ? new com.kusitms.jipbap.user.entity.QGlobalRegion(forProperty("globalRegion")) : null;
this.owner = inits.isInitialized("owner") ? new com.kusitms.jipbap.user.QUser(forProperty("owner"), inits.get("owner")) : null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kusitms/jipbap/common/utils/S3Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class S3Utils {

// originalFilename에 Random UUID 붙여서 같은 파일명 덮어쓰기 방지
public static String saveFile(AmazonS3 amazonS3, String bucket, MultipartFile multipartFile) throws IOException {
String originalFilename = multipartFile.getOriginalFilename() + UUID.randomUUID();
String originalFilename = multipartFile.getOriginalFilename() + "_" + UUID.randomUUID();

ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(multipartFile.getSize());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/kusitms/jipbap/store/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class Store extends DateEntity {
private Double avgRate; // 가게 평점
private Long minOrderAmount; //최소 주문 금액
private String image;
private String image2;
private String image3;

private Long reviewCount; // 가게 후기 개수
private Long bookmarkCount; // 가게 즐겨찾기 횟수 (추천순)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class StoreController {
public CommonResponse<StoreDto> registerStore(
@Auth AuthInfo authInfo,
@RequestPart(value = "dto") RegisterStoreRequestDto dto,
@RequestPart(value = "image", required = false) MultipartFile image
@RequestPart(value = "image", required = false) List<MultipartFile> image
){
return new CommonResponse<>(storeService.registerStore(authInfo.getEmail(), dto, image));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public Slice<StoreDetailResponseDto> searchByKeywordOrderBySort(User user, Pagea
List<StoreDetailResponseDto> dtoList = new ArrayList<>();

for(Store s: storeList) {
String[] strArr = new String[3];
strArr[0] = s.getImage();
strArr[1] = s.getImage2();
strArr[2] = s.getImage3();
dtoList.add(new StoreDetailResponseDto(
new StoreDto(
s.getId(),
Expand All @@ -51,7 +55,7 @@ public Slice<StoreDetailResponseDto> searchByKeywordOrderBySort(User user, Pagea
s.getKoreanYn(),
s.getAvgRate(),
s.getMinOrderAmount(),
s.getImage()
strArr
),
isUserBookmarkedStore(user, s)
));
Expand All @@ -77,8 +81,8 @@ private Boolean isUserBookmarkedStore(User user, Store store) {
private BooleanExpression lastStore(Pageable pageable, List<OrderSpecifier<?>> specifiers, Long id) {
if(id==null) return null;

Store stdStore = queryFactory.selectFrom(QStore.store)
.where(QStore.store.id.eq(id))
Store stdStore = queryFactory.selectFrom(store)
.where(store.id.eq(id))
.fetchFirst();

for (Sort.Order order : pageable.getSort()) {
Expand Down
51 changes: 39 additions & 12 deletions src/main/java/com/kusitms/jipbap/store/StoreService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,52 @@ public class StoreService {
private String bucket;

@Transactional
public StoreDto registerStore(String email, RegisterStoreRequestDto dto, MultipartFile image) {
public StoreDto registerStore(String email, RegisterStoreRequestDto dto, List<MultipartFile> image) {
User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다."));
String imageUri = null;
String[] imageUri = new String[3];
if(storeRepository.existsByOwner(user)) {
throw new StoreExistsException("이미 가게를 생성한 유저입니다.");
}

//이미지가 null이 아닌 경우 s3 업로드
if(image!=null) {
try {
imageUri = S3Utils.saveFile(amazonS3, bucket, image);
} catch (IOException e) {
throw new S3RegisterFailureException("가게 이미지 저장 중 오류가 발생했습니다.");
for(int i=0; i<3; i++) {
if(image.get(i)!=null) {
try {
imageUri[i] = S3Utils.saveFile(amazonS3, bucket, image.get(i));
} catch (IOException e) {
throw new S3RegisterFailureException("가게 이미지 저장 중 오류가 발생했습니다.");
}
}
}

Store store = storeRepository.save(
new Store(null, user, user.getGlobalRegion(), dto.getName(), dto.getDescription(), dto.getKoreanYn(), 0D, dto.getMinOrderAmount(),null, 0L, 0L, 0L)
Store.builder()
.id(null)
.owner(user)
.globalRegion(user.getGlobalRegion())
.name(dto.getName())
.description(dto.getDescription())
.koreanYn(dto.getKoreanYn())
.avgRate(0D)
.minOrderAmount(dto.getMinOrderAmount())
.image(imageUri[0])
.image2(imageUri[1])
.image3(imageUri[2])
.reviewCount(0L)
.bookmarkCount(0L)
.rateCount(0L)
.build()
);

return new StoreDto(store.getId(), store.getName(), store.getDescription(), store.getKoreanYn(), store.getAvgRate(), store.getBookmarkCount(), store.getImage());
return new StoreDto(
store.getId(),
store.getName(),
store.getDescription(),
store.getKoreanYn(),
store.getAvgRate(),
store.getBookmarkCount(),
imageUri
);
}

@Transactional
Expand All @@ -82,6 +107,7 @@ public StoreDetailResponseDto getStoreDetail(String email, Long storeId) {
User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다."));

Store store = storeRepository.findById(storeId).orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다."));

return new StoreDetailResponseDto(
new StoreDto(
store.getId(),
Expand All @@ -90,7 +116,7 @@ public StoreDetailResponseDto getStoreDetail(String email, Long storeId) {
store.getKoreanYn(),
store.getAvgRate(),
store.getMinOrderAmount(),
store.getImage()
new String[]{store.getImage(), store.getImage2(), store.getImage3()}
),
isStoreBookmarked(user, store)
);
Expand All @@ -111,7 +137,7 @@ public StoreDto bookmarkStore(String email, Long storeId) {
store.getKoreanYn(),
store.getAvgRate(),
store.getMinOrderAmount(),
store.getImage()
new String[]{store.getImage(), store.getImage2(), store.getImage3()}
);
}

Expand All @@ -122,6 +148,7 @@ public BookmarkedStoreListResponseDto findBookmarkedStore(String email) {
List<StoreBookmark> storeBookmarks = storeBookmarkRepository.findByUser(user);
List<StoreDto> sbList = new ArrayList<>();


for (StoreBookmark sb : storeBookmarks) {
sbList.add(new StoreDto(
sb.getId(),
Expand All @@ -130,7 +157,7 @@ public BookmarkedStoreListResponseDto findBookmarkedStore(String email) {
sb.getStore().getKoreanYn(),
sb.getStore().getAvgRate(),
sb.getStore().getMinOrderAmount(),
sb.getStore().getImage()
new String[]{sb.getStore().getImage(), sb.getStore().getImage2(), sb.getStore().getImage3()}
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kusitms/jipbap/store/dto/StoreDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public class StoreDto {
private Boolean koreanYn;
private Double avgRate; // 가게 평점
private Long minOrderAmount; //최소 주문 금액
private String image;
private String[] images;
}

0 comments on commit 5a68e75

Please sign in to comment.