-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: 인증 코드 만료 시간 환경 변수명을 VERIFICATION_CODE_EXPIRE_TIME으로 변경 * feat: 내 사용자 정보 조회 기능 구현 * test: 내 사용자 정보 조회 기능 테스트 작성 * chore: static 파일 gitignore에 추가
- Loading branch information
Showing
20 changed files
with
210 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,4 +100,6 @@ Temporary Items | |
local.sh | ||
|
||
# JUnit settings | ||
.run/ | ||
.run/ | ||
|
||
src/main/resources/static/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
operation::/get-my-member/get-my-member[snippets="http-request,http-response,response-fields-data"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
src/main/java/es/princip/getp/domain/base/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
package es.princip.getp.domain.base; | ||
|
||
import java.time.LocalDateTime; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@EntityListeners(AuditingEntityListener.class) | ||
@MappedSuperclass | ||
@Getter | ||
public abstract class BaseTimeEntity { | ||
@CreatedDate | ||
@Column(columnDefinition = "TIMESTAMP") | ||
private LocalDateTime createdAt; | ||
protected LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(columnDefinition = "TIMESTAMP") | ||
private LocalDateTime updateAt; | ||
protected LocalDateTime updatedAt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/es/princip/getp/domain/member/controller/MemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package es.princip.getp.domain.member.controller; | ||
|
||
import es.princip.getp.domain.client.service.ClientService; | ||
import es.princip.getp.domain.member.domain.entity.Member; | ||
import es.princip.getp.domain.member.domain.enums.MemberType; | ||
import es.princip.getp.domain.member.dto.response.MemberResponse; | ||
import es.princip.getp.domain.people.service.PeopleService; | ||
import es.princip.getp.global.security.details.PrincipalDetails; | ||
import es.princip.getp.global.util.ApiResponse; | ||
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.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static es.princip.getp.global.util.ApiResponse.ApiSuccessResult; | ||
|
||
@RestController | ||
@RequestMapping("/member") | ||
@RequiredArgsConstructor | ||
public class MemberController { | ||
|
||
private final PeopleService peopleService; | ||
private final ClientService clientService; | ||
|
||
@GetMapping("/me") | ||
@PreAuthorize("isAuthenticated()") | ||
public ResponseEntity<ApiSuccessResult<MemberResponse>> getMyMember( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails | ||
) { | ||
Member member = principalDetails.getMember(); | ||
Long memberId = member.getMemberId(); | ||
String email = member.getEmail(); | ||
MemberType memberType = member.getMemberType(); | ||
String nickname = memberType.isClient() ? clientService.getByMemberId(memberId).getNickname() : | ||
memberType.isPeople() ? peopleService.getByMemberId(memberId).getNickname() : | ||
email.substring(0, email.indexOf('@')); | ||
return ResponseEntity.ok().body(ApiResponse.success(HttpStatus.OK, MemberResponse.of(member, nickname))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 23 additions & 2 deletions
25
src/main/java/es/princip/getp/domain/member/dto/response/MemberResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,43 @@ | ||
package es.princip.getp.domain.member.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import es.princip.getp.domain.member.domain.entity.Member; | ||
import es.princip.getp.domain.member.domain.enums.MemberType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record MemberResponse( | ||
Long memberId, | ||
String email, | ||
String nickname, | ||
MemberType memberType, | ||
LocalDateTime createdAt, | ||
LocalDateTime updatedAt) { | ||
LocalDateTime updatedAt | ||
) { | ||
|
||
public static MemberResponse from(final Member member) { | ||
return new MemberResponse( | ||
member.getMemberId(), | ||
member.getEmail(), | ||
null, | ||
member.getMemberType(), | ||
member.getCreatedAt(), | ||
member.getUpdatedAt() | ||
); | ||
} | ||
|
||
public static MemberResponse of( | ||
final Member member, | ||
final String nickname | ||
) { | ||
return new MemberResponse( | ||
member.getMemberId(), | ||
member.getEmail(), | ||
nickname, | ||
member.getMemberType(), | ||
member.getCreatedAt(), | ||
member.getUpdateAt()); | ||
member.getUpdatedAt() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/test/java/es/princip/getp/domain/member/controller/MemberControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package es.princip.getp.domain.member.controller; | ||
|
||
import es.princip.getp.domain.client.service.ClientService; | ||
import es.princip.getp.domain.member.domain.entity.Member; | ||
import es.princip.getp.domain.member.domain.enums.MemberType; | ||
import es.princip.getp.domain.people.domain.entity.People; | ||
import es.princip.getp.domain.people.service.PeopleService; | ||
import es.princip.getp.fixture.PeopleFixture; | ||
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 static es.princip.getp.global.support.FieldDescriptorHelper.getDescriptor; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.beneathPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; | ||
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; | ||
|
||
@WebMvcTest(MemberController.class) | ||
class MemberControllerTest extends AbstractControllerTest { | ||
|
||
@MockBean | ||
private PeopleService peopleService; | ||
|
||
|
||
|
||
@MockBean | ||
private ClientService clientService; | ||
|
||
@Nested | ||
@DisplayName("사용자는") | ||
class GetMyMember { | ||
|
||
@DisplayName("내 회원 정보를 조회할 수 있다.") | ||
@WithCustomMockUser(memberType = MemberType.ROLE_PEOPLE) | ||
@Test | ||
void getMyMember(PrincipalDetails principalDetails) throws Exception { | ||
Member member = principalDetails.getMember(); | ||
Long memberId = member.getMemberId(); | ||
People people = PeopleFixture.createPeople(member); | ||
given(peopleService.getByMemberId(memberId)).willReturn(people); | ||
|
||
mockMvc.perform(get("/member/me") | ||
.header("Authorization", "Bearer ${ACCESS_TOKEN}") | ||
) | ||
.andExpect(status().isOk()) | ||
.andDo( | ||
restDocs.document( | ||
requestHeaders( | ||
headerWithName("Authorization").description("Bearer ${ACCESS_TOKEN}") | ||
), | ||
responseFields(beneathPath("data").withSubsectionId("data")) | ||
.and( | ||
getDescriptor("memberId", "회원 ID"), | ||
getDescriptor("email", "이메일"), | ||
getDescriptor("nickname", "닉네임"), | ||
getDescriptor("memberType", "회원 유형"), | ||
getDescriptor("createdAt", "회원 가입일") | ||
.attributes(key("format").value("yyyy-MM-dd'T'HH:mm:ss")), | ||
getDescriptor("updatedAt", "회원 정보 수정일") | ||
.attributes(key("format").value("yyyy-MM-dd'T'HH:mm:ss")) | ||
) | ||
) | ||
) | ||
.andDo(print()); | ||
} | ||
} | ||
} |
Oops, something went wrong.