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

[Feature] 기본 정보 조회 API 반환 추가 및 프로필 조회 API 구현 #140

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -3,10 +3,7 @@
import com.pawwithu.connectdog.domain.volunteer.dto.request.AdditionalAuthRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.NicknameRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.VolunteerMyProfileRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.response.NicknameResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyBadgeResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyBookmarkResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyInfoResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.*;
import com.pawwithu.connectdog.domain.volunteer.service.VolunteerService;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -55,8 +52,8 @@ public ResponseEntity<Void> additionalAuth(@AuthenticationPrincipal UserDetails
return ResponseEntity.noContent().build();
}

@Operation(summary = "마이페이지 통계 정보 조회 API", description = "마이페이지 통계 정보를 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "마이페이지 통계 정보 조회 성공")
@Operation(summary = "마이페이지 기본 정보 조회 API", description = "마이페이지 기본 정보를 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "마이페이지 기본 정보 조회 성공")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

워딩 통일 좋습니다~!

, @ApiResponse(responseCode = "400"
, description = "M1, 해당 이동봉사자를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
Expand Down Expand Up @@ -104,4 +101,16 @@ public ResponseEntity<Void> volunteerMyProfile(@AuthenticationPrincipal UserDeta
return ResponseEntity.noContent().build();
}

@Operation(summary = "프로필 이미지, 닉네임 조회 API", description = "프로필 이미지, 닉네임을 조회합니다.",
responses = {@ApiResponse(responseCode = "200", description = "프로필 이미지, 닉네임 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M1, 해당 이동봉사자를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/my/profile")
public ResponseEntity<VolunteerGetProfileResponse> getMyProfile(@AuthenticationPrincipal UserDetails loginUser) {
VolunteerGetProfileResponse response = volunteerService.getMyProfile(loginUser.getUsername());
return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pawwithu.connectdog.domain.volunteer.dto.response;

public record VolunteerGetMyInfoResponse(Long completedCount, Long reviewCount, Long dogStatusCount) {
public static VolunteerGetMyInfoResponse of(Long completedCount, Long reviewCount, Long dogStatusCount) {
return new VolunteerGetMyInfoResponse(completedCount, reviewCount, dogStatusCount);
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pawwithu.connectdog.domain.volunteer.dto.response;

public record VolunteerGetProfileResponse(Integer profileImageNum, String nickname) {
public static VolunteerGetProfileResponse of(Integer profileImageNum, String nickname) {
return new VolunteerGetProfileResponse(profileImageNum, nickname);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import com.pawwithu.connectdog.domain.volunteer.dto.request.AdditionalAuthRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.NicknameRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.VolunteerMyProfileRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.response.NicknameResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyBadgeResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyBookmarkResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyInfoResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.*;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository;
import com.pawwithu.connectdog.error.ErrorCode;
Expand Down Expand Up @@ -64,7 +61,7 @@ public VolunteerGetMyInfoResponse getMyInfo(String email) {
// 입양 근황 건수
Long dogStatusCount = customDogStatusRepository.getVolunteerCountOfDogStatuses(volunteer.getId());

VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(completedCount, reviewCount, dogStatusCount);
VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(volunteer.getProfileImageNum(), volunteer.getNickname(), completedCount, reviewCount, dogStatusCount);
return response;
}

Expand Down Expand Up @@ -100,4 +97,11 @@ public void volunteerMyProfile(String email, VolunteerMyProfileRequest volunteer
volunteer.updateMyProfile(nickname, profileImageNum);
}
}

@Transactional(readOnly = true)
public VolunteerGetProfileResponse getMyProfile(String email) {
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
VolunteerGetProfileResponse profile = VolunteerGetProfileResponse.of(volunteer.getProfileImageNum(), volunteer.getNickname());
return profile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import com.pawwithu.connectdog.domain.volunteer.dto.request.AdditionalAuthRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.NicknameRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.VolunteerMyProfileRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.response.NicknameResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyBadgeResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyBookmarkResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerGetMyInfoResponse;
import com.pawwithu.connectdog.domain.volunteer.dto.response.*;
import com.pawwithu.connectdog.domain.volunteer.service.VolunteerService;
import com.pawwithu.connectdog.utils.TestUserArgumentResolver;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -91,9 +88,9 @@ void setUp() {
}

@Test
void 이동봉사자_마이페이지_통계_정보_조회() throws Exception {
void 이동봉사자_마이페이지_기본_정보_조회() throws Exception {
// given
VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(1L, 3L, 5L);
VolunteerGetMyInfoResponse response = VolunteerGetMyInfoResponse.of(1, "하노정", 1L, 3L, 5L);

// when
given(volunteerService.getMyInfo(any())).willReturn(response);
Expand Down Expand Up @@ -164,4 +161,20 @@ void setUp() {
verify(volunteerService, times(1)).volunteerMyProfile(anyString(), any());

}

@Test
void 이동봉사자_프로필_이미지_닉네임_조회() throws Exception {
// given
VolunteerGetProfileResponse response = VolunteerGetProfileResponse.of(1, "하노정");

// when
given(volunteerService.getMyProfile(anyString())).willReturn(response);
ResultActions result = mockMvc.perform(
get("/volunteers/my/profile")
);

// then
result.andExpect(status().isOk());
verify(volunteerService, times(1)).getMyProfile(anyString());
}
}
Loading