Skip to content

Commit

Permalink
Merge pull request #184 from PawWithU/feat/181-mypage-main-api
Browse files Browse the repository at this point in the history
[Feature] 이동봉사자 마이페이지 메인 정보 조회 API 수정
  • Loading branch information
hojeong2747 authored May 5, 2024
2 parents 1120585 + c10354a commit 40f9aa8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,8 +19,6 @@ public interface CustomApplicationRepository {
List<ApplicationIntermediaryProgressingResponse> getIntermediaryProgressingApplications(Long intermediaryId, Pageable pageable);
List<ApplicationVolunteerCompletedResponse> getVolunteerCompletedApplications(Long volunteerId, Pageable pageable);
List<ApplicationIntermediaryCompletedResponse> getIntermediaryCompletedApplications(Long intermediaryId, Pageable pageable);

// 진행한 이동봉사 건수
Long getCountOfCompletedApplications(Long id);
List<Tuple> getCountOfApplicationsByStatus(Long id);
boolean existsByPostIdAndPostStatus(Long postId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -170,15 +171,14 @@ public List<ApplicationIntermediaryCompletedResponse> getIntermediaryCompletedAp
.fetch();
}

// 진행한 이동봉사 건수
@Override
public Long getCountOfCompletedApplications(Long id) {
public List<Tuple> 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
Expand All @@ -190,4 +190,5 @@ public boolean existsByPostIdAndPostStatus(Long postId) {
.and(application.status.ne(ApplicationStatus.REJECTED)))
.fetchOne() != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ResponseEntity<Void> 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, 해당 이동봉사자를 찾을 수 없습니다."
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<Tuple> 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;
}

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

0 comments on commit 40f9aa8

Please sign in to comment.