diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/controller/ProjectController.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/controller/ProjectController.java index 948093d..0644fd5 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/controller/ProjectController.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/controller/ProjectController.java @@ -1,5 +1,6 @@ package com.puzzling.puzzlingServer.api.project.controller; + import com.puzzling.puzzlingServer.api.project.dto.request.*; import com.puzzling.puzzlingServer.api.project.dto.response.*; import com.puzzling.puzzlingServer.api.project.service.ProjectService; @@ -37,11 +38,17 @@ public ApiResponse getMyPuzzles(@PathVariable Long public ApiResponse getTeamPuzzles(Principal principal, @PathVariable Long projectId, @RequestParam String today) { return ApiResponse.success(SuccessStatus.GET_PROJECT_TEAM_PUZZLE_SUCCESS, projectService.getTeamPuzzles(principal, projectId, today)); } + @PostMapping("member/{memberId}/project") public ApiResponse createProject(@PathVariable("memberId") Long memberId, @Valid @RequestBody ProjectRegisterRequestDto projectRegisterRequestDto) { - projectService.createProject(memberId, projectRegisterRequestDto); - return ApiResponse.success(SuccessStatus.POST_PROJECT_SUCCESS.getStatusCode(), SuccessStatus.POST_PROJECT_SUCCESS.getMessage()); + projectService.createProject(memberId, projectRegisterRequestDto); + return ApiResponse.success(SuccessStatus.POST_PROJECT_SUCCESS.getStatusCode(), SuccessStatus.POST_PROJECT_SUCCESS.getMessage()); + } + + @GetMapping("project/{projectId}/rank") + public ApiResponse getTeamRank(@PathVariable Long projectId) { + return ApiResponse.success(SuccessStatus.GET_PROJECT_TEAM_RANK_SUCCESS, projectService.getTeamRank(projectId)); } @PostMapping("member/{memberId}/project/join") diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/domain/UserProject.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/domain/UserProject.java index 0908c2e..f0969f0 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/domain/UserProject.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/domain/UserProject.java @@ -3,9 +3,11 @@ import com.puzzling.puzzlingServer.api.member.domain.Member; import com.puzzling.puzzlingServer.api.template.domain.ReviewTemplate; import com.puzzling.puzzlingServer.common.entity.BaseTimeEntity; +import io.micrometer.core.annotation.Counted; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; import javax.persistence.*; @@ -26,6 +28,9 @@ public class UserProject extends BaseTimeEntity { @Column(nullable = false, length = 10) private String nickname; + @Column(name = "review_count", columnDefinition = "integer default 0") + private int reviewCount; + @Column(name = "leader_or_not", nullable = false) private Boolean leaderOrNot; @@ -54,4 +59,6 @@ public UserProject(String role, String nickname, Boolean leaderOrNot, Long revie public void updatePreviousTemplateId(Long reviewTemplateId) { this.reviewTemplateId = reviewTemplateId; } + + public void addReviewCount() { this.reviewCount++; } } diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/dto/response/ProjectTeamRankResponseDto.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/dto/response/ProjectTeamRankResponseDto.java new file mode 100644 index 0000000..8392bd4 --- /dev/null +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/dto/response/ProjectTeamRankResponseDto.java @@ -0,0 +1,23 @@ +package com.puzzling.puzzlingServer.api.project.dto.response; + +import com.puzzling.puzzlingServer.api.project.domain.UserProject; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import static lombok.AccessLevel.PRIVATE; + +@Getter +@NoArgsConstructor(access = PRIVATE) +@AllArgsConstructor +public class ProjectTeamRankResponseDto { + private int memberRank; + private String memberNickname; + private String memberRole; + private int memberPuzzleCount; + + public static ProjectTeamRankResponseDto of (int memberRank, UserProject userProject) { + return new ProjectTeamRankResponseDto(memberRank, userProject.getNickname(), userProject.getRole(), userProject.getReviewCount()); + } + +} diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/repository/UserProjectRepository.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/repository/UserProjectRepository.java index 7c69ab9..e294b62 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/repository/UserProjectRepository.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/repository/UserProjectRepository.java @@ -16,6 +16,7 @@ public interface UserProjectRepository extends JpaRepository Optional findByMemberIdAndProjectId(Long memberId, Long projectId); - Boolean existsByMemberIdAndProjectId(Long memberId, Long projectId); + List findAllByProjectIdOrderByReviewCountDesc(Long projectId); + Boolean existsByMemberIdAndProjectId(Long memberId, Long projectId); } diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/Impl/ProjectServiceImpl.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/Impl/ProjectServiceImpl.java index 3e766ab..50ec38f 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/Impl/ProjectServiceImpl.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/Impl/ProjectServiceImpl.java @@ -124,7 +124,7 @@ public ProjectTeamPuzzleResponseDto getTeamPuzzles(Principal principal, Long pro for (Map.Entry entry : sortedReviewCountMap.entrySet()) { String reviewMemberPercent = getReviewMemberPercent(projectId, entry.getValue()); teamPuzzleBoard.add(TeamPuzzleObjectDto.of(entry.getKey(), - reviewMemberPercent, "puzzle"+reviewMemberPercent+idx++)); + reviewMemberPercent, "puzzle" + reviewMemberPercent + idx++)); } if (isReviewDay) { @@ -138,7 +138,7 @@ public ProjectTeamPuzzleResponseDto getTeamPuzzles(Principal principal, Long pro @Override @Transactional - public ProjectRegisterResponseDto createProject(Long memberId, ProjectRegisterRequestDto projectRegisterRequestDto){ + public ProjectRegisterResponseDto createProject(Long memberId, ProjectRegisterRequestDto projectRegisterRequestDto) { String inviteCode = makeShortUUID(); String cycle = convertReviewCycleToString(projectRegisterRequestDto.getReviewCycle()); @@ -165,6 +165,15 @@ public ProjectRegisterResponseDto createProject(Long memberId, ProjectRegisterRe userProjectRepository.save(userProject); return new ProjectRegisterResponseDto(cycle); } + public List getTeamRank(Long projectId) { + List findUserProjects = userProjectRepository.findAllByProjectIdOrderByReviewCountDesc(projectId); + List result = new ArrayList<>(); + int idx = 1; + for (UserProject userProject : findUserProjects) { + result.add(ProjectTeamRankResponseDto.of(idx++, userProject)); + } + return result; + } @Override @Transactional diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/ProjectService.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/ProjectService.java index 5c2aaa4..cc2149a 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/ProjectService.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/project/service/ProjectService.java @@ -24,9 +24,13 @@ public interface ProjectService { //* 프로젝트 생성 ProjectRegisterResponseDto createProject(Long memberId, ProjectRegisterRequestDto projectRegisterRequestDto); + //* 팀원 회고 랭킹 조회 + List getTeamRank(Long projectId); + //* 프로젝트 참여 ProjectJoinResponseDto joinProject(Long memberId, ProjectJoinRequestDto projectJoinRequestDto); //* 프로젝트 주기 조회 ProjectCycleResponseDto getProjectCycle(Long projectId); + } diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/review/service/Impl/ReviewServiceImpl.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/review/service/Impl/ReviewServiceImpl.java index 4e37590..9e0b8db 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/review/service/Impl/ReviewServiceImpl.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/api/review/service/Impl/ReviewServiceImpl.java @@ -70,6 +70,7 @@ public void createReviewTIL(Long memberId, Long projectId, ReviewTILRequestDto r ReviewTemplate reviewTemplate = findReviewTemplateById(reviewTILRequestDto.getReviewTemplateId()); userProject.updatePreviousTemplateId(reviewTILRequestDto.getReviewTemplateId()); + userProject.addReviewCount(); Review review = Review.builder() .userProject(userProject) @@ -100,6 +101,7 @@ public void createReview5F(Long memberId, Long projectId, Review5FRequestDto rev ReviewTemplate reviewTemplate = findReviewTemplateById(review5FRequestDto.getReviewTemplateId()); userProject.updatePreviousTemplateId(review5FRequestDto.getReviewTemplateId()); + userProject.addReviewCount(); Review review = Review.builder() .userProject(userProject) @@ -132,6 +134,7 @@ public void createReviewAAR(Long memberId, Long projectId, ReviewAARRequestDto r ReviewTemplate reviewTemplate = findReviewTemplateById(reviewAARRequestDto.getReviewTemplateId()); userProject.updatePreviousTemplateId(reviewAARRequestDto.getReviewTemplateId()); + userProject.addReviewCount(); Review review = Review.builder() .userProject(userProject) diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/response/SuccessStatus.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/response/SuccessStatus.java index db9cd23..50fbcce 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/response/SuccessStatus.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/response/SuccessStatus.java @@ -23,8 +23,9 @@ public enum SuccessStatus { GET_PROJECT_ALL_SUCCESS(HttpStatus.OK, "진행 중인 프로젝트 리스트 조회 성공"), GET_PROJECT_MY_PUZZLE_SUCCESS(HttpStatus.OK, "개인 대시보드 퍼즐 조회 성공"), GET_PROJECT_TEAM_PUZZLE_SUCCESS(HttpStatus.OK, "팀 대시보드 퍼즐 조회 성공"), - POST_PROJECT_SUCCESS(HttpStatus.OK, "프로젝트 등록 성공"), - JOIN_PROJECT_SUCCESS(HttpStatus.OK, "프로젝트 참여 성공"), + POST_PROJECT_SUCCESS(HttpStatus.CREATED, "프로젝트 등록 성공"), + GET_PROJECT_TEAM_RANK_SUCCESS(HttpStatus.OK, "팀원 회고 랭킹 조회 성공"), + JOIN_PROJECT_SUCCESS(HttpStatus.CREATED, "프로젝트 참여 성공"), GET_PROJECT_CYCLE_SUCCESS(HttpStatus.OK,"프로젝트 회고 주기 조회 성공"), /** @@ -35,6 +36,7 @@ public enum SuccessStatus { GET_REVIEW_PREVIOUS_TEMPLATE(HttpStatus.OK, "이전 회고 템플릿 조회 성공"), GET_REVIEW_ACTION_PLAN(HttpStatus.OK, "ACTIONPLAN 내용 조회 성공") ; + private final HttpStatus httpStatus; private final String message; diff --git a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/util/MemberUtil.java b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/util/MemberUtil.java index c0cf42f..ca9a06c 100644 --- a/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/util/MemberUtil.java +++ b/puzzlingServer/src/main/java/com/puzzling/puzzlingServer/common/util/MemberUtil.java @@ -1,7 +1,6 @@ package com.puzzling.puzzlingServer.common.util; import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Configuration; import java.security.Principal; import java.util.Objects;