Skip to content

Commit

Permalink
Merge pull request #187 from lemonssoju/develop-v2
Browse files Browse the repository at this point in the history
[develop-v2] main merge
  • Loading branch information
JoongHyun-Kim authored Jun 5, 2024
2 parents d758286 + 633225f commit a6f1bba
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ public BaseResponse<GroupListResponse> 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));
}

// GroupListDto 정렬을 위한 최근 업로드 일자 계산
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ public BaseResponse<CreatePuzzleResponse> 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()));
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/lesso/neverland/puzzle/domain/Puzzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -55,12 +55,11 @@ public class Puzzle extends BaseEntity {
private List<PuzzleMember> 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;
}
Expand All @@ -73,4 +72,5 @@ public void setUser(User user) {
public void delete() {
this.setStatus(INACTIVE);
}
public void addPuzzleImage(String puzzleImage) { this.puzzleImage = puzzleImage; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public BaseResponse<PuzzleDetailResponse> getPuzzleDetail(@PathVariable("groupId

// 퍼즐 생성
@PostMapping("")
public BaseResponse<CreatePuzzleResponse> createPuzzle(@PathVariable Long groupIdx, @RequestPart MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) {
public BaseResponse<CreatePuzzleResponse> createPuzzle(@PathVariable Long groupIdx, @RequestPart(required = false) MultipartFile image, @RequestPart CreatePuzzleRequest createPuzzleRequest) {
try {
return puzzleService.createPuzzle(groupIdx, image, createPuzzleRequest);
} catch (IOException e) {
Expand Down

0 comments on commit a6f1bba

Please sign in to comment.