Skip to content

Commit

Permalink
#122 feat: 그룹 프로필 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim committed May 22, 2024
1 parent 23763b6 commit 820d119
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

import static com.lesso.neverland.common.base.BaseResponseStatus.*;
import static com.lesso.neverland.common.constants.Constants.ACTIVE;
Expand All @@ -53,7 +52,7 @@ public BaseResponse<GroupListResponse> getGroupList() {
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());
}).toList();
return new BaseResponse<>(new GroupListResponse(groupListDto));
}

Expand All @@ -67,20 +66,48 @@ private String calculateRecentUpdate(Team group) {
return daysBetween + "일 전";
}

// 그룹 퍼즐 목록 조회
public BaseResponse<GroupPuzzleListResponse> getGroupPuzzleList(Long groupIdx) {
User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
// 그룹 프로필 조회
public BaseResponse<GroupProfileResponse> getGroupProfile(Long groupIdx) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
List<Puzzle> groupPuzzleList = puzzleRepository.findByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE);

List<GroupPuzzleDto> groupPuzzleListDto = groupPuzzleList.stream()
.map(groupPuzzle -> new GroupPuzzleDto(
groupPuzzle.getTitle(),
groupPuzzle.getPuzzleImage(),
groupPuzzle.getUser().getProfile().getNickname())).collect(Collectors.toList());
return new BaseResponse<>(new GroupPuzzleListResponse(group.getName(), groupPuzzleListDto));
List<String> memberImageList = group.getUserTeams().stream()
.map(userTeam -> userTeam.getUser().getProfile().getProfileImage())
.limit(3)
.toList();

Integer puzzleCount = puzzleRepository.countByTeam(group);

LocalDate today = LocalDate.now(ZoneId.of("Asia/Seoul"));
long dayCount = ChronoUnit.DAYS.between(group.getStartDate(), today);

GroupProfileResponse profile = new GroupProfileResponse(group.getName(), group.getStartDate().getYear(), memberImageList,
group.getUserTeams().size(), puzzleCount, dayCount);
return new BaseResponse<>(profile);
}


//TODO: 퍼즐 도메인 하위로 이동
// // 그룹 상세 조회
// public BaseResponse<GroupProfileResponse> getGroupDetail() {
//
// }
//
// // 그룹 퍼즐 목록 조회
// public BaseResponse<GroupPuzzleListResponse> getGroupPuzzleList(Long groupIdx) {
// User user = userRepository.findById(userService.getUserIdxWithValidation()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
// Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
// List<Puzzle> groupPuzzleList = puzzleRepository.findByTeamAndStatusEqualsOrderByCreatedDateDesc(group, ACTIVE);
//
// List<GroupPuzzleDto> groupPuzzleListDto = groupPuzzleList.stream()
// .map(groupPuzzle -> new GroupPuzzleDto(
// groupPuzzle.getTitle(),
// groupPuzzle.getPuzzleImage(),
// groupPuzzle.getUser().getProfile().getNickname(),
// groupPuzzle.getCreatedDate().toString(),
// groupPuzzle.getLocation())).collect(Collectors.toList());
// return new BaseResponse<>(new GroupPuzzleListResponse(group.getName(), groupPuzzleListDto));
// }

// TODO: 퍼즐 도메인 하위로 이동
// 그룹 퍼즐 상세 조회
public BaseResponse<GroupPuzzleResponse> getGroupPuzzle(Long groupIdx, Long puzzleIdx) {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
Expand Down Expand Up @@ -202,6 +229,7 @@ public BaseResponse<String> createGroup(MultipartFile image, CreateGroupRequest
return new BaseResponse<>(SUCCESS);
}

// TODO: 퍼즐 도메인 하위로 이동
// 그룹 피드 등록
public BaseResponse<String> createGroupPuzzle(Long groupIdx, MultipartFile image, GroupPuzzleRequest groupPuzzleRequest) throws IOException {
Team group = groupRepository.findById(groupIdx).orElseThrow(() -> new BaseException(INVALID_GROUP_IDX));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.lesso.neverland.group.dto;

import java.util.List;

public record GroupProfileResponse(String groupName,
Integer startYear,
List<String> memberImageList, // 3개만 조회
Integer memberCount, // 멤버수
Integer puzzleCount,
long dayCount) {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,29 @@ public BaseResponse<GroupListResponse> getGroupList() {
return groupService.getGroupList();
}

// 그룹 피드 목록 조회
@GetMapping("/{groupIdx}/posts")
public BaseResponse<GroupPuzzleListResponse> getGroupPostList(@PathVariable Long groupIdx) {
return groupService.getGroupPuzzleList(groupIdx);
// 그룹 프로필 조회
@GetMapping("/{groupIdx}/profile")
public BaseResponse<GroupProfileResponse> getGroupProfile(@PathVariable Long groupIdx) {
return groupService.getGroupProfile(groupIdx);
}

// 그룹 피드 상세 조회
@GetMapping("/{groupIdx}/posts/{postIdx}")
public BaseResponse<GroupPuzzleResponse> getGroupPostList(@PathVariable Long groupIdx, @PathVariable Long postIdx) {
return groupService.getGroupPuzzle(groupIdx, postIdx);
}
// // 그룹 상세 조회
// @GetMapping("")
// public BaseResponse<GroupProfileResponse> getGroupDetail() {
// return groupService.getGroupDetail();
// }

// // 그룹 피드 목록 조회
// @GetMapping("/{groupIdx}/posts")
// public BaseResponse<GroupPuzzleListResponse> getGroupPostList(@PathVariable Long groupIdx) {
// return groupService.getGroupPuzzleList(groupIdx);
// }

// // 그룹 피드 상세 조회
// @GetMapping("/{groupIdx}/posts/{postIdx}")
// public BaseResponse<GroupPuzzleResponse> getGroupPostList(@PathVariable Long groupIdx, @PathVariable Long postIdx) {
// return groupService.getGroupPuzzle(groupIdx, postIdx);
// }

// [관리자] 그룹 수정 화면 조회
@GetMapping("/{groupIdx}/editView")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface PuzzleRepository extends JpaRepository<Puzzle, Long> {
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, '%')")
List<Puzzle> searchTitleAndContentByKeyword(@Param("keyword") String keyword);

Integer countByTeam(Team team);
}

0 comments on commit 820d119

Please sign in to comment.