Merge pull request #51 from Development-team-1/mypage

Mypage
This commit is contained in:
Sangbum Park
2022-03-16 20:27:35 +09:00
committed by GitHub
7 changed files with 179 additions and 1 deletions

View File

@@ -5,6 +5,9 @@ export default {
requestRegisterUser(user) {
return axios.post(process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL+"/user-service/store-owner", user);
},
geUserData() {
return axios.get(process.env.VUE_APP_CUSTOMER_SERVICE_BASEURL+"/user-service/customer/", );
},
async requestLoginUser(email, password) {
const user = {

View File

@@ -24,7 +24,7 @@ export default {
{name: "검색", url: "/search", icon: "mdi-magnify"},
{name: "즐겨찾기", url: "/favorite", icon: "mdi-cards-heart-outline"},
{name: "주문내역", url: "/history", icon: "mdi-clipboard-check-outline"},
{name: "마이페이지", url: "/", icon: "mdi-account-outline"}
{name: "마이페이지", url: "/mypage", icon: "mdi-account-outline"}
]
}
},
@@ -33,6 +33,13 @@ export default {
this.value = index;
this.$router.push(url);
}
},mounted() {
const path =this.$route.path
this.links.forEach((link, index) => {
if(link.url === path){
this.value = index
}
})
}
}
</script>

View File

@@ -0,0 +1,88 @@
<template>
<v-container
fill-height
>
<v-row >
<v-col >
<v-card
class="mx-auto mb-5 v-alert--border"
outlined
elevation="9"
>
<v-card-title> 정보 관리</v-card-title>
<v-card-text>
<v-form
ref="form"
v-model="userData.valid"
lazy-validation
readonly
>
<v-text-field
v-model="userData.userId"
label="id"
required
/>
<v-text-field
v-model="userData.email"
label="E-mail"
required
/>
<v-text-field
v-model="userData.userName"
label="Name"
required
/>
<v-text-field
v-model="userData.phoneNumber"
label="phoneNumber"
required
/>
<v-btn
color="orange"
block>수정하기</v-btn>
</v-form>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</template>
<script>
import userApi from "@/api/user";
export default {
name: "MyPage",
data (){
return {
userData:{
userId:'',
email:'',
userName:'',
phoneNumber:'',
},
}
},
methods:{
getUserData(){
userApi.geUserData().then(response =>{
this.userData = response.data.data
}).catch(error =>{
console.log(error.response)
})
},
},
mounted() {
this.getUserData()
}
}
</script>
<style scoped>
</style>

View File

@@ -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']
=== 회원 조회 (존재하지 않는 회원)

View File

@@ -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();

View File

@@ -24,6 +24,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(@Valid @PathVariable("userId") Long userId) {

View File

@@ -21,12 +21,15 @@ 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;
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;
@@ -58,6 +61,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 {