Skip to content

Commit 74325e9

Browse files
Merge pull request #118 from lemonssoju/feature/103-getGroupList
[feature/103-getGroupList] 그룹 목록 조회 API 구현
2 parents d58d00b + 6c80a35 commit 74325e9

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/main/java/com/lesso/neverland/group/application/GroupService.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import java.io.IOException;
2424
import java.time.LocalDate;
25+
import java.time.ZoneId;
2526
import java.time.format.DateTimeFormatter;
27+
import java.time.temporal.ChronoUnit;
2628
import java.util.*;
2729
import java.util.stream.Collectors;
2830

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

60+
private String calculateRecentUpdate(Team group) {
61+
Puzzle recentPuzzle = puzzleRepository.findTopByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE);
62+
63+
LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul"));
64+
LocalDate puzzleCreatedDate = recentPuzzle.getCreatedDate();
65+
long daysBetween = ChronoUnit.DAYS.between(puzzleCreatedDate, today);
66+
67+
return daysBetween + "일 전";
68+
}
69+
5770
// 그룹 퍼즐 목록 조회
5871
public BaseResponse<GroupPuzzleListResponse> getGroupPuzzleList(Long groupIdx) {
5972
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));

src/main/java/com/lesso/neverland/group/domain/Team.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import lombok.NoArgsConstructor;
1111
import org.hibernate.annotations.DynamicInsert;
1212

13-
import java.time.LocalDate;
13+
import java.time.YearMonth;
1414
import java.util.ArrayList;
1515
import java.util.List;
1616

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

3939
@Column(nullable = false)
40-
private LocalDate startDate;
40+
private YearMonth startDate;
4141

4242
@OneToMany(mappedBy = "team")
4343
private List<UserTeam> userTeams = new ArrayList<>();

src/main/java/com/lesso/neverland/group/dto/GroupListDto.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
public record GroupListDto(Long groupIdx,
44
String groupImage,
5-
String name) {}
5+
String startYear,
6+
String name,
7+
Integer memberCount,
8+
String admin,
9+
String recentUpdate) {}

src/main/java/com/lesso/neverland/puzzle/repository/PuzzleRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

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

0 commit comments

Comments
 (0)