Skip to content

Commit

Permalink
fix: 카페 이미지 3개 초과하여 저장 시 예외 반환하는 로직 버그 수정 (#140)
Browse files Browse the repository at this point in the history
* fix: modified cafeImagesCounts filtering logic to include isUsed column

* style: modify ExceedCageImagesTotalCountsException message

* refact: extract method for cafe image ownership and isused check
  • Loading branch information
Ji-soo708 authored Dec 9, 2023
1 parent 0dbdf7a commit b32fde2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class ExceedCageImagesTotalCountsException extends BadRequestException{
public ExceedCageImagesTotalCountsException() {
super("카페 이미지는 3개 이상 등록하실 수 없습니다.", 2008);
super("카페 이미지는 4개 이상 등록하실 수 없습니다.", 2008);
}
}
6 changes: 5 additions & 1 deletion src/main/java/mocacong/server/service/CafeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,17 @@ public CafeImagesSaveResponse saveCafeImage(Long memberId, String mapId, List<Mu
private void validateOwnedCafeImagesCounts(Cafe cafe, Member member, List<MultipartFile> requestCafeImages) {
List<CafeImage> currentOwnedCafeImages = cafe.getCafeImages()
.stream()
.filter(cafeImage -> cafeImage.isOwned(member))
.filter(cafeImage -> isOwnedAndUsed(cafeImage, member))
.collect(Collectors.toList());
if (currentOwnedCafeImages.size() + requestCafeImages.size() > CAFE_IMAGES_PER_MEMBER_LIMIT_COUNTS) {
throw new ExceedCageImagesTotalCountsException();
}
}

private boolean isOwnedAndUsed(CafeImage cafeImage, Member member) {
return cafeImage.isOwned(member) && cafeImage.getIsUsed();
}

@Transactional(readOnly = true)
public CafeImagesResponse findCafeImages(Long memberId, String mapId, Integer page, int count) {
Cafe cafe = cafeRepository.findByMapId(mapId)
Expand Down

0 comments on commit b32fde2

Please sign in to comment.