From 7f8c9a47ab060df57a0add817fb14cc235c81ce7 Mon Sep 17 00:00:00 2001 From: hojeong2747 Date: Sun, 5 May 2024 23:16:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EC=9D=B4=EB=8F=99=EB=B4=89?= =?UTF-8?q?=EC=82=AC=EC=9E=90=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=A9=94=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EB=B0=98=ED=99=98=EA=B0=92=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomApplicationRepository.java | 5 ++-- .../impl/CustomApplicationRepositoryImpl.java | 13 +++++----- .../controller/VolunteerController.java | 2 +- .../response/VolunteerGetMyInfoResponse.java | 9 ++++--- .../volunteer/service/VolunteerService.java | 26 ++++++++++++++----- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/repository/CustomApplicationRepository.java b/src/main/java/com/pawwithu/connectdog/domain/application/repository/CustomApplicationRepository.java index 2fb9e2c3..1fa2f208 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/repository/CustomApplicationRepository.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/repository/CustomApplicationRepository.java @@ -3,6 +3,7 @@ import com.pawwithu.connectdog.domain.application.dto.response.*; import com.pawwithu.connectdog.domain.application.entity.Application; import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus; +import com.querydsl.core.Tuple; import org.springframework.data.domain.Pageable; import java.util.List; @@ -18,8 +19,6 @@ public interface CustomApplicationRepository { List getIntermediaryProgressingApplications(Long intermediaryId, Pageable pageable); List getVolunteerCompletedApplications(Long volunteerId, Pageable pageable); List getIntermediaryCompletedApplications(Long intermediaryId, Pageable pageable); - - // 진행한 이동봉사 건수 - Long getCountOfCompletedApplications(Long id); + List getCountOfApplicationsByStatus(Long id); boolean existsByPostIdAndPostStatus(Long postId); } diff --git a/src/main/java/com/pawwithu/connectdog/domain/application/repository/impl/CustomApplicationRepositoryImpl.java b/src/main/java/com/pawwithu/connectdog/domain/application/repository/impl/CustomApplicationRepositoryImpl.java index 655dcf18..2de80323 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/application/repository/impl/CustomApplicationRepositoryImpl.java +++ b/src/main/java/com/pawwithu/connectdog/domain/application/repository/impl/CustomApplicationRepositoryImpl.java @@ -4,6 +4,7 @@ import com.pawwithu.connectdog.domain.application.entity.Application; import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus; import com.pawwithu.connectdog.domain.application.repository.CustomApplicationRepository; +import com.querydsl.core.Tuple; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -170,15 +171,14 @@ public List getIntermediaryCompletedAp .fetch(); } - // 진행한 이동봉사 건수 @Override - public Long getCountOfCompletedApplications(Long id) { + public List getCountOfApplicationsByStatus(Long id) { return queryFactory - .select(application.count()) + .select(application.status, application.count()) .from(application) - .where(application.volunteer.id.eq(id) - .and(application.status.eq(ApplicationStatus.COMPLETED))) - .fetchOne(); + .where(application.volunteer.id.eq(id)) + .groupBy(application.status) + .fetch(); } @Override @@ -190,4 +190,5 @@ public boolean existsByPostIdAndPostStatus(Long postId) { .and(application.status.ne(ApplicationStatus.REJECTED))) .fetchOne() != null; } + } diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java index 699bcde7..ecb413fa 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerController.java @@ -53,7 +53,7 @@ public ResponseEntity additionalAuth(@AuthenticationPrincipal UserDetails return ResponseEntity.noContent().build(); } - @Operation(summary = "마이페이지 기본 정보 조회 API", description = "마이페이지 기본 정보를 조회합니다.", + @Operation(summary = "마이페이지 메인 정보 조회 API", description = "마이페이지 메인 화면의 닉네임, 프로필 이미지, 봉사 현황 요약 조회를 조회합니다.", responses = {@ApiResponse(responseCode = "200", description = "마이페이지 기본 정보 조회 성공") , @ApiResponse(responseCode = "400" , description = "M1, 해당 이동봉사자를 찾을 수 없습니다." diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetMyInfoResponse.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetMyInfoResponse.java index 33fa8583..e7c9622e 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetMyInfoResponse.java +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/dto/response/VolunteerGetMyInfoResponse.java @@ -1,7 +1,10 @@ package com.pawwithu.connectdog.domain.volunteer.dto.response; -public record VolunteerGetMyInfoResponse(Integer profileImageNum, String nickname, Long completedCount, Long reviewCount, Long dogStatusCount) { - public static VolunteerGetMyInfoResponse of(Integer profileImageNum, String nickname, Long completedCount, Long reviewCount, Long dogStatusCount) { - return new VolunteerGetMyInfoResponse(profileImageNum, nickname, completedCount, reviewCount, dogStatusCount); +public record VolunteerGetMyInfoResponse(Integer profileImageNum, String nickname, + Long waitingCount, Long progressingCount, Long completedCount, Long reviewCount) { + + public static VolunteerGetMyInfoResponse of(Integer profileImageNum, String nickname, + Long waitingCount, Long progressingCount, Long completedCount, Long reviewCount) { + return new VolunteerGetMyInfoResponse(profileImageNum, nickname, waitingCount, progressingCount, completedCount, reviewCount); } } diff --git a/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java b/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java index ee5ef957..68b923cb 100644 --- a/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java +++ b/src/main/java/com/pawwithu/connectdog/domain/volunteer/service/VolunteerService.java @@ -1,5 +1,6 @@ package com.pawwithu.connectdog.domain.volunteer.service; +import com.pawwithu.connectdog.domain.application.entity.ApplicationStatus; import com.pawwithu.connectdog.domain.application.repository.CustomApplicationRepository; import com.pawwithu.connectdog.domain.badge.repository.CustomVolunteerBadgeRepository; import com.pawwithu.connectdog.domain.bookmark.repository.CustomBookmarkRepository; @@ -13,6 +14,7 @@ import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository; import com.pawwithu.connectdog.error.ErrorCode; import com.pawwithu.connectdog.error.exception.custom.BadRequestException; +import com.querydsl.core.Tuple; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.crypto.password.PasswordEncoder; @@ -21,6 +23,7 @@ import java.util.List; +import static com.pawwithu.connectdog.domain.application.entity.QApplication.application; import static com.pawwithu.connectdog.error.ErrorCode.ALREADY_EXIST_NICKNAME; import static com.pawwithu.connectdog.error.ErrorCode.VOLUNTEER_NOT_FOUND; @@ -54,16 +57,25 @@ public void additionalAuth(String email, AdditionalAuthRequest request) { public VolunteerGetMyInfoResponse getMyInfo(String email) { Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); - // 진행한 이동봉사 건수 - Long completedCount = customApplicationRepository.getCountOfCompletedApplications(volunteer.getId()); - - // 봉사 후기 건수 + Long waitingCount = 0L; + Long progressingCount = 0L; + Long completedCount = 0L; Long reviewCount = customReviewRepository.getVolunteerCountOfReviews(volunteer.getId()); - // 입양 근황 건수 - Long dogStatusCount = customDogStatusRepository.getVolunteerCountOfDogStatuses(volunteer.getId()); + List applicationCounts = customApplicationRepository.getCountOfApplicationsByStatus(volunteer.getId()); + for (Tuple tuple : applicationCounts) { + ApplicationStatus status = tuple.get(application.status); + Long count = tuple.get(application.count()); + + switch (status) { + case WAITING -> waitingCount = count; + case PROGRESSING -> progressingCount = count; + case COMPLETED -> completedCount = count; + } + } - VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(volunteer.getProfileImageNum(), volunteer.getNickname(), completedCount, reviewCount, dogStatusCount); + VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(volunteer.getProfileImageNum(), volunteer.getNickname(), + waitingCount, progressingCount, completedCount, reviewCount); return response; } From 26fea1ac96b38d2eb4a8208807d6a63ef55eeec0 Mon Sep 17 00:00:00 2001 From: hojeong2747 Date: Sun, 5 May 2024 23:16:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=EC=9D=B4=EB=8F=99=EB=B4=89?= =?UTF-8?q?=EC=82=AC=EC=9E=90=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EB=A9=94=EC=9D=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95=20(#181)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/volunteer/controller/VolunteerControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java b/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java index ecc95bfd..c14bef57 100644 --- a/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java +++ b/src/test/java/com/pawwithu/connectdog/domain/volunteer/controller/VolunteerControllerTest.java @@ -92,7 +92,7 @@ void setUp() { @Test void 이동봉사자_마이페이지_기본_정보_조회() throws Exception { // given - VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(1, "하노정", 1L, 3L, 5L); + VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(1, "하노정", 1L, 3L, 5L, 4L); // when given(volunteerService.getMyInfo(any())).willReturn(response);