Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user의 정보 반환하는 api 작업 완료 #41

Merged
merged 7 commits into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/docs/asciidoc/api-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ The index provides the entry point into the service.

로그인, 화원가입과 관련된 API 입니다



=== `GET` /user

로그인 된 유저의 정보를 가져옵니다 password 정보는 제외됩니다

operation::user/get_my_information[snippets='http-request,request-headers,http-response,http-response,response-fields,response-fields-data']

=== `GET` /user/login

로그인 상태를 확인합니다
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class User {
private Membership membership;

@Field("signup_favorite")
private List<String> signupFavorite;
private List<String> signupFavorite = new ArrayList<>();

@Field("my_collection")
private List<String> myCollection;
private List<String> myCollection = new ArrayList<>();

public List<String> getRoleList(){
if(this.roles.length() > 0){
Expand All @@ -72,7 +72,7 @@ public User(String id, String nickname, String username, String firebaseUid, Str
this.performerGrade = performerGrade;
this.membership = membership;
this.signupFavorite = signupFavorite;
this.myCollection = new ArrayList<>();
this.myCollection = myCollection;
}

public User(String id){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public ResponseEntity<Void> login(@AuthenticationPrincipal PrincipalDetails prin
return ResponseEntity.ok().build();
}

@GetMapping()
public ApiResponse<MyInformationResponse> getMyInformation(@AuthenticationPrincipal PrincipalDetails principalDetails){
MyInformationResponse myInformationResponse= new MyInformationResponse(principalDetails.getUser());
return ApiResponse.success(myInformationResponse, HttpStatus.OK.value());
}
@GetMapping("/nickname")
public ApiResponse<NicknameResponse> getNickname(@AuthenticationPrincipal PrincipalDetails principalDetails){
String userEmail = principalDetails.getUser().getEmail();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.chordplay.chordplayapiserver.domain.user.dto;

import com.chordplay.chordplayapiserver.domain.entity.User;
import com.chordplay.chordplayapiserver.domain.entity.item.*;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.List;

@Getter
@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
public class MyInformationResponse {
private String id;
private String nickname;

private String username;

private String firebaseUid;

private String roles;


private String email;
private Country country;
private Language language;
private Gender gender;

private PerformerGrade performerGrade;
private Membership membership;

private List<String> signupFavorite;

private List<String> myCollection;

public MyInformationResponse(User user){
this.id = user.getId();
this.nickname = user.getNickname();
this.username = user.getUsername();
this.firebaseUid = user.getFirebaseUid();
this.roles = user.getRoles();
this.email = user.getEmail();
this.country = user.getCountry();
this.language = user.getLanguage();
this.gender = user.getGender();
this.performerGrade = user.getPerformerGrade();
this.membership = user.getMembership();
this.signupFavorite = user.getSignupFavorite();
this.myCollection = user.getMyCollection();
}
}
219 changes: 218 additions & 1 deletion src/main/resources/static/docs/api-guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ <h1>CHORD PLAY API</h1>
<li><a href="#resources_index">Index</a></li>
<li><a href="#_user">USER</a>
<ul class="sectlevel2">
<li><a href="#_get_user"><code>GET</code> /user</a></li>
<li><a href="#_get_userlogin"><code>GET</code> /user/login</a></li>
<li><a href="#_get_usernickname"><code>GET</code> /user/nickname</a></li>
<li><a href="#_post_usercheck_duplication"><code>POST</code> /user/check-duplication</a></li>
Expand Down Expand Up @@ -649,6 +650,222 @@ <h2 id="_user"><a class="link" href="#_user">USER</a></h2>
<p>로그인, 화원가입과 관련된 API 입니다</p>
</div>
<div class="sect2">
<h3 id="_get_user"><a class="link" href="#_get_user"><code>GET</code> /user</a></h3>
<div class="paragraph">
<p>로그인 된 유저의 정보를 가져옵니다 password 정보는 제외됩니다</p>
</div>
<div class="sect3">
<h4 id="_get_user_http_request"><a class="link" href="#_get_user_http_request">HTTP request</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code data-lang="http" class="language-http hljs">GET /user HTTP/1.1
Accept: application/json
Authorization: Bearer {token}
Host: api.baetles.site</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_get_user_request_headers"><a class="link" href="#_get_user_request_headers">Request headers</a></h4>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Authorization</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Bearer {token}</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="_get_user_http_response"><a class="link" href="#_get_user_http_response">Example response</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code data-lang="http" class="language-http hljs">HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 485

{
"code" : "200",
"message" : "success",
"data" : {
"id" : "6313b2381f8fa3bb122eaa78",
"nickname" : "test",
"username" : "최현준",
"firebase_uid" : "firebase_uid",
"roles" : "ROLE_USER",
"email" : "[email protected]",
"country" : "KR",
"language" : "kr",
"gender" : "MALE",
"performer_grade" : "EXPERT",
"membership" : "NORMAL",
"signup_favorite" : [ "videoId1", "videoId2" ],
"my_collection" : [ "videoId3", "videoId4" ]
}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_get_user_http_response"><a class="link" href="#_get_user_http_response">Example response</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code data-lang="http" class="language-http hljs">HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 485

{
"code" : "200",
"message" : "success",
"data" : {
"id" : "6313b2381f8fa3bb122eaa78",
"nickname" : "test",
"username" : "최현준",
"firebase_uid" : "firebase_uid",
"roles" : "ROLE_USER",
"email" : "[email protected]",
"country" : "KR",
"language" : "kr",
"gender" : "MALE",
"performer_grade" : "EXPERT",
"membership" : "NORMAL",
"signup_favorite" : [ "videoId1", "videoId2" ],
"my_collection" : [ "videoId3", "videoId4" ]
}
}</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_get_user_response_fields"><a class="link" href="#_get_user_response_fields">Response fields</a></h4>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Path</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>code</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">결과 코드</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>message</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">결과 메시지</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>data</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Object</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">결과 데이터</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="_get_user_response_fields-data"><a class="link" href="#_get_user_response_fields-data">Response fields-data</a></h4>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Path</th>
<th class="tableblock halign-left valign-top">Type</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>id</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 아이디</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>nickname</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 닉네임</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>username</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 이름</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>firebase_uid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 firebase 아이디</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>roles</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 권한</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>email</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 email</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>country</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 국가</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>language</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 언어</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>gender</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 성별</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>performer_grade</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저 기타 숙련도</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>membership</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저의 등급</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>signup_favorite</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Array</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저의 초기 선택곡 리스트</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>my_collection</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Array</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">유저의 내 곡 목록</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect2">
<h3 id="_get_userlogin"><a class="link" href="#_get_userlogin"><code>GET</code> /user/login</a></h3>
<div class="paragraph">
<p>로그인 상태를 확인합니다</p>
Expand Down Expand Up @@ -4114,7 +4331,7 @@ <h4 id="_get_recommendation_response_fields-data"><a class="link" href="#_get_re
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2022-10-22 16:47:41 +0900
Last updated 2022-10-23 03:09:33 +0900
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/github.min.css">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chordplay.chordplayapiserver.domain.user.api;

import com.chordplay.chordplayapiserver.domain.entity.Sheet;
import com.chordplay.chordplayapiserver.domain.entity.User;
import com.chordplay.chordplayapiserver.domain.entity.Video;
import com.chordplay.chordplayapiserver.domain.entity.item.Country;
import com.chordplay.chordplayapiserver.domain.entity.item.Gender;
Expand All @@ -16,6 +17,7 @@
import com.chordplay.chordplayapiserver.domain.video.dto.VideoResponse;
import com.chordplay.chordplayapiserver.domain.video.service.VideoService;
import com.chordplay.chordplayapiserver.util.WithMockCustomUser;
import com.chordplay.chordplayapiserver.util.WithMockCustomUserSecurityContextFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -74,6 +76,25 @@ public void loginTest() throws Exception {
result.andDo(UserTestDocs.documentOnLoginSuccess());
}

@Test
@DisplayName("내 정보 반환 요청_닉네임 있는 유저_내 정보 반환")
@WithMockCustomUser(hasNickname = true)
public void getMyInformationTest() throws Exception {

//get
User user = WithMockCustomUserSecurityContextFactory.getAdminUser(true);

//when
ResultActions result = getMyInformation();

//then
verifyOK(result);
result.andExpect(jsonPath("$.data.nickname").value(user.getNickname()))
.andExpect(jsonPath("$.data.id").value(user.getId()))
.andExpect(jsonPath("$.data.roles").value(user.getRoles()));
result.andDo(UserTestDocs.documentOnMyInformation());
}

@Test
@DisplayName("닉네임 추천받기_닉네임 있는 유저_성공 상태 반환")
@WithMockCustomUser(hasNickname = true)
Expand Down Expand Up @@ -223,6 +244,12 @@ private ResultActions loginCheck() throws Exception {
.header("Authorization","Bearer {token}"));
}

private ResultActions getMyInformation() throws Exception {
return mockMvc.perform(get("/user")
.accept(MediaType.APPLICATION_JSON)
.header("Authorization","Bearer {token}"));
}

private ResultActions recommendNickname() throws Exception {
return mockMvc.perform(get("/user/nickname")
.accept(MediaType.APPLICATION_JSON)
Expand Down
Loading