Skip to content

Commit

Permalink
Merge pull request #119 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 May 16, 2024
2 parents 45c86dd + 74325e9 commit 4b50863
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

import java.io.IOException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -47,13 +49,24 @@ public BaseResponse<GroupListResponse> getGroupList() {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
List<Team> groupList = groupRepository.findByAdminAndStatusEquals(user, ACTIVE);
List<GroupListDto> groupListDto = groupList.stream()
.map(group -> new GroupListDto(
group.getTeamIdx(),
group.getTeamImage(),
group.getName())).collect(Collectors.toList());
.map(group -> {
String startYear = group.getStartDate().format(DateTimeFormatter.ofPattern("yyyy"));
return new GroupListDto(group.getTeamIdx(), group.getTeamImage(), startYear, group.getName(),
group.getUserTeams().size(), group.getAdmin().getProfile().getNickname(), calculateRecentUpdate(group));
}).collect(Collectors.toList());
return new BaseResponse<>(new GroupListResponse(groupListDto));
}

private String calculateRecentUpdate(Team group) {
Puzzle recentPuzzle = puzzleRepository.findTopByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE);

LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul"));
LocalDate puzzleCreatedDate = recentPuzzle.getCreatedDate();
long daysBetween = ChronoUnit.DAYS.between(puzzleCreatedDate, today);

return daysBetween + "일 전";
}

// 그룹 퍼즐 목록 조회
public BaseResponse<GroupPuzzleListResponse> getGroupPuzzleList(Long groupIdx) {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/lesso/neverland/group/domain/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;

import java.time.LocalDate;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -37,7 +37,7 @@ public class Team extends BaseEntity {
private String teamImage;

@Column(nullable = false)
private LocalDate startDate;
private YearMonth startDate;

@OneToMany(mappedBy = "team")
private List<UserTeam> userTeams = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

public record GroupListDto(Long groupIdx,
String groupImage,
String name) {}
String startYear,
String name,
Integer memberCount,
String admin,
String recentUpdate) {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public interface PuzzleRepository extends JpaRepository<Puzzle, Long> {
List<Puzzle> findByTeamAndStatusEqualsOrderByCreatedDateDesc(Team group, String status);
Puzzle findTopByTeamAndStatusEqualsOrderByCreatedDateDesc(Team group, String status);
List<Puzzle> findByTeamAndStatusEquals(Team group, String status);
List<Puzzle> findByUserAndStatusEquals(User user, String status);
@Query("SELECT p FROM Puzzle p WHERE p.title LIKE CONCAT('%', :keyword, '%') OR p.content LIKE CONCAT('%', :keyword, '%')")
Expand Down

0 comments on commit 4b50863

Please sign in to comment.