Skip to content

Commit

Permalink
[Fix] DTO Response Model 재정의 (일부) = #33
Browse files Browse the repository at this point in the history
  • Loading branch information
eunki96 committed May 25, 2023
1 parent 35616f2 commit e61d4ec
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ protected void init() {
}

// JWT 토큰 생성
public String createToken(String email, Role role) {
public String createToken(String email, Role role, Long userNo) {
Claims claims = Jwts.claims().setSubject(email); // JWT payload 에 저장되는 정보단위
claims.put("roles", role); // 정보는 key / value 쌍으로 저장된다.
claims.put("userNo", userNo);
Date now = new Date();

String token = Jwts.builder()
Expand All @@ -66,6 +67,8 @@ public String getUserEmail(String token) {
return info;
}



// Request의 Header에서 token 값을 가져옵니다. "X-AUTH-TOKEN" : "TOKEN값'
public String resolveToken(HttpServletRequest request) {
return request.getHeader("X-AUTH-TOKEN");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected void configure(HttpSecurity http) throws Exception {
.and()
.exceptionHandling().authenticationEntryPoint(new CustomAuthenticationEntryPoint())


.and()
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider),
UsernamePasswordAuthenticationFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public void commence(HttpServletRequest request,
responseJson.put("ResponseCode", "AUTHENTICATION_FAILED");
responseJson.put("ResponseMessage", "인증에 실패하였습니다.");



response.getWriter().print(responseJson);
}
}
47 changes: 24 additions & 23 deletions favor/src/main/java/com/favor/favor/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public ResponseEntity<DefaultResponseDto<Object>> updatePassword(
@ApiResponses(value={
@ApiResponse(code = 200,
message = "REMINDERS_FOUND",
response = ReminderResponseDto.class),
response = UserResponseDto.class),
@ApiResponse(code = 401,
message = "UNAUTHORIZED_USER"),
@ApiResponse(code = 404,
Expand Down Expand Up @@ -380,58 +380,59 @@ public ResponseEntity<DefaultResponseDto<Object>> readFriendList(@PathVariable L
.build());
}

@ApiOperation("회원의 기념일 전체 조회")

@ApiOperation("전체 회원 조회")
@ApiResponses(value={
@ApiResponse(code = 200,
message = "ANNIVERSARY_FOUND",
response = AnniversaryResponseDto.class),
message = "USERS_FOUND",
response = UserResponseDto.class),
@ApiResponse(code = 401,
message = "UNAUTHORIZED_USER"),
@ApiResponse(code = 404,
message = "USER_NOT_FOUND"),
@ApiResponse(code = 500,
message = "SERVER_ERROR")
})
@ResponseStatus(HttpStatus.OK)
@Transactional
@GetMapping("/anniversary-list/{userNo}")
public ResponseEntity<DefaultResponseDto<Object>> readAnniversaryList(@PathVariable Long userNo){

userService.isExistingUserNo(userNo);
@GetMapping
public ResponseEntity<DefaultResponseDto<Object>> readAll(){

List<AnniversaryResponseDto> friends = userService.readAnniversaryList(userNo);
List<UserResponseDto> dto = userService.readAll();

return ResponseEntity.status(200)
.body(DefaultResponseDto.builder()
.responseCode("ANNIVERSARY_FOUND")
.responseMessage("회원의 기념일 전체 조회 완료")
.data(friends)
.responseCode("USERS_FOUND")
.responseMessage("전체 회원 조회 완료")
.data(dto)
.build());
}


@ApiOperation("전체 회원 조회")
@ApiOperation("회원의 기념일 전체 조회")
@ApiResponses(value={
@ApiResponse(code = 200,
message = "USERS_FOUND",
response = UserResponseDto.class),
message = "ANNIVERSARY_FOUND",
response = AnniversaryResponseDto.class),
@ApiResponse(code = 401,
message = "UNAUTHORIZED_USER"),
@ApiResponse(code = 404,
message = "USER_NOT_FOUND"),
@ApiResponse(code = 500,
message = "SERVER_ERROR")
})
@ResponseStatus(HttpStatus.OK)
@Transactional
@GetMapping
public ResponseEntity<DefaultResponseDto<Object>> readAll(){
@GetMapping("/anniversary-list/{userNo}")
public ResponseEntity<DefaultResponseDto<Object>> readAnniversaryList(@PathVariable Long userNo){

List<UserResponseDto> dto = userService.readAll();
userService.isExistingUserNo(userNo);

List<AnniversaryResponseDto> friends = userService.readAnniversaryList(userNo);

return ResponseEntity.status(200)
.body(DefaultResponseDto.builder()
.responseCode("USERS_FOUND")
.responseMessage("전체 회원 조회 완료")
.data(dto)
.responseCode("ANNIVERSARY_FOUND")
.responseMessage("회원의 기념일 전체 조회 완료")
.data(friends)
.build());
}

Expand Down
109 changes: 99 additions & 10 deletions favor/src/main/java/com/favor/favor/user/UserResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,114 @@
@AllArgsConstructor
@Builder
public class UserResponseDto {
@ApiModelProperty(value = "1")
@ApiModelProperty(value = "1", example = "1")
private final Long userNo;
@ApiModelProperty(value = "[email protected]")

@ApiModelProperty(value = "[email protected]", example = "[email protected]")
private String email;
@ApiModelProperty(value = "페이버")

@ApiModelProperty(value = "페이버", example = "페이버")
private String name;
@ApiModelProperty(value = "favor")

@ApiModelProperty(value = "favor", example = "favor")
private String userid;
@ApiModelProperty(value = "USER")

@ApiModelProperty(value = "USER", example = "USER")
private Role role;
@ApiModelProperty(value = "")

@ApiModelProperty(value = "", example = "[\n" +
" {\n" +
" \"reminderNo\": 1,\n" +
" \"reminderTitle\": \"제목\",\n" +
" \"reminderDate\": \"1996-02-29\",\n" +
" \"reminderMemo\": \"메모\",\n" +
" \"isAlarmSet\": false,\n" +
" \"alarmTime\": \"1996-02-29T00:00:00\",\n" +
" \"userNo\": 1,\n" +
" \"friendNo\": 1\n" +
" }\n" +
" ]")
private List<ReminderResponseDto> reminderList;
@ApiModelProperty(value = "")

@ApiModelProperty(value = "", example = "[\n" +
" {\n" +
" \"giftNo\": 1,\n" +
" \"giftName\": \"선물이름\",\n" +
" \"giftDate\": \"1996-02-29\",\n" +
" \"giftMemo\": \"선물메모\",\n" +
" \"category\": \"생일\",\n" +
" \"emotion\": \"기뻐요\",\n" +
" \"isPinned\": false,\n" +
" \"isGiven\": false,\n" +
" \"userNo\": 1,\n" +
" \"friendList\": [\n" +
" {\n" +
" \"isUser\": true,\n" +
" \"friendNo\": 1,\n" +
" \"friendName\": \"페이버2\",\n" +
" \"friendMemo\": \"메모\",\n" +
" \"reminderList\": [],\n" +
" \"giftList\": [],\n" +
" \"favorList\": [],\n" +
" \"friendUserNo\": 2,\n" +
" \"anniversaryList\": [],\n" +
" \"userNo\": 1\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]")
private List<GiftResponseDto> giftList;
@ApiModelProperty(value = "")

@ApiModelProperty(value = "", example = "[\n" +
" {\n" +
" \"isUser\": true,\n" +
" \"friendNo\": 1,\n" +
" \"friendName\": \"페이버2\",\n" +
" \"friendMemo\": \"메모\",\n" +
" \"reminderList\": [],\n" +
" \"giftList\": [],\n" +
" \"favorList\": [],\n" +
" \"friendUserNo\": 2,\n" +
" \"anniversaryList\": [],\n" +
" \"userNo\": 1\n" +
" },\n" +
" {\n" +
" \"isUser\": false,\n" +
" \"friendNo\": 2,\n" +
" \"friendName\": \"이름11\",\n" +
" \"friendMemo\": \"메모\",\n" +
" \"reminderList\": [],\n" +
" \"giftList\": [],\n" +
" \"favorList\": [],\n" +
" \"friendUserNo\": null,\n" +
" \"anniversaryList\": [],\n" +
" \"userNo\": 1\n" +
" }\n" +
" ]")
private List<FriendResponseDto> friendList;
@ApiModelProperty(value = "")

@ApiModelProperty(value = "", example = "[\n" +
" {\n" +
" \"anniversaryNo\": 1,\n" +
" \"anniversaryTitle\": \"제목\",\n" +
" \"anniversaryDate\": \"1996-02-29\",\n" +
" \"isPinned\": false,\n" +
" \"userNo\": 1\n" +
" },\n" +
" {\n" +
" \"anniversaryNo\": 2,\n" +
" \"anniversaryTitle\": \"제목\",\n" +
" \"anniversaryDate\": \"2024-02-29\",\n" +
" \"isPinned\": false,\n" +
" \"userNo\": 1\n" +
" }\n" +
" ]")
private List<AnniversaryResponseDto> anniversaryList;
@ApiModelProperty(value = "")

@ApiModelProperty(value = "", example = "[\n" +
" \"심플한\",\n" +
" \"귀여운\"\n" +
" ]")
private List<Favor> favorList;

@Builder
Expand Down
2 changes: 1 addition & 1 deletion favor/src/main/java/com/favor/favor/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public SignInResponseDto signIn(SignDto dto){

isRightPassword(password, user);

String token = jwtTokenProvider.createToken(user.getEmail(), user.getRole());
String token = jwtTokenProvider.createToken(user.getEmail(), user.getRole(), user.getUserNo());

return new SignInResponseDto(token);
}
Expand Down

0 comments on commit e61d4ec

Please sign in to comment.