diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3fa8f862..4adc80ec 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ +#Tue Jul 09 18:32:55 KST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip -networkTimeout=10000 -validateDistributionUrl=true +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index 9dfbe584..d7e13fa2 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -33,14 +33,26 @@ include::{docdir}/member/upload-profile-image.adoc[] == 피플 -=== 피플 정보 등록 -include::{docdir}/people/create-people.adoc[] - === 피플 상세 조회 include::{docdir}/people/get-people.adoc[] === 피플 목록 조회 include::{docdir}/people/get-card-people-page.adoc[] +=== 내 피플 정보 등록 +include::{docdir}/my-people/create-my-people.adoc[] + === 내 피플 정보 조회 -include::{docdir}/people/get-my-people.adoc[] \ No newline at end of file +include::{docdir}/my-people/get-my-people.adoc[] + +=== 내 피플 정보 수정 +include::{docdir}/my-people/update-my-people.adoc[] + +=== 내 피플 프로필 등록 +include::{docdir}/my-people-profile/create-my-people-profile.adoc[] + +=== 내 피플 프로필 조회 +include::{docdir}/my-people-profile/get-my-people-profile.adoc[] + +=== 내 피플 프로필 수정 +include::{docdir}/my-people-profile/update-my-people-profile.adoc[] \ No newline at end of file diff --git a/src/docs/asciidoc/my-people-profile/create-my-people-profile.adoc b/src/docs/asciidoc/my-people-profile/create-my-people-profile.adoc new file mode 100644 index 00000000..8208146f --- /dev/null +++ b/src/docs/asciidoc/my-people-profile/create-my-people-profile.adoc @@ -0,0 +1 @@ +operation::/create-my-people-profile/create-my-people-profile[snippets="http-request,request-headers,request-fields,http-response"] \ No newline at end of file diff --git a/src/docs/asciidoc/my-people-profile/get-my-people-profile.adoc b/src/docs/asciidoc/my-people-profile/get-my-people-profile.adoc new file mode 100644 index 00000000..d48a56f4 --- /dev/null +++ b/src/docs/asciidoc/my-people-profile/get-my-people-profile.adoc @@ -0,0 +1 @@ +operation::/get-my-people-profile/get-my-people-profile[snippets="http-request,request-headers,http-response,response-fields-data"] \ No newline at end of file diff --git a/src/docs/asciidoc/my-people-profile/update-my-people-profile.adoc b/src/docs/asciidoc/my-people-profile/update-my-people-profile.adoc new file mode 100644 index 00000000..22b350f6 --- /dev/null +++ b/src/docs/asciidoc/my-people-profile/update-my-people-profile.adoc @@ -0,0 +1 @@ +operation::/update-my-people-profile/update-my-people-profile[snippets="http-request,request-headers,request-fields,http-response"] \ No newline at end of file diff --git a/src/docs/asciidoc/my-people/create-my-people.adoc b/src/docs/asciidoc/my-people/create-my-people.adoc new file mode 100644 index 00000000..2b64d7de --- /dev/null +++ b/src/docs/asciidoc/my-people/create-my-people.adoc @@ -0,0 +1 @@ +operation::/create-my-people/create-my-people[snippets="http-request,request-headers,request-fields,http-response"] \ No newline at end of file diff --git a/src/docs/asciidoc/my-people/get-my-people.adoc b/src/docs/asciidoc/my-people/get-my-people.adoc new file mode 100644 index 00000000..96df4dd7 --- /dev/null +++ b/src/docs/asciidoc/my-people/get-my-people.adoc @@ -0,0 +1 @@ +operation::/get-my-people/get-my-people[snippets="http-request,request-headers,http-response,response-fields-data"] \ No newline at end of file diff --git a/src/docs/asciidoc/my-people/update-my-people.adoc b/src/docs/asciidoc/my-people/update-my-people.adoc new file mode 100644 index 00000000..8cb38190 --- /dev/null +++ b/src/docs/asciidoc/my-people/update-my-people.adoc @@ -0,0 +1 @@ +operation::/update-my-people/update-my-people[snippets="http-request,request-headers,request-fields,http-response"] \ No newline at end of file diff --git a/src/docs/asciidoc/people/create-people.adoc b/src/docs/asciidoc/people/create-people.adoc deleted file mode 100644 index f0f58b19..00000000 --- a/src/docs/asciidoc/people/create-people.adoc +++ /dev/null @@ -1 +0,0 @@ -operation::/create-people/create-people[snippets="http-request,request-fields,http-response,response-headers,response-fields-data"] \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/member/controller/MyMemberController.java b/src/main/java/es/princip/getp/domain/member/controller/MyMemberController.java index 8e30dfe8..2c0dab2b 100644 --- a/src/main/java/es/princip/getp/domain/member/controller/MyMemberController.java +++ b/src/main/java/es/princip/getp/domain/member/controller/MyMemberController.java @@ -38,7 +38,7 @@ public ResponseEntity uploadProfileImage( @RequestPart MultipartFile image ) { Member member = principalDetails.getMember(); - return ResponseEntity.created(memberService.updateProfileImage(member, image)) + return ResponseEntity.created(memberService.updateProfileImage(member.getMemberId(), image)) .body(ApiResponse.success(HttpStatus.CREATED)); } } diff --git a/src/main/java/es/princip/getp/domain/member/domain/entity/Member.java b/src/main/java/es/princip/getp/domain/member/domain/entity/Member.java index 0988df98..660a8f44 100644 --- a/src/main/java/es/princip/getp/domain/member/domain/entity/Member.java +++ b/src/main/java/es/princip/getp/domain/member/domain/entity/Member.java @@ -11,6 +11,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.net.URI; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -72,7 +73,6 @@ public Member( public void update(final UpdateMemberRequest request) { this.nickname = request.nickname(); this.phoneNumber = request.phoneNumber(); - this.profileImageUri = request.profileImageUri(); } public static Member from(final CreateMemberRequest request) { @@ -82,4 +82,12 @@ public static Member from(final CreateMemberRequest request) { .memberType(request.memberType()) .build(); } + + public void updateProfileImageUri(URI profileImageUri) { + this.profileImageUri = profileImageUri.toString(); + } + + public boolean hasProfileImage() { + return profileImageUri != null; + } } diff --git a/src/main/java/es/princip/getp/domain/member/dto/request/UpdateMemberRequest.java b/src/main/java/es/princip/getp/domain/member/dto/request/UpdateMemberRequest.java index 10bf1325..8b315283 100644 --- a/src/main/java/es/princip/getp/domain/member/dto/request/UpdateMemberRequest.java +++ b/src/main/java/es/princip/getp/domain/member/dto/request/UpdateMemberRequest.java @@ -7,39 +7,34 @@ public record UpdateMemberRequest( String nickname, - String phoneNumber, - String profileImageUri + String phoneNumber ) { public static UpdateMemberRequest from(final CreatePeopleRequest request) { return new UpdateMemberRequest( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() ); } public static UpdateMemberRequest from(final UpdatePeopleRequest request) { return new UpdateMemberRequest( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() ); } public static UpdateMemberRequest from(final CreateClientRequest request) { return new UpdateMemberRequest( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() ); } public static UpdateMemberRequest from(final UpdateClientRequest request) { return new UpdateMemberRequest( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() ); } } diff --git a/src/main/java/es/princip/getp/domain/member/service/MemberService.java b/src/main/java/es/princip/getp/domain/member/service/MemberService.java index a9c3c07b..c32fe256 100644 --- a/src/main/java/es/princip/getp/domain/member/service/MemberService.java +++ b/src/main/java/es/princip/getp/domain/member/service/MemberService.java @@ -73,12 +73,15 @@ public Member create(CreateMemberRequest request) { } @Transactional - public URI updateProfileImage(Member member, MultipartFile image) { - if (member.getProfileImageUri() != null) { - imageStorageService.deleteImage(Paths.get(member.getProfileImageUri())); + public URI updateProfileImage(Long memberId, MultipartFile image) { + Member member = getByMemberId(memberId); + if (member.hasProfileImage()) { + imageStorageService.deleteImage(Paths.get(member.getProfileImageUri())); } Path path = Paths.get(String.valueOf(member.getMemberId())).resolve("profile"); - return URI.create("/" + PathUtil.toURI(imageStorageService.storeImage(path, image))); + URI profileImageUri = URI.create("/" + PathUtil.toURI(imageStorageService.storeImage(path, image))); + member.updateProfileImageUri(profileImageUri); + return profileImageUri; } @Transactional diff --git a/src/main/java/es/princip/getp/domain/people/controller/MyPeopleController.java b/src/main/java/es/princip/getp/domain/people/controller/MyPeopleController.java index 328bff8d..56835355 100644 --- a/src/main/java/es/princip/getp/domain/people/controller/MyPeopleController.java +++ b/src/main/java/es/princip/getp/domain/people/controller/MyPeopleController.java @@ -1,15 +1,10 @@ package es.princip.getp.domain.people.controller; import es.princip.getp.domain.member.domain.entity.Member; -import es.princip.getp.domain.people.dto.request.CreatePeopleProfileRequest; -import es.princip.getp.domain.people.dto.request.UpdatePeopleProfileRequest; +import es.princip.getp.domain.people.dto.request.CreatePeopleRequest; import es.princip.getp.domain.people.dto.request.UpdatePeopleRequest; +import es.princip.getp.domain.people.dto.response.people.CreatePeopleResponse; import es.princip.getp.domain.people.dto.response.people.PeopleResponse; -import es.princip.getp.domain.people.dto.response.people.UpdatePeopleResponse; -import es.princip.getp.domain.people.dto.response.peopleProfile.CreatePeopleProfileResponse; -import es.princip.getp.domain.people.dto.response.peopleProfile.DetailPeopleProfileResponse; -import es.princip.getp.domain.people.dto.response.peopleProfile.UpdatePeopleProfileResponse; -import es.princip.getp.domain.people.service.PeopleProfileService; import es.princip.getp.domain.people.service.PeopleService; import es.princip.getp.global.security.details.PrincipalDetails; import es.princip.getp.global.util.ApiResponse; @@ -20,12 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/people/me") @@ -34,83 +24,52 @@ public class MyPeopleController { private final PeopleService peopleService; - private final PeopleProfileService peopleProfileService; - /** - * 내 피플 정보 수정 - * - * @param request 수정할 피플 정보 - * @return 수정 완료된 피플 정보 + * 내 피플 정보 등록 + * + * @param request 등록할 피플 정보 + * @return 등록된 피플 정보 */ - @PutMapping - @PreAuthorize("isAuthenticated()") - public ResponseEntity> updatePeople( - @RequestBody @Valid UpdatePeopleRequest request, - @AuthenticationPrincipal PrincipalDetails principalDetails) { - Member member = principalDetails.getMember(); - UpdatePeopleResponse response = UpdatePeopleResponse.from(peopleService.update(member.getMemberId(), request)); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); + @PostMapping + @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") + public ResponseEntity> createMyPeople( + @RequestBody @Valid CreatePeopleRequest request, + @AuthenticationPrincipal PrincipalDetails principalDetails) { + Long memberId = principalDetails.getMember().getMemberId(); + CreatePeopleResponse response = CreatePeopleResponse.from(peopleService.create(memberId, request)); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ApiResponse.success(HttpStatus.CREATED, response)); } /** * 내 피플 정보 조회 - * + * * @return 내 피플 정보 */ @GetMapping @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") public ResponseEntity> getMyPeople( - @AuthenticationPrincipal PrincipalDetails principalDetails) { - Member member = principalDetails.getMember(); - PeopleResponse response = PeopleResponse.from(peopleService.getByMemberId(member.getMemberId())); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); - } - - /** - * 피플 프로필 등록 - * - * @param request 등록할 피플 프로필 정보 - * @return 등록된 피플 프로필 정보 - */ - @PostMapping("/profile") - @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") - public ResponseEntity> createPeopleProfile( - @RequestBody @Valid CreatePeopleProfileRequest request, @AuthenticationPrincipal PrincipalDetails principalDetails) { Member member = principalDetails.getMember(); - CreatePeopleProfileResponse response = - CreatePeopleProfileResponse.from(peopleProfileService.create(member.getMemberId(), request)); - return ResponseEntity.status(HttpStatus.CREATED) - .body(ApiResponse.success(HttpStatus.CREATED, response)); + PeopleResponse response = PeopleResponse.from(peopleService.getByMemberId(member.getMemberId())); + return ResponseEntity.ok() + .body(ApiResponse.success(HttpStatus.OK, response)); } /** - * 내 피플 프로필 조회 + * 내 피플 정보 수정 * - * @return 내 피플 프로필 정보 + * @param request 수정할 피플 정보 + * @return 수정된 피플 정보 */ - @GetMapping("/profile") + @PutMapping @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") - public ResponseEntity> getMyPeopleProfile( - @AuthenticationPrincipal PrincipalDetails principalDetails) { - Member member = principalDetails.getMember(); - DetailPeopleProfileResponse response = DetailPeopleProfileResponse.from(peopleProfileService.getByMemberId(member.getMemberId())); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); - } - - /** - * 내 피플 프로필 수정 - * - * @param request 수정할 피플 프로필 정보 - * @return 수정 완료된 피플 프로필 정보 - */ - @PutMapping("/profile") - @PreAuthorize("isAuthenticated()") - public ResponseEntity> updatePeopleProfile( - @RequestBody @Valid UpdatePeopleProfileRequest request, + public ResponseEntity> updateMyPeople( + @RequestBody @Valid UpdatePeopleRequest request, @AuthenticationPrincipal PrincipalDetails principalDetails) { Member member = principalDetails.getMember(); - UpdatePeopleProfileResponse response = UpdatePeopleProfileResponse.from(peopleProfileService.update(member.getMemberId(), request)); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); + peopleService.update(member.getMemberId(), request); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ApiResponse.success(HttpStatus.CREATED)); } } \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/controller/MyPeopleProfileController.java b/src/main/java/es/princip/getp/domain/people/controller/MyPeopleProfileController.java new file mode 100644 index 00000000..21f9d8ba --- /dev/null +++ b/src/main/java/es/princip/getp/domain/people/controller/MyPeopleProfileController.java @@ -0,0 +1,74 @@ +package es.princip.getp.domain.people.controller; + +import es.princip.getp.domain.member.domain.entity.Member; +import es.princip.getp.domain.people.dto.request.CreatePeopleProfileRequest; +import es.princip.getp.domain.people.dto.request.UpdatePeopleProfileRequest; +import es.princip.getp.domain.people.dto.response.peopleProfile.DetailPeopleProfileResponse; +import es.princip.getp.domain.people.service.PeopleProfileService; +import es.princip.getp.global.security.details.PrincipalDetails; +import es.princip.getp.global.util.ApiResponse; +import es.princip.getp.global.util.ApiResponse.ApiSuccessResult; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/people/me/profile") +@RequiredArgsConstructor +public class MyPeopleProfileController { + + private final PeopleProfileService peopleProfileService; + + /** + * 내 피플 프로필 등록 + * + * @param request 등록할 피플 프로필 정보 + * @return 등록된 피플 프로필 정보 + */ + @PostMapping + @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") + public ResponseEntity> createMyPeopleProfile( + @RequestBody @Valid CreatePeopleProfileRequest request, + @AuthenticationPrincipal PrincipalDetails principalDetails) { + Member member = principalDetails.getMember(); + peopleProfileService.create(member.getMemberId(), request); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ApiResponse.success(HttpStatus.CREATED)); + } + + /** + * 내 피플 프로필 조회 + * + * @return 내 피플 프로필 정보 + */ + @GetMapping + @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") + public ResponseEntity> getMyPeopleProfile( + @AuthenticationPrincipal PrincipalDetails principalDetails) { + Member member = principalDetails.getMember(); + DetailPeopleProfileResponse response = DetailPeopleProfileResponse.from(peopleProfileService.getByMemberId(member.getMemberId())); + return ResponseEntity.ok() + .body(ApiResponse.success(HttpStatus.OK, response)); + } + + /** + * 내 피플 프로필 수정 + * + * @param request 수정할 피플 프로필 정보 + * @return 수정된 피플 프로필 정보 + */ + @PutMapping + @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") + public ResponseEntity> updateMyPeopleProfile( + @RequestBody @Valid UpdatePeopleProfileRequest request, + @AuthenticationPrincipal PrincipalDetails principalDetails) { + Member member = principalDetails.getMember(); + peopleProfileService.update(member.getMemberId(), request); + return ResponseEntity.status(HttpStatus.CREATED) + .body(ApiResponse.success(HttpStatus.CREATED)); + } +} \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/controller/PeopleController.java b/src/main/java/es/princip/getp/domain/people/controller/PeopleController.java index 27901f07..e09c903f 100644 --- a/src/main/java/es/princip/getp/domain/people/controller/PeopleController.java +++ b/src/main/java/es/princip/getp/domain/people/controller/PeopleController.java @@ -1,29 +1,23 @@ package es.princip.getp.domain.people.controller; -import es.princip.getp.domain.people.dto.request.CreatePeopleRequest; import es.princip.getp.domain.people.dto.response.people.CardPeopleResponse; -import es.princip.getp.domain.people.dto.response.people.CreatePeopleResponse; import es.princip.getp.domain.people.dto.response.people.DetailPeopleResponse; import es.princip.getp.domain.people.dto.response.people.PublicDetailPeopleResponse; import es.princip.getp.domain.people.service.PeopleService; import es.princip.getp.global.domain.dto.response.PageResponse; -import es.princip.getp.global.security.details.PrincipalDetails; import es.princip.getp.global.support.ControllerSupport; import es.princip.getp.global.util.ApiResponse; import es.princip.getp.global.util.ApiResponse.ApiSuccessResult; -import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.*; - -import java.net.URI; -import java.net.URISyntaxException; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/people") @@ -32,23 +26,6 @@ public class PeopleController extends ControllerSupport { private final PeopleService peopleService; - /** - * 피플 정보 등록 - * - * @param request 등록할 피플 정보 - * @return 등록된 피플 정보 - */ - @PostMapping - @PreAuthorize("hasRole('PEOPLE') and isAuthenticated()") - public ResponseEntity> createPeople( - @RequestBody @Valid CreatePeopleRequest request, - @AuthenticationPrincipal PrincipalDetails principalDetails) throws URISyntaxException { - Long memberId = principalDetails.getMember().getMemberId(); - CreatePeopleResponse response = CreatePeopleResponse.from(peopleService.create(memberId, request)); - return ResponseEntity.created(new URI("/people/" + response.peopleId())) - .body(ApiResponse.success(HttpStatus.CREATED, response)); - } - /** * 포트폴리오 개발 진행 후 완성 예정 - 피플 상세 조회 * @@ -59,10 +36,12 @@ public ResponseEntity> createPeople( public ResponseEntity> getPeople(@PathVariable Long peopleId) { if (isAuthenticated()) { DetailPeopleResponse response = DetailPeopleResponse.from(peopleService.getByPeopleId(peopleId)); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); + return ResponseEntity.ok() + .body(ApiResponse.success(HttpStatus.OK, response)); } PublicDetailPeopleResponse response = PublicDetailPeopleResponse.from(peopleService.getByPeopleId(peopleId)); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); + return ResponseEntity.ok() + .body(ApiResponse.success(HttpStatus.OK, response)); } /** @@ -75,6 +54,7 @@ public ResponseEntity> getPeople(@PathVariable Long peopleId public ResponseEntity>> getCardPeoplePage( @PageableDefault(sort = "peopleId", direction = Sort.Direction.DESC) Pageable pageable) { PageResponse response = PageResponse.from(peopleService.getCardPeoplePage(pageable)); - return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response)); + return ResponseEntity.ok() + .body(ApiResponse.success(HttpStatus.OK, response)); } } \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/dto/request/CreatePeopleRequest.java b/src/main/java/es/princip/getp/domain/people/dto/request/CreatePeopleRequest.java index f75f8280..3079cf84 100644 --- a/src/main/java/es/princip/getp/domain/people/dto/request/CreatePeopleRequest.java +++ b/src/main/java/es/princip/getp/domain/people/dto/request/CreatePeopleRequest.java @@ -11,7 +11,6 @@ public record CreatePeopleRequest( @NotBlank String nickname, @Email String email, @NotNull @PhoneNumber String phoneNumber, - @Enum PeopleType peopleType, - String profileImageUri + @Enum PeopleType peopleType ) { } \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/dto/request/UpdatePeopleRequest.java b/src/main/java/es/princip/getp/domain/people/dto/request/UpdatePeopleRequest.java index ba294a71..49913128 100644 --- a/src/main/java/es/princip/getp/domain/people/dto/request/UpdatePeopleRequest.java +++ b/src/main/java/es/princip/getp/domain/people/dto/request/UpdatePeopleRequest.java @@ -11,7 +11,6 @@ public record UpdatePeopleRequest( @NotBlank String nickname, @Email String email, @NotNull @PhoneNumber String phoneNumber, - @Enum PeopleType peopleType, - @NotNull String profileImageUri + @Enum PeopleType peopleType ) { } \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/dto/response/people/UpdatePeopleResponse.java b/src/main/java/es/princip/getp/domain/people/dto/response/people/UpdatePeopleResponse.java deleted file mode 100644 index 6fc469ed..00000000 --- a/src/main/java/es/princip/getp/domain/people/dto/response/people/UpdatePeopleResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -package es.princip.getp.domain.people.dto.response.people; - -import es.princip.getp.domain.people.domain.entity.People; -import es.princip.getp.domain.people.domain.enums.PeopleType; - -import java.time.LocalDateTime; - -public record UpdatePeopleResponse( - Long peopleId, - String nickname, - String email, - String phoneNumber, - PeopleType peopleType, - String profileImageUri, - LocalDateTime createdAt, - LocalDateTime updatedAt -) { - - public static UpdatePeopleResponse from(People people) { - return new UpdatePeopleResponse( - people.getPeopleId(), - people.getNickname(), - people.getEmail(), - people.getPhoneNumber(), - people.getPeopleType(), - people.getProfileImageUri(), - people.getCreatedAt(), - people.getUpdatedAt() - ); - } -} \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/dto/response/peopleProfile/CreatePeopleProfileResponse.java b/src/main/java/es/princip/getp/domain/people/dto/response/peopleProfile/CreatePeopleProfileResponse.java deleted file mode 100644 index b1ea6a3d..00000000 --- a/src/main/java/es/princip/getp/domain/people/dto/response/peopleProfile/CreatePeopleProfileResponse.java +++ /dev/null @@ -1,29 +0,0 @@ -package es.princip.getp.domain.people.dto.response.peopleProfile; - -import es.princip.getp.domain.people.domain.entity.PeopleProfile; -import es.princip.getp.domain.people.domain.values.Education; -import es.princip.getp.domain.people.domain.values.Portfolio; -import es.princip.getp.global.domain.values.Hashtag; -import es.princip.getp.global.domain.values.TechStack; -import java.util.List; - -public record CreatePeopleProfileResponse( - String introduction, - String activityArea, - List techStacks, - Education education, - List hashtags, - List portfolios -) { - - public static CreatePeopleProfileResponse from(final PeopleProfile peopleProfile) { - return new CreatePeopleProfileResponse( - peopleProfile.getIntroduction(), - peopleProfile.getActivityArea(), - peopleProfile.getTechStacks(), - peopleProfile.getEducation(), - peopleProfile.getHashtags(), - peopleProfile.getPortfolios() - ); - } -} \ No newline at end of file diff --git a/src/main/java/es/princip/getp/domain/people/dto/response/peopleProfile/UpdatePeopleProfileResponse.java b/src/main/java/es/princip/getp/domain/people/dto/response/peopleProfile/UpdatePeopleProfileResponse.java deleted file mode 100644 index 2e0452bb..00000000 --- a/src/main/java/es/princip/getp/domain/people/dto/response/peopleProfile/UpdatePeopleProfileResponse.java +++ /dev/null @@ -1,29 +0,0 @@ -package es.princip.getp.domain.people.dto.response.peopleProfile; - -import es.princip.getp.domain.people.domain.entity.PeopleProfile; -import es.princip.getp.domain.people.domain.values.Education; -import es.princip.getp.domain.people.domain.values.Portfolio; -import es.princip.getp.global.domain.values.Hashtag; -import es.princip.getp.global.domain.values.TechStack; -import java.util.List; - -public record UpdatePeopleProfileResponse( - String introduction, - String activityArea, - List techStacks, - Education education, - List hashtags, - List portfolios -) { - - public static UpdatePeopleProfileResponse from(final PeopleProfile peopleProfile) { - return new UpdatePeopleProfileResponse( - peopleProfile.getIntroduction(), - peopleProfile.getActivityArea(), - peopleProfile.getTechStacks(), - peopleProfile.getEducation(), - peopleProfile.getHashtags(), - peopleProfile.getPortfolios() - ); - } -} \ No newline at end of file diff --git a/src/main/java/es/princip/getp/global/exception/handler/AccessDeniedExceptionHandler.java b/src/main/java/es/princip/getp/global/exception/handler/AccessDeniedExceptionHandler.java new file mode 100644 index 00000000..901fcb36 --- /dev/null +++ b/src/main/java/es/princip/getp/global/exception/handler/AccessDeniedExceptionHandler.java @@ -0,0 +1,28 @@ +package es.princip.getp.global.exception.handler; + +import es.princip.getp.global.exception.ErrorDescription; +import es.princip.getp.global.util.ApiResponse; +import es.princip.getp.global.util.ApiResponse.ApiErrorResult; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@RestControllerAdvice +@Slf4j +public class AccessDeniedExceptionHandler { + + @ExceptionHandler(AccessDeniedException.class) + public ResponseEntity validationException( + final AccessDeniedException exception) { + ErrorDescription description = ErrorDescription.of( + "ACCESS_DENIED", + "접근할 수 없습니다." + ); + log.debug(exception.getMessage()); + return ResponseEntity.status(HttpStatus.FORBIDDEN) + .body(ApiResponse.error(HttpStatus.FORBIDDEN, description)); + } +} \ No newline at end of file diff --git a/src/main/java/es/princip/getp/global/util/ApiResponse.java b/src/main/java/es/princip/getp/global/util/ApiResponse.java index 17e42570..a9e0fec3 100644 --- a/src/main/java/es/princip/getp/global/util/ApiResponse.java +++ b/src/main/java/es/princip/getp/global/util/ApiResponse.java @@ -12,6 +12,10 @@ public static ApiSuccessResult success(HttpStatus status, T data) { return new ApiSuccessResult<>(status.value(), data); } + public static ApiSuccessResult success(HttpStatus status, String message) { + return new ApiSuccessResult<>(status.value(), message); + } + public static ApiSuccessResult success(HttpStatus status) { return new ApiSuccessResult<>(status.value()); } @@ -29,15 +33,24 @@ public static ApiErrorResult error(HttpStatus status, ErrorDescription... descri public static class ApiSuccessResult { private final int status; private final T data; + private final String message; private ApiSuccessResult(int status, T data) { this.status = status; this.data = data; + this.message = null; } private ApiSuccessResult(int status) { this.status = status; this.data = null; + this.message = null; + } + + private ApiSuccessResult(int status, String message) { + this.status = status; + this.data = null; + this.message = message; } } diff --git a/src/test/java/es/princip/getp/domain/client/fixture/ClientFixture.java b/src/test/java/es/princip/getp/domain/client/fixture/ClientFixture.java index 1737247e..3cf5fcee 100644 --- a/src/test/java/es/princip/getp/domain/client/fixture/ClientFixture.java +++ b/src/test/java/es/princip/getp/domain/client/fixture/ClientFixture.java @@ -48,7 +48,7 @@ public static Client createClient(Member member) { } public static Client createClient() { - return Client.from(createMember(NICKNAME, PHONE_NUMBER, PROFILE_IMAGE_URI), createClientRequest()); + return Client.from(createMember(NICKNAME, PHONE_NUMBER), createClientRequest()); } public static Client createClient(Member member, UpdateClientRequest request) { diff --git a/src/test/java/es/princip/getp/domain/client/service/ClientServiceTest.java b/src/test/java/es/princip/getp/domain/client/service/ClientServiceTest.java index 531267d3..aec99e45 100644 --- a/src/test/java/es/princip/getp/domain/client/service/ClientServiceTest.java +++ b/src/test/java/es/princip/getp/domain/client/service/ClientServiceTest.java @@ -52,8 +52,7 @@ class Create { void setUp() { mockMember = Mockito.spy(createMember( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() )); given(mockMember.getMemberId()).willReturn(1L); } @@ -72,7 +71,6 @@ void create() { softly.assertThat(created.getNickname()).isEqualTo(request.nickname()); softly.assertThat(created.getEmail()).isEqualTo(request.email()); softly.assertThat(created.getPhoneNumber()).isEqualTo(request.phoneNumber()); - softly.assertThat(created.getProfileImageUri()).isEqualTo(request.profileImageUri()); softly.assertThat(created.getAddress()).isEqualTo(request.address()); softly.assertThat(created.getBankAccount()).isEqualTo(request.bankAccount()); }); @@ -141,8 +139,7 @@ class Update { void setUp() { mockMember = Mockito.spy(createMember( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() )); given(mockMember.getMemberId()).willReturn(1L); mockClient = createClient(mockMember); @@ -161,7 +158,6 @@ void update() { softly.assertThat(updated.getNickname()).isEqualTo(request.nickname()); softly.assertThat(updated.getEmail()).isEqualTo(request.email()); softly.assertThat(updated.getPhoneNumber()).isEqualTo(request.phoneNumber()); - softly.assertThat(updated.getProfileImageUri()).isEqualTo(request.profileImageUri()); softly.assertThat(updated.getAddress()).isEqualTo(request.address()); softly.assertThat(updated.getBankAccount()).isEqualTo(request.bankAccount()); }); diff --git a/src/test/java/es/princip/getp/domain/member/fixture/MemberFixture.java b/src/test/java/es/princip/getp/domain/member/fixture/MemberFixture.java index a7943ead..9176c2ce 100644 --- a/src/test/java/es/princip/getp/domain/member/fixture/MemberFixture.java +++ b/src/test/java/es/princip/getp/domain/member/fixture/MemberFixture.java @@ -62,15 +62,13 @@ public static Member createMember(final String email, final MemberType memberTyp public static Member createMember( final String nickname, - final String phoneNumber, - final String profileImageUri + final String phoneNumber ) { return Member.builder() .password(PASSWORD) .memberType(MEMBER_TYPE) .nickname(nickname) .phoneNumber(phoneNumber) - .profileImageUri(profileImageUri) .build(); } diff --git a/src/test/java/es/princip/getp/domain/member/service/MemberServiceTest.java b/src/test/java/es/princip/getp/domain/member/service/MemberServiceTest.java index de91c50f..0f1eb40d 100644 --- a/src/test/java/es/princip/getp/domain/member/service/MemberServiceTest.java +++ b/src/test/java/es/princip/getp/domain/member/service/MemberServiceTest.java @@ -62,8 +62,7 @@ class Update { private Member mockMember; private final UpdateMemberRequest request = new UpdateMemberRequest( "newNickname", - "010-9999-8888", - "/images/1/profile/newImage.jpeg" + "010-9999-8888" ); @BeforeEach @@ -81,7 +80,6 @@ void update() { assertThat(mockMember.getNickname()).isEqualTo(request.nickname()); assertThat(mockMember.getPhoneNumber()).isEqualTo(request.phoneNumber()); - assertThat(mockMember.getProfileImageUri()).isEqualTo(request.profileImageUri()); } } @@ -94,11 +92,13 @@ void updateProfileImage() throws IOException { MultipartFile image = createImageMultiPartFile(); Path path = Paths.get("images").resolve(String.valueOf(member.getMemberId())).resolve("profile"); Path imagePath = path.resolve("image.jpeg"); + given(memberRepository.findById(member.getMemberId())).willReturn(Optional.of(member)); given(imageStorageService.storeImage(any(), eq(image))).willReturn(imagePath); - URI profileImageUri = memberService.updateProfileImage(member, image); + URI profileImageUri = memberService.updateProfileImage(member.getMemberId(), image); assertThat(profileImageUri).isEqualTo(URI.create("/" + PathUtil.toURI(imagePath))); + assertThat(member.getProfileImageUri()).isEqualTo(profileImageUri.toString()); } } diff --git a/src/test/java/es/princip/getp/domain/people/controller/MyPeopleControllerTest.java b/src/test/java/es/princip/getp/domain/people/controller/MyPeopleControllerTest.java index 144c11a2..c1f5a26f 100644 --- a/src/test/java/es/princip/getp/domain/people/controller/MyPeopleControllerTest.java +++ b/src/test/java/es/princip/getp/domain/people/controller/MyPeopleControllerTest.java @@ -1,10 +1,14 @@ package es.princip.getp.domain.people.controller; import es.princip.getp.domain.member.domain.entity.Member; +import es.princip.getp.domain.people.controller.description.request.CreatePeopleRequestDescription; +import es.princip.getp.domain.people.controller.description.request.UpdatePeopleRequestDescription; +import es.princip.getp.domain.people.controller.description.response.CreatePeopleResponseDescription; +import es.princip.getp.domain.people.controller.description.response.PeopleResponseDescription; import es.princip.getp.domain.people.domain.entity.People; -import es.princip.getp.domain.people.service.PeopleProfileService; +import es.princip.getp.domain.people.dto.request.CreatePeopleRequest; +import es.princip.getp.domain.people.dto.request.UpdatePeopleRequest; import es.princip.getp.domain.people.service.PeopleService; -import es.princip.getp.global.controller.ErrorCodeController; import es.princip.getp.global.mock.WithCustomMockUser; import es.princip.getp.global.security.details.PrincipalDetails; import es.princip.getp.global.support.AbstractControllerTest; @@ -13,67 +17,129 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.ResultActions; -import java.time.LocalDateTime; - +import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_CLIENT; import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_PEOPLE; -import static es.princip.getp.domain.people.fixture.PeopleFixture.createPeople; -import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; +import static es.princip.getp.domain.people.fixture.PeopleFixture.*; import static es.princip.getp.global.support.HeaderDescriptorHelper.authorizationHeaderDescriptor; import static es.princip.getp.global.support.PayloadDocumentationHelper.responseFields; -import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.spy; -import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest({MyPeopleController.class, ErrorCodeController.class}) +@WebMvcTest({MyPeopleController.class, PeopleErrorCodeController.class}) class MyPeopleControllerTest extends AbstractControllerTest { @MockBean private PeopleService peopleService; - @MockBean - private PeopleProfileService peopleProfileService; + @DisplayName("피플은 자신의 정보를 등록할 수 있다.") + @Nested + class CreateMyPeople { + + private final CreatePeopleRequest request = createPeopleRequest(); + + private ResultActions perform() throws Exception { + return mockMvc.perform(post("/people/me") + .header("Authorization", "Bearer ${ACCESS_TOKEN}") + .content(objectMapper.writeValueAsString(request))); + } + + @WithCustomMockUser(memberType = ROLE_PEOPLE) + @Test + public void createMyPeople(PrincipalDetails principalDetails) throws Exception { + Member member = principalDetails.getMember(); + People people = spy(createPeople(member)); + given(people.getPeopleId()).willReturn(1L); + given(peopleService.create(member.getMemberId(), request)).willReturn(people); + + perform() + .andExpect(status().isCreated()) + .andDo(restDocs.document( + requestHeaders(authorizationHeaderDescriptor()), + requestFields(CreatePeopleRequestDescription.description()), + responseFields(CreatePeopleResponseDescription.description()) + )) + .andDo(print()); + } - @DisplayName("피플은 자신의 피플 정보를 조회할 수 있다.") + @WithCustomMockUser(memberType = ROLE_CLIENT) + @Test + public void createMyPeople_WhenMemberTypeIsClient_ShouldFail() throws Exception { + expectForbidden(perform()); + } + } + + @DisplayName("피플은 자신의 정보를 조회할 수 있다.") @Nested class GetMyPeople { + private ResultActions perform() throws Exception { + return mockMvc.perform(get("/people/me") + .header("Authorization", "Bearer ${ACCESS_TOKEN}")); + } + @WithCustomMockUser(memberType = ROLE_PEOPLE) @Test void getMyPeople(PrincipalDetails principalDetails) throws Exception { Member member = principalDetails.getMember(); People people = spy(createPeople(member)); - given(people.getPeopleId()).willReturn(1L); - given(people.getCreatedAt()).willReturn(LocalDateTime.now()); - given(people.getUpdatedAt()).willReturn(LocalDateTime.now()); + given(peopleService.getByMemberId(member.getMemberId())).willReturn(people); - given(peopleService.getByMemberId(anyLong())).willReturn(people); + perform() + .andExpect(status().isOk()) + .andDo(restDocs.document( + requestHeaders(authorizationHeaderDescriptor()), + responseFields(PeopleResponseDescription.description()) + )) + .andDo(print()); + } - mockMvc.perform(get("/people/me") + @WithCustomMockUser(memberType = ROLE_CLIENT) + @Test + public void getMyPeople_WhenMemberTypeIsClient_ShouldFail() throws Exception { + expectForbidden(perform()); + } + } + + @DisplayName("피플은 자신의 정보를 수정할 수 있다.") + @Nested + class UpdateMyPeople { + + private final UpdatePeopleRequest request = updatePeopleRequest(); + + private ResultActions perform() throws Exception { + return mockMvc.perform(put("/people/me") .header("Authorization", "Bearer ${ACCESS_TOKEN}") - .contentType(APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo( - restDocs.document( - requestHeaders(authorizationHeaderDescriptor()), - responseFields( - getDescriptor("peopleId", "피플 ID"), - getDescriptor("nickname", "닉네임"), - getDescriptor("email", "이메일(기본값은 회원 가입 시 기입한 이메일)"), - getDescriptor("phoneNumber", "전화번호"), - getDescriptor("peopleType", "피플 유형"), - getDescriptor("profileImageUri", "프로필 이미지 URI"), - getDescriptor("createdAt", "피플 정보 등록일"), - getDescriptor("updatedAt", "피플 정보 수정일") - ) - ) - ) + .content(objectMapper.writeValueAsString(request))); + } + + @WithCustomMockUser(memberType = ROLE_PEOPLE) + @Test + public void updateMyPeople(PrincipalDetails principalDetails) throws Exception { + Member member = principalDetails.getMember(); + People people = spy(createPeople(member)); + given(people.getPeopleId()).willReturn(1L); + given(peopleService.update(member.getMemberId(), request)).willReturn(people); + + perform() + .andExpect(status().isCreated()) + .andDo(restDocs.document( + requestHeaders(authorizationHeaderDescriptor()), + requestFields(UpdatePeopleRequestDescription.description()) + )) .andDo(print()); } + + @WithCustomMockUser(memberType = ROLE_CLIENT) + @Test + public void updateMyPeople_WhenMemberTypeIsClient_ShouldFail() throws Exception { + expectForbidden(perform()); + } } } \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/MyPeopleProfileControllerTest.java b/src/test/java/es/princip/getp/domain/people/controller/MyPeopleProfileControllerTest.java new file mode 100644 index 00000000..7d83dda1 --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/MyPeopleProfileControllerTest.java @@ -0,0 +1,148 @@ +package es.princip.getp.domain.people.controller; + +import es.princip.getp.domain.member.domain.entity.Member; +import es.princip.getp.domain.people.controller.description.request.CreatePeopleProfileRequestDescription; +import es.princip.getp.domain.people.controller.description.request.UpdatePeopleProfileRequestDescription; +import es.princip.getp.domain.people.controller.description.response.DetailPeopleProfileResponseDescription; +import es.princip.getp.domain.people.domain.entity.People; +import es.princip.getp.domain.people.domain.entity.PeopleProfile; +import es.princip.getp.domain.people.dto.request.CreatePeopleProfileRequest; +import es.princip.getp.domain.people.dto.request.UpdatePeopleProfileRequest; +import es.princip.getp.domain.people.service.PeopleProfileService; +import es.princip.getp.global.mock.WithCustomMockUser; +import es.princip.getp.global.security.details.PrincipalDetails; +import es.princip.getp.global.support.AbstractControllerTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.ResultActions; + +import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_CLIENT; +import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_PEOPLE; +import static es.princip.getp.domain.people.fixture.PeopleFixture.createPeople; +import static es.princip.getp.domain.people.fixture.PeopleProfileFixture.*; +import static es.princip.getp.global.support.HeaderDescriptorHelper.authorizationHeaderDescriptor; +import static es.princip.getp.global.support.PayloadDocumentationHelper.responseFields; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.spy; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest({MyPeopleProfileController.class}) +class MyPeopleProfileControllerTest extends AbstractControllerTest { + + @MockBean + private PeopleProfileService peopleProfileService; + + private static final String MY_PEOPLE_PROFILE_URI = "/people/me/profile"; + + @DisplayName("피플은 자신의 프로필을 등록할 수 있다.") + @Nested + class CreateMyPeopleProfile { + + private final CreatePeopleProfileRequest request = createPeopleProfileRequest(); + + private ResultActions perform() throws Exception { + return mockMvc.perform(post(MY_PEOPLE_PROFILE_URI) + .header("Authorization", "Bearer ${ACCESS_TOKEN}") + .content(objectMapper.writeValueAsString(request))); + } + + @WithCustomMockUser(memberType = ROLE_PEOPLE) + @Test + public void createMyPeopleProfile(PrincipalDetails principalDetails) throws Exception { + Member member = principalDetails.getMember(); + People people = spy(createPeople(member)); + PeopleProfile profile = createPeopleProfile(request, people); + given(people.getPeopleId()).willReturn(1L); + given(peopleProfileService.create(member.getMemberId(), request)).willReturn(profile); + + perform() + .andExpect(status().isCreated()) + .andDo(restDocs.document( + requestHeaders(authorizationHeaderDescriptor()), + requestFields(CreatePeopleProfileRequestDescription.description()) + )) + .andDo(print()); + } + + @WithCustomMockUser(memberType = ROLE_CLIENT) + @Test + public void createMyPeopleProfile_WhenMemberTypeIsClient_ShouldFail() throws Exception { + expectForbidden(perform()); + } + } + + @DisplayName("피플은 자신의 프로필을 조회할 수 있다.") + @Nested + class GetMyPeopleProfile { + + private ResultActions perform() throws Exception { + return mockMvc.perform(get(MY_PEOPLE_PROFILE_URI) + .header("Authorization", "Bearer ${ACCESS_TOKEN}")); + } + + @WithCustomMockUser(memberType = ROLE_PEOPLE) + @Test + void getMyPeopleProfile(PrincipalDetails principalDetails) throws Exception { + Member member = principalDetails.getMember(); + People people = spy(createPeople(member)); + PeopleProfile profile = createPeopleProfile(people); + given(peopleProfileService.getByMemberId(member.getMemberId())).willReturn(profile); + + perform() + .andExpect(status().isOk()) + .andDo(restDocs.document( + requestHeaders(authorizationHeaderDescriptor()), + responseFields(DetailPeopleProfileResponseDescription.description()) + )) + .andDo(print()); + } + + @WithCustomMockUser(memberType = ROLE_CLIENT) + @Test + public void getMyPeopleProfile_WhenMemberTypeIsClient_ShouldFail() throws Exception { + expectForbidden(perform()); + } + } + + @DisplayName("피플은 자신의 프로필을 수정할 수 있다.") + @Nested + class UpdateMyPeopleProfile { + + private final UpdatePeopleProfileRequest request = updatePeopleProfileRequest(); + + private ResultActions perform() throws Exception { + return mockMvc.perform(put(MY_PEOPLE_PROFILE_URI) + .header("Authorization", "Bearer ${ACCESS_TOKEN}") + .content(objectMapper.writeValueAsString(request))); + } + + @WithCustomMockUser(memberType = ROLE_PEOPLE) + @Test + public void updateMyPeopleProfile(PrincipalDetails principalDetails) throws Exception { + Member member = principalDetails.getMember(); + People people = spy(createPeople(member)); + PeopleProfile profile = createPeopleProfile(request, people); + given(peopleProfileService.update(member.getMemberId(), request)).willReturn(profile); + + perform() + .andExpect(status().isCreated()) + .andDo(restDocs.document( + requestHeaders(authorizationHeaderDescriptor()), + requestFields(UpdatePeopleProfileRequestDescription.description()) + )) + .andDo(print()); + } + + @WithCustomMockUser(memberType = ROLE_CLIENT) + @Test + public void updateMyPeopleProfile_WhenMemberTypeIsClient_ShouldFail() throws Exception { + expectForbidden(perform()); + } + } +} \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/PeopleControllerTest.java b/src/test/java/es/princip/getp/domain/people/controller/PeopleControllerTest.java index 5bd8f6a2..38e3f443 100644 --- a/src/test/java/es/princip/getp/domain/people/controller/PeopleControllerTest.java +++ b/src/test/java/es/princip/getp/domain/people/controller/PeopleControllerTest.java @@ -1,13 +1,13 @@ package es.princip.getp.domain.people.controller; import es.princip.getp.domain.member.domain.entity.Member; +import es.princip.getp.domain.people.controller.description.response.DetailPeopleResponseDescription; +import es.princip.getp.domain.people.controller.description.response.PublicDetailPeopleResponseDescription; import es.princip.getp.domain.people.domain.entity.People; -import es.princip.getp.domain.people.dto.request.CreatePeopleRequest; import es.princip.getp.domain.people.dto.response.people.CardPeopleResponse; import es.princip.getp.domain.people.fixture.PeopleFixture; import es.princip.getp.domain.people.service.PeopleService; import es.princip.getp.global.mock.WithCustomMockUser; -import es.princip.getp.global.security.details.PrincipalDetails; import es.princip.getp.global.support.AbstractControllerTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -20,24 +20,18 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; -import org.springframework.security.access.AccessDeniedException; import org.springframework.test.web.servlet.ResultActions; -import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_CLIENT; import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_PEOPLE; import static es.princip.getp.domain.member.fixture.MemberFixture.createMember; -import static es.princip.getp.domain.people.fixture.PeopleFixture.createPeopleRequest; import static es.princip.getp.domain.people.fixture.PeopleProfileFixture.createPeopleProfile; import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; import static es.princip.getp.global.support.HeaderDescriptorHelper.authorizationHeaderDescriptor; import static es.princip.getp.global.support.PageResponseDescriptor.pageResponseFieldDescriptors; import static es.princip.getp.global.support.PayloadDocumentationHelper.responseFields; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.springframework.http.MediaType.APPLICATION_JSON; -import static org.springframework.restdocs.headers.HeaderDocumentation.*; -import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; +import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; import static org.springframework.restdocs.request.RequestDocumentation.*; import static org.springframework.restdocs.snippet.Attributes.key; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -60,8 +54,7 @@ private ResultActions perform() throws Exception { return mockMvc.perform(get("/people") .queryParam("page", String.valueOf(page)) .queryParam("size", String.valueOf(size)) - .queryParam("sort", "peopleId,desc") - .contentType(APPLICATION_JSON)); + .queryParam("sort", "peopleId,desc")); } @Test @@ -105,14 +98,12 @@ class GetPeople { private final Long peopleId = 2L; private ResultActions perform() throws Exception { - return mockMvc.perform(get("/people/{peopleId}", peopleId) - .contentType(APPLICATION_JSON)); + return mockMvc.perform(get("/people/{peopleId}", peopleId)); } - private ResultActions performWithAcessToken() throws Exception { + private ResultActions performWithAccessToken() throws Exception { return mockMvc.perform(get("/people/{peopleId}", peopleId) - .header("Authorization", "Bearer ${ACCESS_TOKEN}") - .contentType(APPLICATION_JSON)); + .header("Authorization", "Bearer ${ACCESS_TOKEN}")); } @BeforeEach @@ -130,19 +121,8 @@ public void getPeople_WhenUserNotLogined() throws Exception { .andExpect(status().isOk()) .andDo( restDocs.document( - pathParameters( - parameterWithName("peopleId").description("피플 ID") - ), - responseFields( - getDescriptor("peopleId", "피플 ID"), - getDescriptor("nickname", "닉네임"), - getDescriptor("peopleType", "피플 유형") - .attributes(key("format").value("TEAM, INDIVIDUAL")), - getDescriptor("profileImageUri", "프로필 이미지 URI"), - getDescriptor("profile.hashtags[].value", "해시태그"), - getDescriptor("profile.completedProjectsCount", "완수한 프로젝트 수"), - getDescriptor("profile.interestsCount", "받은 관심 수") - ) + pathParameters(parameterWithName("peopleId").description("피플 ID")), + responseFields(PublicDetailPeopleResponseDescription.description()) ) ); } @@ -150,90 +130,15 @@ public void getPeople_WhenUserNotLogined() throws Exception { @Test @WithCustomMockUser(memberType = ROLE_PEOPLE) public void getPeople_WhenUserLogined() throws Exception { - performWithAcessToken() + performWithAccessToken() .andExpect(status().isOk()) .andDo( restDocs.document( - requestHeaders( - authorizationHeaderDescriptor() - ), - pathParameters( - parameterWithName("peopleId").description("피플 ID") - ), - responseFields( - getDescriptor("peopleId", "피플 ID"), - getDescriptor("nickname", "닉네임"), - getDescriptor("peopleType", "피플 유형") - .attributes(key("format").value("TEAM, INDIVIDUAL")), - getDescriptor("profileImageUri", "프로필 이미지 URI"), - getDescriptor("profile.introduction", "소개"), - getDescriptor("profile.activityArea", "활동 지역"), - getDescriptor("profile.techStacks[].value", "기술 스택"), - getDescriptor("profile.education.school", "학교"), - getDescriptor("profile.education.major", "전공"), - getDescriptor("profile.hashtags[].value", "해시태그"), - getDescriptor("profile.completedProjectsCount", "완수한 프로젝트 수"), - getDescriptor("profile.interestsCount", "받은 관심 수"), - getDescriptor("profile.portfolios[].uri", "포트폴리오 URI"), - getDescriptor("profile.portfolios[].description", "포트폴리오 설명") - ) + requestHeaders(authorizationHeaderDescriptor()), + pathParameters(parameterWithName("peopleId").description("피플 ID")), + responseFields(DetailPeopleResponseDescription.description()) ) ); } } - - @DisplayName("피플은 피플 정보를 등록할 수 있다.") - @Nested - class CreatePeople { - private final CreatePeopleRequest request = createPeopleRequest(); - - private ResultActions perform() throws Exception { - return mockMvc.perform(post("/people") - .header("Authorization", "Bearer ${ACCESS_TOKEN}") - .content(objectMapper.writeValueAsString(request)) - .contentType(APPLICATION_JSON)) - .andExpect(status().isCreated()); - } - - @WithCustomMockUser(memberType = ROLE_PEOPLE) - @Test - public void createPeople(PrincipalDetails principalDetails) throws Exception { - Member member = principalDetails.getMember(); - People people = Mockito.spy(PeopleFixture.createPeople(member)); - given(people.getPeopleId()).willReturn(1L); - given(peopleService.create(member.getMemberId(), request)).willReturn(people); - - perform() - .andDo(restDocs.document( - requestHeaders( - authorizationHeaderDescriptor() - ), - requestFields( - getDescriptor("nickname", "닉네임", CreatePeopleRequest.class), - getDescriptor("email", "이메일(기본값은 회원 가입 시 기입한 이메일)", CreatePeopleRequest.class), - getDescriptor("phoneNumber", "전화번호", CreatePeopleRequest.class), - getDescriptor("peopleType", "피플 유형", CreatePeopleRequest.class) - .attributes(key("format").value("TEAM, INDIVIDUAL")), - getDescriptor("profileImageUri", "프로필 이미지 URI", CreatePeopleRequest.class) - .attributes(key("format").value("/images/{memberId}/profile/{fileName}")) - ), - responseHeaders( - headerWithName("Location").description("생성된 피플 정보 URI") - ), - responseFields( - getDescriptor("peopleId", "피플 ID") - ) - ) - ) - .andDo(print()); - } - - @WithCustomMockUser(memberType = ROLE_CLIENT) - @Test - public void createPeople_WhenMemberTypeIsClient_ShouldFail() { - assertThatThrownBy(() -> perform() - .andExpect(status().isForbidden()) - .andDo(print())).hasCauseInstanceOf(AccessDeniedException.class); - } - } } \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/PeopleLikeControllerTest.java b/src/test/java/es/princip/getp/domain/people/controller/PeopleLikeControllerTest.java index 24244822..0ff7c34c 100644 --- a/src/test/java/es/princip/getp/domain/people/controller/PeopleLikeControllerTest.java +++ b/src/test/java/es/princip/getp/domain/people/controller/PeopleLikeControllerTest.java @@ -4,37 +4,26 @@ import es.princip.getp.domain.people.exception.PeopleErrorCode; import es.princip.getp.domain.people.exception.PeopleLikeErrorCode; import es.princip.getp.domain.people.service.PeopleLikeService; -import es.princip.getp.global.config.SecurityConfig; -import es.princip.getp.global.config.SecurityTestConfig; import es.princip.getp.global.exception.BusinessLogicException; -import es.princip.getp.global.mock.PrincipalDetailsParameterResolver; import es.princip.getp.global.mock.WithCustomMockUser; -import lombok.RequiredArgsConstructor; +import es.princip.getp.global.support.AbstractControllerTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.Import; -import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; +import static es.princip.getp.domain.member.domain.enums.MemberType.ROLE_CLIENT; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.willDoNothing; import static org.mockito.BDDMockito.willThrow; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@RequiredArgsConstructor -@WebMvcTest(PeopleLikeController.class) -@Import({SecurityConfig.class, SecurityTestConfig.class}) -@ActiveProfiles("test") -@ExtendWith(PrincipalDetailsParameterResolver.class) -public class PeopleLikeControllerTest { +@WebMvcTest({PeopleLikeController.class, PeopleErrorCodeController.class}) +public class PeopleLikeControllerTest extends AbstractControllerTest { @Autowired private MockMvc mockMvc; @@ -48,25 +37,23 @@ class Like { private final Long peopleId = 1L; @DisplayName("의뢰자는 피플에게 좋아요를 누를 수 있다.") - @WithCustomMockUser(memberType = MemberType.ROLE_CLIENT) + @WithCustomMockUser(memberType = ROLE_CLIENT) @Test void like() throws Exception { willDoNothing().given(peopleLikeService).like(any(), eq(peopleId)); - mockMvc.perform(post("/people/{peopleId}/likes", peopleId) - .contentType(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/people/{peopleId}/likes", peopleId)) .andExpect(status().isCreated()); } @DisplayName("의뢰자는 이미 좋아요를 누른 피플에게 다시 좋아요를 누를 수 없다.") - @WithCustomMockUser(memberType = MemberType.ROLE_CLIENT) + @WithCustomMockUser(memberType = ROLE_CLIENT) @Test void like_WhenPeopleIsAlreadyLiked_ShouldBeFailed() throws Exception { willThrow(new BusinessLogicException(PeopleLikeErrorCode.ALREADY_LIKED)) .given(peopleLikeService).like(any(), eq(peopleId)); - mockMvc.perform(post("/people/{peopleId}/likes", peopleId) - .contentType(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/people/{peopleId}/likes", peopleId)) .andExpect(status().isConflict()); } @@ -74,20 +61,18 @@ void like_WhenPeopleIsAlreadyLiked_ShouldBeFailed() throws Exception { @WithCustomMockUser(memberType = MemberType.ROLE_PEOPLE) @Test void like_WhenMemberTypeIsPeople_ShouldBeFailed() throws Exception { - mockMvc.perform(post("/people/{peopleId}/likes", peopleId) - .contentType(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/people/{peopleId}/likes", peopleId)) .andExpect(status().isForbidden()); } @DisplayName("의뢰자는 존재하지 않는 피플에게 좋아요를 누를 수 없다.") - @WithCustomMockUser(memberType = MemberType.ROLE_CLIENT) + @WithCustomMockUser(memberType = ROLE_CLIENT) @Test void like_WhenPeopleIsNotFound_ShouldBeFailed() throws Exception { willThrow(new BusinessLogicException(PeopleErrorCode.PEOPLE_NOT_FOUND)) .given(peopleLikeService).like(any(), eq(peopleId)); - mockMvc.perform(post("/people/{peopleId}/likes", peopleId) - .contentType(MediaType.APPLICATION_JSON)) + mockMvc.perform(post("/people/{peopleId}/likes", peopleId)) .andExpect(status().isNotFound()); } } diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/request/CreatePeopleProfileRequestDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/request/CreatePeopleProfileRequestDescription.java new file mode 100644 index 00000000..db2f1f73 --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/request/CreatePeopleProfileRequestDescription.java @@ -0,0 +1,22 @@ +package es.princip.getp.domain.people.controller.description.request; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; + +public class CreatePeopleProfileRequestDescription { + + public static FieldDescriptor[] description() { + final Class clazz = CreatePeopleProfileRequestDescription.class; + return new FieldDescriptor[] { + getDescriptor("education.school", "학력", clazz), + getDescriptor("education.major", "전공", clazz), + getDescriptor("activityArea", "활동 지역", clazz), + getDescriptor("introduction", "소개", clazz), + getDescriptor("techStacks[].value", "기술 스택",clazz), + getDescriptor("portfolios[].uri", "포트폴리오 URI", clazz), + getDescriptor("portfolios[].description", "포트폴리오 설명", clazz), + getDescriptor("hashtags[].value", "해시태그", clazz) + }; + } +} diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/request/CreatePeopleRequestDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/request/CreatePeopleRequestDescription.java new file mode 100644 index 00000000..0f706270 --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/request/CreatePeopleRequestDescription.java @@ -0,0 +1,20 @@ +package es.princip.getp.domain.people.controller.description.request; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; +import static org.springframework.restdocs.snippet.Attributes.key; + +public class CreatePeopleRequestDescription { + + public static FieldDescriptor[] description() { + final Class clazz = CreatePeopleRequestDescription.class; + return new FieldDescriptor[] { + getDescriptor("nickname", "닉네임", clazz), + getDescriptor("email", "이메일(기본값은 회원 가입 시 기입한 이메일)", clazz), + getDescriptor("phoneNumber", "전화번호", clazz), + getDescriptor("peopleType", "피플 유형", clazz) + .attributes(key("format").value("TEAM, INDIVIDUAL")) + }; + } +} diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/request/UpdatePeopleProfileRequestDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/request/UpdatePeopleProfileRequestDescription.java new file mode 100644 index 00000000..7331d84d --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/request/UpdatePeopleProfileRequestDescription.java @@ -0,0 +1,22 @@ +package es.princip.getp.domain.people.controller.description.request; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; + +public class UpdatePeopleProfileRequestDescription { + + public static FieldDescriptor[] description() { + final Class clazz = UpdatePeopleProfileRequestDescription.class; + return new FieldDescriptor[] { + getDescriptor("education.school", "학력", clazz), + getDescriptor("education.major", "전공", clazz), + getDescriptor("activityArea", "활동 지역", clazz), + getDescriptor("introduction", "소개", clazz), + getDescriptor("techStacks[].value", "기술 스택", clazz), + getDescriptor("portfolios[].uri", "포트폴리오 URI", clazz), + getDescriptor("portfolios[].description", "포트폴리오 설명", clazz), + getDescriptor("hashtags[].value", "해시태그", clazz) + }; + } +} diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/request/UpdatePeopleRequestDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/request/UpdatePeopleRequestDescription.java new file mode 100644 index 00000000..cebbb4ca --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/request/UpdatePeopleRequestDescription.java @@ -0,0 +1,20 @@ +package es.princip.getp.domain.people.controller.description.request; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; +import static org.springframework.restdocs.snippet.Attributes.key; + +public class UpdatePeopleRequestDescription { + + public static FieldDescriptor[] description() { + final Class clazz = UpdatePeopleRequestDescription.class; + return new FieldDescriptor[] { + getDescriptor("nickname", "닉네임", clazz), + getDescriptor("email", "이메일(기본값은 회원 가입 시 기입한 이메일)", clazz), + getDescriptor("phoneNumber", "전화번호", clazz), + getDescriptor("peopleType", "피플 유형", clazz) + .attributes(key("format").value("TEAM, INDIVIDUAL")) + }; + } +} diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/response/CreatePeopleResponseDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/response/CreatePeopleResponseDescription.java new file mode 100644 index 00000000..45ce6196 --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/response/CreatePeopleResponseDescription.java @@ -0,0 +1,14 @@ +package es.princip.getp.domain.people.controller.description.response; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; + +public class CreatePeopleResponseDescription { + + public static FieldDescriptor[] description() { + return new FieldDescriptor[] { + getDescriptor("peopleId", "피플 ID") + }; + } +} \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/response/DetailPeopleProfileResponseDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/response/DetailPeopleProfileResponseDescription.java new file mode 100644 index 00000000..99791998 --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/response/DetailPeopleProfileResponseDescription.java @@ -0,0 +1,24 @@ +package es.princip.getp.domain.people.controller.description.response; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; + + +public class DetailPeopleProfileResponseDescription { + + public static FieldDescriptor[] description() { + return new FieldDescriptor[] { + getDescriptor("education.school", "학력"), + getDescriptor("education.major", "전공"), + getDescriptor("activityArea", "활동 지역"), + getDescriptor("introduction", "소개"), + getDescriptor("techStacks[].value", "기술 스택"), + getDescriptor("portfolios[].uri", "포트폴리오 URI"), + getDescriptor("portfolios[].description", "포트폴리오 설명"), + getDescriptor("hashtags[].value", "해시태그"), + getDescriptor("completedProjectsCount", "완료한 프로젝트 수"), + getDescriptor("interestsCount", "받은 관심 수") + }; + } +} \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/response/DetailPeopleResponseDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/response/DetailPeopleResponseDescription.java new file mode 100644 index 00000000..f576597b --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/response/DetailPeopleResponseDescription.java @@ -0,0 +1,30 @@ +package es.princip.getp.domain.people.controller.description.response; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; +import static org.springframework.restdocs.snippet.Attributes.key; + + +public class DetailPeopleResponseDescription { + + public static FieldDescriptor[] description() { + return new FieldDescriptor[] { + getDescriptor("peopleId", "피플 ID"), + getDescriptor("nickname", "닉네임"), + getDescriptor("peopleType", "피플 유형") + .attributes(key("format").value("TEAM, INDIVIDUAL")), + getDescriptor("profileImageUri", "프로필 이미지 URI"), + getDescriptor("profile.introduction", "소개"), + getDescriptor("profile.activityArea", "활동 지역"), + getDescriptor("profile.techStacks[].value", "기술 스택"), + getDescriptor("profile.education.school", "학교"), + getDescriptor("profile.education.major", "전공"), + getDescriptor("profile.hashtags[].value", "해시태그"), + getDescriptor("profile.completedProjectsCount", "완수한 프로젝트 수"), + getDescriptor("profile.interestsCount", "받은 관심 수"), + getDescriptor("profile.portfolios[].uri", "포트폴리오 URI"), + getDescriptor("profile.portfolios[].description", "포트폴리오 설명") + }; + } +} \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/response/PeopleResponseDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/response/PeopleResponseDescription.java new file mode 100644 index 00000000..48ea02de --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/response/PeopleResponseDescription.java @@ -0,0 +1,23 @@ +package es.princip.getp.domain.people.controller.description.response; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; +import static org.springframework.restdocs.snippet.Attributes.key; + +public class PeopleResponseDescription { + + public static FieldDescriptor[] description() { + return new FieldDescriptor[] { + getDescriptor("peopleId", "피플 ID"), + getDescriptor("nickname", "닉네임"), + getDescriptor("email", "이메일"), + getDescriptor("phoneNumber", "전화번호"), + getDescriptor("peopleType", "피플 유형") + .attributes(key("format").value("TEAM, INDIVIDUAL")), + getDescriptor("profileImageUri", "프로필 이미지 URI"), + getDescriptor("createdAt", "피플 정보 등록 일시"), + getDescriptor("updatedAt", "최근 피플 정보 수정 일시") + }; + } +} \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/controller/description/response/PublicDetailPeopleResponseDescription.java b/src/test/java/es/princip/getp/domain/people/controller/description/response/PublicDetailPeopleResponseDescription.java new file mode 100644 index 00000000..1740ce7f --- /dev/null +++ b/src/test/java/es/princip/getp/domain/people/controller/description/response/PublicDetailPeopleResponseDescription.java @@ -0,0 +1,23 @@ +package es.princip.getp.domain.people.controller.description.response; + +import org.springframework.restdocs.payload.FieldDescriptor; + +import static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; +import static org.springframework.restdocs.snippet.Attributes.key; + + +public class PublicDetailPeopleResponseDescription { + + public static FieldDescriptor[] description() { + return new FieldDescriptor[] { + getDescriptor("peopleId", "피플 ID"), + getDescriptor("nickname", "닉네임"), + getDescriptor("peopleType", "피플 유형") + .attributes(key("format").value("TEAM, INDIVIDUAL")), + getDescriptor("profileImageUri", "프로필 이미지 URI"), + getDescriptor("profile.hashtags[].value", "해시태그"), + getDescriptor("profile.completedProjectsCount", "완수한 프로젝트 수"), + getDescriptor("profile.interestsCount", "받은 관심 수") + }; + } +} \ No newline at end of file diff --git a/src/test/java/es/princip/getp/domain/people/fixture/PeopleFixture.java b/src/test/java/es/princip/getp/domain/people/fixture/PeopleFixture.java index bc8dce1f..91a4b6a4 100644 --- a/src/test/java/es/princip/getp/domain/people/fixture/PeopleFixture.java +++ b/src/test/java/es/princip/getp/domain/people/fixture/PeopleFixture.java @@ -21,25 +21,23 @@ public class PeopleFixture { public static String PHONE_NUMBER = "01012345678"; public static PeopleType PEOPLE_TYPE = PeopleType.INDIVIDUAL; public static String PROFILE_IMAGE_URI = "/images/1/profile/image.jpeg"; - public static String UPDATE = "updated_"; + private static String UPDATED = "updated_"; public static CreatePeopleRequest createPeopleRequest() { return new CreatePeopleRequest( NICKNAME, EMAIL, PHONE_NUMBER, - PEOPLE_TYPE, - PROFILE_IMAGE_URI + PEOPLE_TYPE ); } public static UpdatePeopleRequest updatePeopleRequest() { return new UpdatePeopleRequest( - UPDATE + NICKNAME, - UPDATE + EMAIL, + UPDATED + NICKNAME, + UPDATED + EMAIL, PHONE_NUMBER, - PEOPLE_TYPE, - PROFILE_IMAGE_URI + PEOPLE_TYPE ); } diff --git a/src/test/java/es/princip/getp/domain/people/fixture/PeopleProfileFixture.java b/src/test/java/es/princip/getp/domain/people/fixture/PeopleProfileFixture.java index c30a7df0..8d9e0a26 100644 --- a/src/test/java/es/princip/getp/domain/people/fixture/PeopleProfileFixture.java +++ b/src/test/java/es/princip/getp/domain/people/fixture/PeopleProfileFixture.java @@ -67,6 +67,30 @@ public static PeopleProfile createPeopleProfile(People people) { .build(); } + public static PeopleProfile createPeopleProfile(UpdatePeopleProfileRequest request, People people) { + return PeopleProfile.builder() + .introduction(request.introduction()) + .activityArea(request.activityArea()) + .education(request.education()) + .hashtags(request.hashtags()) + .techStacks(request.techStacks()) + .portfolios(request.portfolios()) + .people(people) + .build(); + } + + public static PeopleProfile createPeopleProfile(CreatePeopleProfileRequest request, People people) { + return PeopleProfile.builder() + .introduction(request.introduction()) + .activityArea(request.activityArea()) + .education(request.education()) + .hashtags(request.hashtags()) + .techStacks(request.techStacks()) + .portfolios(request.portfolios()) + .people(people) + .build(); + } + public static CardPeopleProfileResponse createCardPeopleProfileResponse() { return new CardPeopleProfileResponse( ACTIVITY_AREA, diff --git a/src/test/java/es/princip/getp/domain/people/service/PeopleServiceTest.java b/src/test/java/es/princip/getp/domain/people/service/PeopleServiceTest.java index 524a7999..a84f6f65 100644 --- a/src/test/java/es/princip/getp/domain/people/service/PeopleServiceTest.java +++ b/src/test/java/es/princip/getp/domain/people/service/PeopleServiceTest.java @@ -58,8 +58,7 @@ class Create { void setUp() { mockMember = Mockito.spy(createMember( request.nickname(), - request.phoneNumber(), - request.profileImageUri() + request.phoneNumber() )); given(mockMember.getMemberId()).willReturn(1L); } @@ -79,7 +78,6 @@ void create() { softly.assertThat(created.getEmail()).isEqualTo(request.email()); softly.assertThat(created.getPhoneNumber()).isEqualTo(mockMember.getPhoneNumber()); softly.assertThat(created.getPeopleType()).isEqualTo(request.peopleType()); - softly.assertThat(created.getProfileImageUri()).isEqualTo(request.profileImageUri()); }); } } @@ -165,7 +163,10 @@ class Update { @BeforeEach void setUp() { - mockMember = Mockito.spy(createMember()); + mockMember = Mockito.spy(createMember( + request.nickname(), + request.phoneNumber() + )); given(mockMember.getMemberId()).willReturn(1L); mockPeople = createPeople(mockMember); } @@ -189,7 +190,6 @@ void update() { softly.assertThat(updated.getEmail()).isEqualTo(request.email()); softly.assertThat(updated.getPhoneNumber()).isEqualTo(request.phoneNumber()); softly.assertThat(updated.getPeopleType()).isEqualTo(request.peopleType()); - softly.assertThat(updated.getProfileImageUri()).isEqualTo(request.profileImageUri()); }); } } diff --git a/src/test/java/es/princip/getp/global/support/AbstractControllerTest.java b/src/test/java/es/princip/getp/global/support/AbstractControllerTest.java index 77c86e30..a3db17d3 100644 --- a/src/test/java/es/princip/getp/global/support/AbstractControllerTest.java +++ b/src/test/java/es/princip/getp/global/support/AbstractControllerTest.java @@ -18,6 +18,7 @@ import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; @@ -26,6 +27,7 @@ import org.springframework.web.filter.CharacterEncodingFilter; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @ActiveProfiles("test") @@ -36,27 +38,27 @@ public abstract class AbstractControllerTest { @Value("${server.servlet.context-path}") protected String contextPath; - protected MockHttpServletRequestBuilder get(String uri, Long id) { - return RestDocumentationRequestBuilders.get(contextPath + uri, id) + protected MockHttpServletRequestBuilder get(String uri, Object... values) { + return RestDocumentationRequestBuilders.get(contextPath + uri, values) .contextPath(contextPath) .contentType(MediaType.APPLICATION_JSON); - }; + } - protected MockHttpServletRequestBuilder get(String uri) { - return RestDocumentationRequestBuilders.get(contextPath + uri) + protected MockHttpServletRequestBuilder post(String uri, Object... values) { + return RestDocumentationRequestBuilders.post(contextPath + uri, values) .contextPath(contextPath) .contentType(MediaType.APPLICATION_JSON); - }; + } - protected MockHttpServletRequestBuilder post(String uri) { - return RestDocumentationRequestBuilders.post(contextPath + uri) + protected MockHttpServletRequestBuilder put(String uri, Object... values) { + return RestDocumentationRequestBuilders.put(contextPath + uri, values) .contextPath(contextPath) .contentType(MediaType.APPLICATION_JSON); - }; + } - protected ResultMatcher errorCode(ErrorCode errorCode) { + protected static ResultMatcher errorCode(ErrorCode errorCode) { return status().is(errorCode.status().value()); - }; + } @Autowired protected RestDocumentationResultHandler restDocs; @@ -80,4 +82,10 @@ void setUp(final WebApplicationContext context, final RestDocumentationContextPr .addFilters(new CharacterEncodingFilter("UTF-8", true)) .build(); } + + protected static void expectForbidden(ResultActions result) throws Exception { + result + .andExpect(status().isForbidden()) + .andDo(print()); + } }