Skip to content

Commit

Permalink
Merge pull request #26 from dnd-side-project/fix/#25-request-review
Browse files Browse the repository at this point in the history
[Fix] 리뷰 요청하기
  • Loading branch information
heejjinkim authored Nov 17, 2024
2 parents 3c06dc0 + c4f3662 commit 540bdcd
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 84 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ out/
### VS Code ###
.vscode/

db/mysql/data/*
db/mysql/data/*
/src/main/generated/
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com._119.wepro.project.domain.repository;

import static com._119.wepro.project.domain.QProjectMember.projectMember;

import com._119.wepro.member.domain.Member;
import com._119.wepro.project.domain.Project;
import com._119.wepro.alarm.domain.QAlarm;
import com._119.wepro.global.enums.AlarmType;
import com._119.wepro.member.domain.QMember;
import com._119.wepro.project.domain.ProjectMember;
import com._119.wepro.project.domain.QProjectMember;
import com.querydsl.jpa.JPAExpressions;
import com._119.wepro.project.dto.response.MemberRequestStatusResponse;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,6 +19,8 @@ public class ProjectMemberCustomRepository {
private final JPAQueryFactory queryFactory;

public Boolean existsByProjectAndMember(Project project, Member member) {
QProjectMember projectMember = QProjectMember.projectMember;

Integer fetchOne = queryFactory
.selectOne()
.from(projectMember)
Expand All @@ -30,22 +29,28 @@ public Boolean existsByProjectAndMember(Project project, Member member) {
return fetchOne != null;
}

public List<ProjectMember> getProjectMembersWithoutReviewRequest(Long reviewFormId) {
public List<MemberRequestStatusResponse> getProjectMembersWithReviewRequestStatus(Long reviewFormId) {
QProjectMember projectMember = QProjectMember.projectMember;
QAlarm alarm = QAlarm.alarm;
QMember member = QMember.member; // Member 엔티티를 가져오기 위해 추가
QMember member = QMember.member;

List<Long> requestedMemberIds = queryFactory
.select(alarm.receiver.id)
.from(alarm)
.where(alarm.targetId.eq(reviewFormId)
.and(alarm.alarmType.eq(AlarmType.REVIEW_REQUEST)))
.fetch();

return queryFactory
.selectFrom(projectMember)
.join(projectMember.member, member).fetchJoin()
.where(projectMember.id.notIn(
JPAExpressions
.select(alarm.receiver.id)
.from(alarm)
.where(alarm.targetId.eq(reviewFormId)
.and(alarm.alarmType.eq(AlarmType.REVIEW_REQUEST)))
.fetch()
.stream()
.map(pm -> MemberRequestStatusResponse.of(
pm.getMember(),
requestedMemberIds.contains(pm.getMember().getId())
))
.fetch();
.toList();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com._119.wepro.project.dto.response;

import com._119.wepro.member.domain.Member;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class MemberRequestStatusResponse {

private Long id;
private String profileUrl;
private String name;
private String tag;
private boolean isAlreadyRequest;

public static MemberRequestStatusResponse of(Member member, boolean isAlreadyRequest) {
return MemberRequestStatusResponse.builder()
.id(member.getId())
.profileUrl(member.getProfile().getProfileImageUrl())
.name(member.getProfile().getName())
.tag(member.getTag())
.isAlreadyRequest(isAlreadyRequest)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import com._119.wepro.project.dto.response.MyProjectResponse;
import com._119.wepro.project.dto.response.ProjectDetailResponse;
import com._119.wepro.project.dto.response.ProjectListResponse;
import com._119.wepro.project.dto.response.MemberRequestStatusResponse;
import com._119.wepro.project.service.ProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -201,4 +203,37 @@ public ResponseEntity<Void> addMember(
projectService.addProjectMember(projectMemberCreateRequest.getMemberId(), id);
return ResponseEntity.ok(null);
}

@GetMapping("/members/request/review/{reviewFormId}")
@Operation(summary = "리뷰 요청할 때 프로젝트 멤버 조회", description = "리뷰 요청 가능 여부를 포함하여 프로젝트 멤버 정보를 조회합니다.")
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(
mediaType = "application/json",
examples = @ExampleObject(
value = "[\n" +
" {\n" +
" \"id\": 1,\n" +
" \"profileUrl\": \"https://img1.kakaocdn.net/thumb/R110x110.q70/?fname=https://t1.kakaocdn.net/account_images/default_profile.jpeg\",\n" +
" \"name\": \"김희진\",\n" +
" \"tag\": \"1\",\n" +
" \"alreadyRequest\": true\n" +
" },\n" +
" {\n" +
" \"id\": 2,\n" +
" \"profileUrl\": null,\n" +
" \"name\": \"테스트1\",\n" +
" \"tag\": \"2\",\n" +
" \"alreadyRequest\": false\n" +
" }\n" +
"]"
)
)
)
public ResponseEntity<List<MemberRequestStatusResponse>> getProjectMembersWithRequestStatus(
@PathVariable("reviewFormId") Long reviewFormId) {
securityUtil.getCurrentMemberId();
return ResponseEntity.ok(projectService.getProjectMembersWithRequestStatus(reviewFormId));
}
}
17 changes: 14 additions & 3 deletions src/main/java/com/_119/wepro/project/service/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import com._119.wepro.project.domain.repository.ProjectRepository;
import com._119.wepro.project.dto.request.ProjectRequest.ProjectCreateRequest;
import com._119.wepro.project.dto.request.ProjectRequest.ProjectUpdateRequest;
import com._119.wepro.project.dto.response.MemberRequestStatusResponse;
import com._119.wepro.project.dto.response.MyProjectResponse;
import com._119.wepro.project.dto.response.ProjectDetailResponse;
import com._119.wepro.project.dto.response.ProjectListResponse;
import com._119.wepro.review.domain.repository.ReviewFormRepository;
import jakarta.transaction.Transactional;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -35,6 +37,7 @@ public class ProjectService {
private final ProjectMemberCustomRepository projectMemberCustomRepository;
private final MemberRepository memberRepository;
private final ProjectCustomRepository projectCustomRepository;
private final ReviewFormRepository reviewFormRepository;

public List<ProjectListResponse> searchProjects(String keyword) {
List<Project> result = projectCustomRepository.searchProjects(keyword);
Expand Down Expand Up @@ -78,7 +81,8 @@ public Long createProject(ProjectCreateRequest projectCreateRequest, Long projec
@Transactional
public Long updateProject(Long projectId, ProjectUpdateRequest projectUpdateRequest) {
Project project = projectRepository.findById(projectId)
.orElseThrow(() -> new IllegalArgumentException("Project not found with id: " + projectId));
.orElseThrow(
() -> new IllegalArgumentException("Project not found with id: " + projectId));

Project updatedProject = Project.of(projectUpdateRequest);

Expand Down Expand Up @@ -118,8 +122,9 @@ private void registerProjectMember(Project project, Long memberId, String role)


public Long deleteProject(Long projectId) {
Project project = projectRepository.findById(projectId).orElseThrow(() -> new RestApiException(
RESOURCE_NOT_FOUND));
Project project = projectRepository.findById(projectId)
.orElseThrow(() -> new RestApiException(
RESOURCE_NOT_FOUND));
projectRepository.delete(project);

return project.getId();
Expand Down Expand Up @@ -151,4 +156,10 @@ public void addProjectMember(Long projectId, Long userId) {
project.setMemberNum(project.getMemberNum() + 1);
projectRepository.save(project);
}

public List<MemberRequestStatusResponse> getProjectMembersWithRequestStatus(Long reviewFormId) {

reviewFormRepository.findByIdOrThrow(reviewFormId);
return projectMemberCustomRepository.getProjectMembersWithReviewRequestStatus(reviewFormId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class ReviewAskRequest {
private Long reviewFormId;

@NotNull
private List<Long> memberIdList;
private Long reviewerId;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,4 @@ public static ReviewFormCreateResponse of(ReviewForm reviewForm) {
.build();
}
}

@Getter
@Builder
public static class ProjectMemberGetResponse {

private List<MemberDto> memberList;

public static ProjectMemberGetResponse of(List<ProjectMember> projectMembers) {
return ProjectMemberGetResponse.builder()
.memberList(projectMembers.stream()
.map(MemberDto::of)
.toList())
.build();
}

@Getter
@Builder
public static class MemberDto {

private Long id;
private String profileUrl;
private String name;
private String tag;

public static MemberDto of(ProjectMember projectMember) {
return MemberDto.builder()
.id(projectMember.getId())
.profileUrl(projectMember.getMember().getProfile().getProfileImageUrl())
.name(projectMember.getMember().getProfile().getName())
.tag(projectMember.getMember().getTag())
.build();
}
}
}
}
Loading

0 comments on commit 540bdcd

Please sign in to comment.