Skip to content

Commit

Permalink
Merge branch 'develop' into feature/member-entity-rft
Browse files Browse the repository at this point in the history
  • Loading branch information
scv1702 authored Jun 1, 2024
2 parents 46b9b1f + 88b1011 commit 2cae2ed
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 63 deletions.
2 changes: 2 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ include::{docdir}/member/upload-profile-image.adoc[]
=== 피플 정보 등록
include::{docdir}/people/create-people.adoc[]

=== 피플 상세 조회
include::{docdir}/people/get-people.adoc[]
17 changes: 17 additions & 0 deletions src/docs/asciidoc/people/get-people.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
==== HTTP request
include::{snippets}/get-people/get-people_-when-user-logined/http-request.adoc[]

==== Request headers
include::{snippets}/get-people/get-people_-when-user-logined/request-headers.adoc[]

==== Path parameters
include::{snippets}/get-people/get-people_-when-user-logined/path-parameters.adoc[]

==== HTTP response when user logined
include::{snippets}/get-people/get-people_-when-user-logined/http-response.adoc[]

==== HTTP response when user not logined
include::{snippets}/get-people/get-people_-when-user-not-logined/http-response.adoc[]

==== Response fields
include::{snippets}/get-people/get-people_-when-user-not-logined/response-fields-data.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import es.princip.getp.domain.people.dto.response.people.PublicDetailPeopleResponse;
import es.princip.getp.domain.people.service.PeopleService;
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;
Expand All @@ -18,9 +19,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
Expand All @@ -29,7 +28,7 @@
@RestController
@RequestMapping("/people")
@RequiredArgsConstructor
public class PeopleController {
public class PeopleController extends ControllerSupport {

private final PeopleService peopleService;

Expand Down Expand Up @@ -58,15 +57,12 @@ public ResponseEntity<ApiSuccessResult<CreatePeopleResponse>> createPeople(
*/
@GetMapping("/{peopleId}")
public ResponseEntity<ApiSuccessResult<?>> getPeople(@PathVariable Long peopleId) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication.isAuthenticated()) {
DetailPeopleResponse response = DetailPeopleResponse.from(peopleService.getByPeopleId(peopleId), null);
return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, response));
}
else{
PublicDetailPeopleResponse response = PublicDetailPeopleResponse.from(peopleService.getByPeopleId(peopleId), null);
if (isAuthenticated()) {
DetailPeopleResponse response = DetailPeopleResponse.from(peopleService.getByPeopleId(peopleId));
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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class People extends BaseTimeEntity {
private Member member;

@OneToOne(mappedBy = "people")
private PeopleProfile peopleProfile;
private PeopleProfile profile;

@Builder
public People(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import es.princip.getp.domain.people.domain.entity.People;
import es.princip.getp.domain.people.domain.enums.PeopleType;
import es.princip.getp.domain.people.dto.response.peopleProfile.DetailPeopleProfileResponse;
import lombok.Builder;

@Builder
public record DetailPeopleResponse(
Long peopleId,
String nickname,
Expand All @@ -12,13 +14,13 @@ public record DetailPeopleResponse(
DetailPeopleProfileResponse profile
) {

public static DetailPeopleResponse from(People people, DetailPeopleProfileResponse profile) {
return new DetailPeopleResponse(
people.getPeopleId(),
people.getNickname(),
people.getPeopleType(),
people.getProfileImageUri(),
profile
);
public static DetailPeopleResponse from(People people) {
return DetailPeopleResponse.builder()
.peopleId(people.getPeopleId())
.nickname(people.getNickname())
.peopleType(people.getPeopleType())
.profileImageUri(people.getProfileImageUri())
.profile(DetailPeopleProfileResponse.from(people.getProfile()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
import es.princip.getp.domain.people.domain.entity.People;
import es.princip.getp.domain.people.domain.enums.PeopleType;
import es.princip.getp.domain.people.dto.response.peopleProfile.PublicDetailPeopleProfileResponse;
import jakarta.validation.Valid;
import lombok.Builder;

@Builder
public record PublicDetailPeopleResponse(
Long peopleId,
String nickname,
PeopleType peopleType,
@Valid PublicDetailPeopleProfileResponse profile
String profileImageUri,
PublicDetailPeopleProfileResponse profile
) {

public static PublicDetailPeopleResponse from(
People people,
PublicDetailPeopleProfileResponse profile
) {
return new PublicDetailPeopleResponse(
people.getPeopleId(),
people.getNickname(),
people.getPeopleType(),
profile
);
public static PublicDetailPeopleResponse from(People people) {
return PublicDetailPeopleResponse.builder()
.peopleId(people.getPeopleId())
.nickname(people.getNickname())
.peopleType(people.getPeopleType())
.profileImageUri(people.getProfileImageUri())
.profile(PublicDetailPeopleProfileResponse.from(people.getProfile()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
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 lombok.Builder;

import java.util.List;

@Builder
public record DetailPeopleProfileResponse(
String introduction,
String activityArea,
Expand All @@ -19,16 +22,15 @@ public record DetailPeopleProfileResponse(
) {

public static DetailPeopleProfileResponse from(final PeopleProfile peopleProfile) {
return new DetailPeopleProfileResponse(
peopleProfile.getIntroduction(),
peopleProfile.getActivityArea(),
peopleProfile.getTechStacks(),
peopleProfile.getEducation(),
peopleProfile.getHashtags(),
//TODO: 계산 프로퍼티 구현
0,
0,
peopleProfile.getPortfolios()
);
return DetailPeopleProfileResponse.builder()
.introduction(peopleProfile.getIntroduction())
.activityArea(peopleProfile.getActivityArea())
.techStacks(peopleProfile.getTechStacks())
.education(peopleProfile.getEducation())
.hashtags(peopleProfile.getHashtags())
.completedProjectsCount(0) //TODO: 완수한 프로젝트 수 계산
.interestsCount(0) //TODO: 받은 관심 수 계산
.portfolios(peopleProfile.getPortfolios())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import es.princip.getp.domain.people.domain.entity.PeopleProfile;
import es.princip.getp.global.domain.values.Hashtag;
import lombok.Builder;

import java.util.List;

@Builder
public record PublicDetailPeopleProfileResponse(
List<Hashtag> hashtags,
Integer completedProjectsCount,
Integer interestsCount
) {

public static PublicDetailPeopleProfileResponse from(final PeopleProfile peopleProfile) {
return new PublicDetailPeopleProfileResponse(
peopleProfile.getHashtags(),
//TODO: 계산 프로퍼티 구현
0,
0
);
return PublicDetailPeopleProfileResponse.builder()
.hashtags(peopleProfile.getHashtags())
.completedProjectsCount(0) //TODO: 완수한 프로젝트 수 계산
.interestsCount(0) //TODO: 받은 관심 수 계산
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public List<CardPeopleResponse> getCardPeopleContent_cursor(Long lastPeopleId, i
peopleProfile.activityArea
)
.from(people)
.join(people.peopleProfile, peopleProfile)
.join(people.profile, peopleProfile)
.where(lastPeopleId == null ? null : people.peopleId.lt(lastPeopleId))
.orderBy(people.peopleId.desc())
.limit(size)
Expand All @@ -97,7 +97,7 @@ private List<CardPeopleResponse> getCardPeopleContent(Pageable pageable) {
peopleProfile.activityArea
)
.from(people)
.join(people.peopleProfile, peopleProfile)
.join(people.profile, peopleProfile)
.orderBy(getPeopleOrderSpecifiers(pageable.getSort()))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package es.princip.getp.global.support;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public abstract class ControllerSupport {

public boolean isAuthenticated() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication != null && authentication.isAuthenticated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -20,6 +21,8 @@
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.createPeopleRequest;
import static es.princip.getp.domain.people.fixture.PeopleProfileFixture.createPeopleProfile;
import static es.princip.getp.fixture.MemberFixture.createMember;
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.PayloadDocumentationHelper.responseFields;
Expand All @@ -28,6 +31,8 @@
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.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.snippet.Attributes.key;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand All @@ -38,6 +43,89 @@ class PeopleControllerTest extends AbstractControllerTest {
@MockBean
private PeopleService peopleService;

@DisplayName("사용자는 피플의 상세 정보를 조회할 수 있다.")
@Nested
class GetPeople {
private final Long peopleId = 2L;

private ResultActions perform() throws Exception {
return mockMvc.perform(get("/people/{peopleId}", peopleId)
.contentType(APPLICATION_JSON));
}

private ResultActions performWithAcessToken() throws Exception {
return mockMvc.perform(get("/people/{peopleId}", peopleId)
.header("Authorization", "Bearer ${ACCESS_TOKEN}")
.contentType(APPLICATION_JSON));
}

@BeforeEach
void setUp() {
Member member = createMember("test2@gmail.com");
People people = Mockito.spy(PeopleFixture.createPeople(member));
given(people.getPeopleId()).willReturn(2L);
given(people.getProfile()).willReturn(createPeopleProfile(people));
given(peopleService.getByPeopleId(peopleId)).willReturn(people);
}

@Test
public void getPeople_WhenUserNotLogined() throws Exception {
perform()
.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", "받은 관심 수")
)
)
);
}

@Test
@WithCustomMockUser(memberType = ROLE_PEOPLE)
public void getPeople_WhenUserLogined() throws Exception {
performWithAcessToken()
.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", "포트폴리오 설명")
)
)
);
}
}

@DisplayName("피플은 피플 정보를 등록할 수 있다.")
@Nested
class CreatePeople {
Expand Down Expand Up @@ -68,7 +156,7 @@ public void createPeople(PrincipalDetails principalDetails) throws Exception {
getDescriptor("nickname", "닉네임", CreatePeopleRequest.class),
getDescriptor("email", "이메일(기본값은 회원 가입 시 기입한 이메일)", CreatePeopleRequest.class),
getDescriptor("phoneNumber", "전화번호", CreatePeopleRequest.class),
getDescriptor("peopleType", "피플 타입", 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}"))
Expand Down
Loading

0 comments on commit 2cae2ed

Please sign in to comment.