Skip to content

Commit

Permalink
Feat: 본인의 정보를 조회하는 api 구현 (#171)
Browse files Browse the repository at this point in the history
* #169 - feat: 내 정보 조회 기능 구현

* #169 - test: 내 정보 조회 기능 테스트 구현
  • Loading branch information
GGHDMS authored Feb 19, 2024
1 parent e7c36be commit f5c8f02
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class SecurityConfig {
"/posts/me",
"/reviews/likes",
"/reviews/me",
"/books/likes/**"
"/books/likes/**",
"/members/me"
};

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ public ResponseEntity<MemberRecommendListResponse> getNewMembers() {
return ResponseEntity.ok(memberService.getNewMembers());
}

@GetMapping("/me")
public ResponseEntity<MemberResponse> getMyInfo(
@AuthenticationPrincipal AuthDetails details
) {
return ResponseEntity.ok(MemberResponse.from(memberService.getMemberInfo(details.getId(), details.getId())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,29 @@ void givenMembers_whenGettingNewMembers_thenReturnNewMembers() throws Exception
;
}

@Test
@WithCustomMockUser
@DisplayName("본인의 정보를 조회한다.")
void givenLogin_whenGettingMyInfo_thenGetMyInfo() throws Exception{
//given

//when & then
mockMvc.perform(get("/members/me")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
;
}

@Test
@DisplayName("로그인 없이 본인의 정보를 조회하면 에러를 반환한다.")
void givenNonLogin_whenGettingMyInfo_thenGetMyInfo() throws Exception{
//given

//when & then
mockMvc.perform(get("/members/me")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isUnauthorized())
;
}

}

0 comments on commit f5c8f02

Please sign in to comment.