Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#29 [FEAT] 팀원 회고 랭킹 조회 API 개발 #36

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,10 +38,16 @@ public ApiResponse<ProjectOwnPuzzleResponseDto> getMyPuzzles(@PathVariable Long
public ApiResponse<ProjectTeamPuzzleResponseDto> 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<ProjectRegisterResponseDto> 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<ProjectTeamRankResponseDto> getTeamRank(@PathVariable Long projectId) {
return ApiResponse.success(SuccessStatus.GET_PROJECT_TEAM_RANK_SUCCESS, projectService.getTeamRank(projectId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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;

Expand Down Expand Up @@ -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++; }
}
Original file line number Diff line number Diff line change
@@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface UserProjectRepository extends JpaRepository<UserProject, Long>

Optional<UserProject> findByMemberIdAndProjectId(Long memberId, Long projectId);

List<UserProject> findAllByProjectIdOrderByReviewCountDesc(Long projectId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public ProjectTeamPuzzleResponseDto getTeamPuzzles(Principal principal, Long pro
for (Map.Entry<String, Integer> 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) {
Expand All @@ -137,7 +137,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());

Expand All @@ -164,6 +164,15 @@ public ProjectRegisterResponseDto createProject(Long memberId, ProjectRegisterRe
userProjectRepository.save(userProject);
return new ProjectRegisterResponseDto(cycle);
}
public List<ProjectTeamRankResponseDto> getTeamRank(Long projectId) {
List<UserProject> findUserProjects = userProjectRepository.findAllByProjectIdOrderByReviewCountDesc(projectId);
List<ProjectTeamRankResponseDto> result = new ArrayList<>();
int idx = 1;
for (UserProject userProject : findUserProjects) {
result.add(ProjectTeamRankResponseDto.of(idx++, userProject));
}
return result;
}

private String getReviewMemberPercent(Long projectId, int reviewCount) {
int totalProjectMember = userProjectRepository.findAllByProjectId(projectId).size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.puzzling.puzzlingServer.api.project.service;


import com.puzzling.puzzlingServer.api.project.dto.request.ProjectRegisterRequestDto;
import com.puzzling.puzzlingServer.api.project.dto.response.*;

Expand All @@ -22,4 +23,8 @@ public interface ProjectService {

//* 프로젝트 생성
ProjectRegisterResponseDto createProject(Long memberId, ProjectRegisterRequestDto projectRegisterRequestDto);

//* 팀원 회고 랭킹 조회
List<ProjectTeamRankResponseDto> getTeamRank(Long projectId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum SuccessStatus {
GET_PROJECT_MY_PUZZLE_SUCCESS(HttpStatus.OK, "개인 대시보드 퍼즐 조회 성공"),
GET_PROJECT_TEAM_PUZZLE_SUCCESS(HttpStatus.OK, "팀 대시보드 퍼즐 조회 성공"),
POST_PROJECT_SUCCESS(HttpStatus.OK, "프로젝트 등록 성공"),
GET_PROJECT_TEAM_RANK_SUCCESS(HttpStatus.OK, "팀원 회고 랭킹 조회 성공"),

/**
* review
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading