Merge branch 'master' into feign_클라이언트_연동
This commit is contained in:
@@ -65,6 +65,8 @@
|
||||
domain-httpRequestCode-etc
|
||||
|
||||
== 유저
|
||||
=== 로그인 된 회원 조회
|
||||
operation::customer-get-mypage[snippets='curl-request,http-request,http-response,request-headers,response-fields']
|
||||
=== 회원 조회
|
||||
operation::customer-get[snippets='curl-request,http-request,http-response,path-parameters,response-fields']
|
||||
=== 회원 조회 (존재하지 않는 회원)
|
||||
|
||||
@@ -16,6 +16,7 @@ public abstract class UserDto {
|
||||
// == 생성 메소드 == //
|
||||
public UserDto(Customer customer) {
|
||||
this.id = customer.getId();
|
||||
this.email = customer.getEmail();
|
||||
this.password = customer.getPassword();
|
||||
this.name = customer.getName();
|
||||
this.phoneNumber = customer.getPhoneNumber();
|
||||
|
||||
@@ -26,6 +26,33 @@ public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@GetMapping("/customer/")
|
||||
public ResponseEntity getCustomerByToken(@Valid @RequestHeader(value = "user-id") String userId ) {
|
||||
|
||||
CustomerDto customerDto = userService.findCustomerByUserId(Long.parseLong(userId));
|
||||
|
||||
GetCustomerByTokenResponse getCustomerByTokenResponse = new GetCustomerByTokenResponse(customerDto);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(Result.createSuccessResult(getCustomerByTokenResponse));
|
||||
}
|
||||
|
||||
@Data @NoArgsConstructor @AllArgsConstructor
|
||||
static class GetCustomerByTokenResponse {
|
||||
private Long userId;
|
||||
private String email;
|
||||
private String userName;
|
||||
private String phoneNumber;
|
||||
|
||||
public GetCustomerByTokenResponse(CustomerDto customerDto) {
|
||||
this.userId = customerDto.getId();
|
||||
this.email = customerDto.getEmail();
|
||||
this.userName = customerDto.getName();
|
||||
this.phoneNumber = customerDto.getPhoneNumber();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/customer/{userId}")
|
||||
public ResponseEntity getCustomer(@PathVariable("userId") Long userId) {
|
||||
|
||||
|
||||
@@ -53,5 +53,4 @@ token:
|
||||
refresh-expired-time: 604800000
|
||||
secret: $2a$10$q42lY7Y18xqrFt1qbODZIO4OMTeOxnrCe7tF3n9bazJinVE7VH5Pi
|
||||
refresh-token-name: refresh-token
|
||||
access-token-name: access-token
|
||||
fegin: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJmZWlnbiIsImV4cCI6MTE2NDY5NzY4NzAsImlhdCI6MTY0Njk3Njg3MH0.5x4Nx7oMnpF0_kZpbZsiB1u9eEbQ4IKIhJlEsa3D22cjZjvTHKz57GCz0sgXb_olhSNIVv9xF41A29-XYiFeBQ
|
||||
access-token-name: access-token
|
||||
@@ -21,6 +21,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.headers.HeaderDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
@@ -31,6 +32,8 @@ import java.util.stream.Collectors;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
|
||||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
|
||||
@@ -62,6 +65,53 @@ class UserControllerTest {
|
||||
@SpyBean
|
||||
CookieProvider cookieProvider;
|
||||
|
||||
@Test
|
||||
@DisplayName("로그인된 회원 조회")
|
||||
void getCustomerByToken() throws Exception {
|
||||
// GIVEN
|
||||
long userId = 1L;
|
||||
|
||||
CustomerDto willReturnDto = CustomerDto.builder()
|
||||
.id(1L)
|
||||
.name("이름")
|
||||
.password("password!@#")
|
||||
.email("hoonasdasd@naver.com")
|
||||
.phoneNumber("010-1234-5678")
|
||||
.build();
|
||||
|
||||
given(userService.findCustomerByUserId(userId))
|
||||
.willReturn(willReturnDto);
|
||||
|
||||
// WHEN
|
||||
ResultActions actions = mockMvc.perform(get("/customer/")
|
||||
.header("user-id",userId));
|
||||
|
||||
// THEN
|
||||
actions.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("code").value(Code.SUCCESS.name()))
|
||||
.andExpect(jsonPath("message").value(""))
|
||||
.andExpect(jsonPath("data.userId").value(1))
|
||||
.andExpect(jsonPath("data.email").value("hoonasdasd@naver.com"))
|
||||
.andExpect(jsonPath("data.userName").value("이름"))
|
||||
.andExpect(jsonPath("data.phoneNumber").value("010-1234-5678"))
|
||||
.andDo(print())
|
||||
.andDo(document("customer-get-mypage",
|
||||
requestHeaders(
|
||||
headerWithName("user-id").description("로그인한 유저 id")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data.userId").description("회원 고유번호"),
|
||||
fieldWithPath("data.userName").description("회원 이름"),
|
||||
fieldWithPath("data.email").description("회원 이메일"),
|
||||
fieldWithPath("data.phoneNumber").description("회원 휴대폰 번호")
|
||||
))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("회원 조회")
|
||||
void getCustomer() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user