From 5ea0c621418d322f6eb540373fed64b11f4377b0 Mon Sep 17 00:00:00 2001 From: joonghyun Date: Wed, 5 Jun 2024 22:53:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#122=20fix:=20=EA=B7=B8=EB=A3=B9=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=B5=9C?= =?UTF-8?q?=EA=B7=BC=20=ED=8D=BC=EC=A6=90=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=BC=EC=9E=90=EC=99=80=20=EA=B7=B8=EB=A3=B9=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=9D=BC=EC=9E=90=EB=A5=BC=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lesso/neverland/group/application/GroupService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lesso/neverland/group/application/GroupService.java b/src/main/java/com/lesso/neverland/group/application/GroupService.java index b4e27d8..c0ba547 100644 --- a/src/main/java/com/lesso/neverland/group/application/GroupService.java +++ b/src/main/java/com/lesso/neverland/group/application/GroupService.java @@ -60,8 +60,9 @@ public BaseResponse getGroupList() { group.getUserTeams().size(), group.getAdmin().getProfile().getNickname(), calculateRecentUpdate(group))) - .sorted(Comparator.comparing(groupDto -> calculateDaysSinceRecentUpdate(groupDto.groupIdx()))) - .toList(); + .sorted(Comparator.comparing((GroupListDto groupDto) -> calculateDaysSinceRecentUpdate(groupDto.groupIdx())) + .thenComparing(groupDto -> groupRepository.findById(groupDto.groupIdx()) + .map(Team::getCreatedDate).orElse(LocalDate.MIN), Comparator.reverseOrder())).toList(); return new BaseResponse<>(new GroupListResponse(groupListDto)); } @@ -69,8 +70,8 @@ public BaseResponse getGroupList() { private long calculateDaysSinceRecentUpdate(Long groupIdx) { Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); Puzzle recentPuzzle = puzzleRepository.findTopByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE); - if (recentPuzzle == null) return Long.MAX_VALUE; // 최근 퍼즐 없으면 큰 값 반환 LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul")); + if (recentPuzzle == null) return ChronoUnit.DAYS.between(group.getCreatedDate(), today); // 그룹 생성일과 오늘 사이 일수 LocalDate puzzleCreatedDate = recentPuzzle.getCreatedDate(); return ChronoUnit.DAYS.between(puzzleCreatedDate, today); } From 784eca33b3d83870ebdf5c6d098b5395865d70ca Mon Sep 17 00:00:00 2001 From: joonghyun Date: Wed, 5 Jun 2024 23:02:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#87=20fix:=20=ED=8D=BC=EC=A6=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EA=B0=80=20?= =?UTF-8?q?=EC=97=86=EC=96=B4=EB=8F=84=20=EC=83=9D=EC=84=B1=EB=90=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../neverland/puzzle/application/PuzzleService.java | 11 ++++++----- .../com/lesso/neverland/puzzle/domain/Puzzle.java | 6 +++--- .../puzzle/presentation/PuzzleController.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java index 1a750dc..b1a776d 100644 --- a/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java +++ b/src/main/java/com/lesso/neverland/puzzle/application/PuzzleService.java @@ -144,10 +144,12 @@ public BaseResponse createPuzzle(Long groupIdx, MultipartF Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX)); User writer = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); - String imagePath = imageService.uploadImage("puzzle", image); LocalDate puzzleDate = convertToLocalDate(createPuzzleRequest.puzzleDate()); - - Puzzle newPuzzle = createPuzzle(createPuzzleRequest, group, writer, imagePath, puzzleDate); + Puzzle newPuzzle = createPuzzle(createPuzzleRequest, group, writer, puzzleDate); + if (!image.isEmpty()) { + String imagePath = imageService.uploadImage("puzzle", image); + newPuzzle.addPuzzleImage(imagePath); + } addPuzzleMember(createPuzzleRequest, newPuzzle); return new BaseResponse<>(new CreatePuzzleResponse(newPuzzle.getPuzzleIdx())); @@ -176,13 +178,12 @@ private static LocalDate convertToLocalDate(String date) { } // puzzle entity 생성 - private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group, User writer, String imagePath, LocalDate puzzleDate) throws JsonProcessingException { + private Puzzle createPuzzle(CreatePuzzleRequest createPuzzleRequest, Team group, User writer, LocalDate puzzleDate) throws JsonProcessingException { Puzzle puzzle = Puzzle.builder() .user(writer) .team(group) .title(createPuzzleRequest.title()) .content(createPuzzleRequest.content()) - .puzzleImage(imagePath) .puzzleDate(puzzleDate) .location(convertAddressToCoordinates(createPuzzleRequest.location())).build(); puzzleRepository.save(puzzle); diff --git a/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java b/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java index 34d483e..6d1dda8 100644 --- a/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java +++ b/src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java @@ -39,7 +39,7 @@ public class Puzzle extends BaseEntity { @Column(nullable = false) private String content; - @Column(nullable = false) + @Column(nullable = true) private String puzzleImage; @Column(nullable = false) @@ -55,12 +55,11 @@ public class Puzzle extends BaseEntity { private List puzzleMembers = new ArrayList<>(); // 해당 퍼즐에 참여한 멤버 목록 @Builder - public Puzzle(User user, Team team, String title, String content, String puzzleImage, LocalDate puzzleDate, PuzzleLocation location) { + public Puzzle(User user, Team team, String title, String content, LocalDate puzzleDate, PuzzleLocation location) { this.user = user; this.team = team; this.title = title; this.content = content; - this.puzzleImage = puzzleImage; this.puzzleDate = puzzleDate; this.location = location; } @@ -73,4 +72,5 @@ public void setUser(User user) { public void delete() { this.setStatus(INACTIVE); } + public void addPuzzleImage(String puzzleImage) { this.puzzleImage = puzzleImage; } } diff --git a/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java b/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java index 620ec52..5183646 100644 --- a/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java +++ b/src/main/java/com/lesso/neverland/puzzle/presentation/PuzzleController.java @@ -35,7 +35,7 @@ public BaseResponse getPuzzleDetail(@PathVariable("groupId // 퍼즐 생성 @PostMapping("") - public BaseResponse createPuzzle(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) { + public BaseResponse createPuzzle(@PathVariable Long groupIdx, @RequestPart(required = false) MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) { try { return puzzleService.createPuzzle(groupIdx, image, createPuzzleRequest); } catch (IOException e) {