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

Refactor: CommonResponse 형태 수정 및 validation 에러메시지 반환 #108

Merged
merged 2 commits into from
Jan 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ResponseEntity<CommonResponse<Map<String, List<String>>>> getAllCategorie

Map<String, List<String>> categories = categoryService.getAllCategories();

return ResponseEntity.ok().body(CommonResponse.of(200, "카테고리 조회 성공", categories));
return ResponseEntity.ok().body(CommonResponse.of("카테고리 조회 성공", categories));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public ResponseEntity<CommonResponse<Void>> sendChatMessage(

chatMessageService.sendChatMessages(hiveId, requestDTO, userDetails.getUser());

return ResponseEntity.ok().body(
CommonResponse.of(HttpStatus.CREATED.value(), "메시지 전송 성공", null));
return ResponseEntity.status(HttpStatus.CREATED).body(
CommonResponse.of("메시지 전송 성공", null));
}

@GetMapping("/hives/{hiveId}")
Expand All @@ -46,8 +46,7 @@ public ResponseEntity<CommonResponse<List<ChatMessageResponseDTO>>> getChatMessa
List<ChatMessageResponseDTO> responseDTOList =
chatMessageService.getChatMessages(hiveId, userDetails.getUser());

return ResponseEntity.ok().body(
CommonResponse.of(HttpStatus.OK.value(), "메시지 조회 성공", responseDTOList));
return ResponseEntity.ok().body(CommonResponse.of("메시지 조회 성공", responseDTOList));
}

@DeleteMapping("/{chat-messagesId}")
Expand All @@ -57,7 +56,6 @@ public ResponseEntity<CommonResponse<Void>> deleteChatMessage(

chatMessageService.deleteChatMessage(chatMessageId, userDetails.getUser());

return ResponseEntity.ok().body(
CommonResponse.of(HttpStatus.NO_CONTENT.value(), "메시지 삭제 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("메시지 삭제 성공", null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public ResponseEntity<CommonResponse<HiveResponseDTO>> createHive(
SubCategory.findByStringName(createHiveRequestDTO.getSubCategoryName());
HiveResponseDTO response = hiveService.createHive(userDetails.getUser(),
createHiveRequestDTO);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 작성되었습니다.", response));
return ResponseEntity.status(HttpStatus.CREATED)
.body(CommonResponse.of("하이브가 작성되었습니다.", response));
}

@PatchMapping("{hive_id}/title")
Expand All @@ -54,8 +54,7 @@ public ResponseEntity<CommonResponse<HiveResponseDTO>> updateHiveTitle(
@RequestBody @Valid UpdateHiveTitleRequestDTO updateHiveTitleRequest) {
HiveResponseDTO response = hiveService.updateHiveTitle(userDetails.getUser(), hive_id,
updateHiveTitleRequest);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 수정되었습니다.", response));
return ResponseEntity.ok().body(CommonResponse.of("하이브가 수정되었습니다.", response));
}

@PatchMapping("{hive_id}/info")
Expand All @@ -64,24 +63,21 @@ public ResponseEntity<CommonResponse<HiveResponseDTO>> updateHiveInfo(
@RequestBody @Valid UpdateHiveInfoRequestDTO updateHiveInfoRequest) {
HiveResponseDTO response = hiveService.updateHiveInfo(userDetails.getUser(), hive_id,
updateHiveInfoRequest);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 수정되었습니다.", response));
return ResponseEntity.ok().body(CommonResponse.of("하이브가 수정되었습니다.", response));
}

@GetMapping("/{hive_id}")
public ResponseEntity<CommonResponse<HiveResponseDTO>> getHive(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long hive_id) {
HiveResponseDTO response = hiveService.getHive(userDetails.getUser(), hive_id);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 조회되었습니다.", response));
return ResponseEntity.ok().body(CommonResponse.of("하이브가 조회되었습니다.", response));
}

@GetMapping("")
public ResponseEntity<CommonResponse<List<HiveResponseDTO>>> gethives() {
List<HiveResponseDTO> responses = hiveService.getHives();
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브들이 조회되었습니다.", responses));
return ResponseEntity.ok().body(CommonResponse.of("하이브들이 조회되었습니다.", responses));
}

@GetMapping("/search")
Expand All @@ -91,8 +87,7 @@ public ResponseEntity<CommonResponse<List<HiveResponseDTO>>> getHivesByCategory(
List<HiveResponseDTO> responses = hiveService.getHivesByCategory(
MajorCategory.findByStringName(majorCategory),
SubCategory.findByStringName(subCategory));
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브들이 조회되었습니다.", responses));
return ResponseEntity.ok().body(CommonResponse.of("하이브들이 조회되었습니다.", responses));
}


Expand All @@ -101,8 +96,7 @@ public ResponseEntity<CommonResponse<String>> deleteHive(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long hive_id) {
hiveService.deleteHive(userDetails.getUser(), hive_id);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브가 삭제되었습니다.", null));
return ResponseEntity.ok().body(CommonResponse.of("하이브가 삭제되었습니다.", null));
}

@PostMapping("/{hive_id}")
Expand All @@ -111,8 +105,7 @@ public ResponseEntity<CommonResponse<String>> inviteNewUser(
@PathVariable Long hive_id,
@RequestBody @Valid HiveUserInviteRequestDTO requestDTO) {
hiveService.inviteNewUser(userDetails.getUser(), hive_id, requestDTO);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브에 참여하였습니다.", null));
return ResponseEntity.ok().body(CommonResponse.of("하이브에 참여하였습니다.", null));
}

@GetMapping("/{hive_id}/hiveUsers")
Expand All @@ -122,8 +115,7 @@ public ResponseEntity<CommonResponse<List<UserInfoResponseDTO>>> getHiveUsersInH
List<UserInfoResponseDTO> hiveUserResponses = hiveService.searchUsersInHive(
userDetails.getUser(), hive_id);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브 유저들이 조회되었습니다.",
hiveUserResponses));
.body(CommonResponse.of("하이브 유저들이 조회되었습니다.", hiveUserResponses));
}

@GetMapping("/{hive_id}/hiveUsers/search")
Expand All @@ -134,8 +126,7 @@ public ResponseEntity<CommonResponse<UserInfoResponseDTO>> getHiveUserInHive(
UserInfoResponseDTO hiveUserResponse = hiveService.searchUserInHive(userDetails.getUser(),
hive_id, username);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브 유저가 조회되었습니다.",
hiveUserResponse));
.body(CommonResponse.of("하이브 유저가 조회되었습니다.", hiveUserResponse));
}

@DeleteMapping("{hive_id}/hiveUsers")
Expand All @@ -145,7 +136,7 @@ public ResponseEntity<CommonResponse<String>> deleteHiveUser(
@RequestParam String username) {
hiveService.deleteHiveUser(userDetails.getUser(), hive_id, username);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "하이브 유저가 탈퇴되었습니다.", null));
.body(CommonResponse.of("하이브 유저가 탈퇴되었습니다.", null));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ResponseEntity<CommonResponse> sendNotification(
notificationRequestDTO);

return ResponseEntity.status(HttpStatus.CREATED)
.body(CommonResponse.of(HttpStatus.CREATED.value(), "메시지 전송 성공", response));
.body(CommonResponse.of("메시지 전송 성공", response));
}

@GetMapping(value = "/{userId}/get" )
Expand All @@ -58,8 +58,7 @@ public ResponseEntity<CommonResponse> getNotificationsByUserId(
) {
List<NotificationResponseDTO> notifications = notificationService.getNotificationsByUserId(
userDetails.getUser().getId());
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "알림 출력 성공", notifications));
return ResponseEntity.ok().body(CommonResponse.of("알림 출력 성공", notifications));
}

@GetMapping("/count")
Expand All @@ -69,25 +68,22 @@ public ResponseEntity<CommonResponse> showUnreadNotificationCountForUser(
Long notificationCount = notificationService.showUnreadNotificationCountForUser(
userDetails.getUser()
.getId());
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "알림 출력 성공", notificationCount));
return ResponseEntity.ok().body(CommonResponse.of("알림 출력 성공", notificationCount));
}

@DeleteMapping("/{notificationId}")
public ResponseEntity<CommonResponse> deleteNotification(
@PathVariable(name = "notificationId") Long notificationId
) {
notificationService.deleteNotification(notificationId);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "알림 개수 조회 완료", null));
return ResponseEntity.ok().body(CommonResponse.of("알림 개수 조회 완료", null));
}
@GetMapping("/read")
public ResponseEntity<CommonResponse> readNotification(
@AuthenticationPrincipal UserDetailsImpl userDetails
){
notificationService.readNotification(userDetails.getUser().getId());
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "알림 열람 완료", null));
return ResponseEntity.ok().body(CommonResponse.of("알림 열람 완료", null));
}
@DeleteMapping("/clear")
public void clear(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ public ResponseEntity<CommonResponse<PartyResponseDTO>> createParty(
@AuthenticationPrincipal UserDetailsImpl userDetails) {

PartyResponseDTO responseDto = partyService.createParty(hiveId, partyRequestDto, userDetails.getUser());
return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 생성 성공", responseDto));
return ResponseEntity.status(HttpStatus.CREATED)
.body(CommonResponse.of("파티 생성 성공", responseDto));
}

@GetMapping("/{partyId}/hives/{hiveId}")
public ResponseEntity<CommonResponse<PartyResponseDTO>> getParty(@PathVariable Long hiveId, @PathVariable Long partyId) {

PartyResponseDTO responseDto = partyService.getPartyDto(hiveId, partyId);

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 조회 성공", responseDto));
return ResponseEntity.ok().body(CommonResponse.of("파티 조회 성공", responseDto));
}


Expand All @@ -48,7 +49,7 @@ public ResponseEntity<CommonResponse<List<PartyListResponseDTO>>> getPartyList(@
.map(entry -> new PartyListResponseDTO(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 목록 조회 성공", response));
return ResponseEntity.ok().body(CommonResponse.of("파티 목록 조회 성공", response));
}

@PatchMapping("/{partyId}")
Expand All @@ -58,7 +59,7 @@ public ResponseEntity<CommonResponse<PartyResponseDTO>> updateParty(@PathVariabl

PartyResponseDTO responseDto = partyService.updateParty(partyId, partyRequestDto, userDetails.getUser());

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "업데이트 성공", responseDto));
return ResponseEntity.ok().body(CommonResponse.of("업데이트 성공", responseDto));
}

@DeleteMapping("/{partyId}")
Expand All @@ -67,7 +68,7 @@ public ResponseEntity<CommonResponse<String>> deleteParty(@PathVariable Long par

partyService.deleteParty(partyId, userDetails.getUser());

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "정상적으로 삭제 되었습니다.", null));
return ResponseEntity.ok().body(CommonResponse.of("정상적으로 삭제 되었습니다.", null));
}

@PostMapping("/{partyId}/join")
Expand All @@ -76,7 +77,7 @@ public ResponseEntity<CommonResponse<String>> joinParty(@PathVariable Long party

partyService.joinParty(partyId, userDetails.getUser());

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 가입 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("파티 가입 성공", null));
}

@DeleteMapping("/{partyId}/resign")
Expand All @@ -85,7 +86,7 @@ public ResponseEntity<CommonResponse<String>> resignParty(@PathVariable Long par

partyService.resignParty(partyId, userDetails.getUser());

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 탈퇴 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("파티 탈퇴 성공", null));
}

@GetMapping("/users/{userId}")
Expand All @@ -94,8 +95,7 @@ public ResponseEntity<CommonResponse<List<PartyResponseDTO>>> getPartiesByUserId

List<PartyResponseDTO> response = partyService.getPartiesByUserId(userId);

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(),
"유저의 파티 조회 성공", response));
return ResponseEntity.ok().body(CommonResponse.of("유저의 파티 조회 성공", response));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public ResponseEntity<CommonResponse<Void>> signup(
@Valid @RequestBody UserSignupRequestDTO requestDTO) {

userService.signup(requestDTO);
return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.CREATED.value(), "회원가입 성공", null));
return ResponseEntity.status(HttpStatus.CREATED)
.body(CommonResponse.of("회원가입 성공", null));
}

// 이메일 인증 코드 생성
Expand All @@ -49,7 +50,8 @@ public ResponseEntity<CommonResponse<Integer>> mailConfirm(@PathVariable Long us
// 생성된 이메일 인증 코드를 사용자 엔티티에 저장
userService.requestEmailVerification(userId, verificationCode);

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.CREATED.value(), "인증코드 발급 성공", verificationCode));
return ResponseEntity.status(HttpStatus.CREATED)
.body(CommonResponse.of("인증코드 발급 성공", verificationCode));
}

// 이메일 인증 코드 검증
Expand All @@ -58,7 +60,7 @@ public ResponseEntity<CommonResponse<Void>> verifyEmail(@PathVariable Long userI

userService.verifyEmail(userId, requestDTO.getVerificationCode());

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "이메일 인증 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("이메일 인증 성공", null));
}


Expand All @@ -71,16 +73,14 @@ public ResponseEntity<CommonResponse<UserInfoResponseDTO>> login(

response.setHeader(JwtUtil.AUTHORIZATION_HEADER, jwtUtil.createToken(requestDTO.getUsername()));

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "로그인 성공", userInfo));
return ResponseEntity.ok().body(CommonResponse.of("로그인 성공", userInfo));
}

@GetMapping("/{userId}")
public ResponseEntity<CommonResponse<UserInfoResponseDTO>> getProfile(@PathVariable Long userId) {

UserInfoResponseDTO responseDTO = userService.getProfile(userId);
return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "프로필 조회 성공", responseDTO));
return ResponseEntity.ok().body(CommonResponse.of("프로필 조회 성공", responseDTO));
}


Expand All @@ -94,8 +94,7 @@ public ResponseEntity<CommonResponse<Void>> updateProfile(
User loginUser = userDetails.getUser();
userService.updateProfile(userId, requestDTO, loginUser);

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "프로필 수정 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("프로필 수정 성공", null));
}

@PatchMapping("/{userId}/password")
Expand All @@ -107,8 +106,7 @@ public ResponseEntity<CommonResponse<Void>> updatePassword(
User loginUser = userDetails.getUser();
userService.updatePassword(userId, requestDTO, loginUser);

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "비밀번호 수정 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("비밀번호 수정 성공", null));
}

@DeleteMapping("/{userId}")
Expand All @@ -119,18 +117,17 @@ public ResponseEntity<CommonResponse<Void>> deleteUser(
User loginUser = userDetails.getUser();
userService.deleteUser(userId, loginUser);

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "회원 탈퇴 성공", null));
return ResponseEntity.ok().body(CommonResponse.of("회원 탈퇴 성공", null));
}

@GetMapping("/{userId}/hives")
public ResponseEntity<CommonResponse> getMyHives(
public ResponseEntity<CommonResponse<List<HiveResponseDTO>>> getMyHives(

@PathVariable Long userId) {
List<HiveResponseDTO> hivesResponses = userService.getMyHives(
userId);
return ResponseEntity.ok()
.body(new CommonResponse<>(200, "참여 목록들이 조회되었습니다.", hivesResponses));
.body(CommonResponse.of("참여 목록들이 조회되었습니다.", hivesResponses));
}


Expand All @@ -143,8 +140,7 @@ public ResponseEntity<CommonResponse<UserCategoryResponseDTO>> setCategory(
User loginUser = userDetails.getUser();
UserCategoryResponseDTO response = userService.setCategory(userId, requestDTO, loginUser);

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.OK.value(), "카테고리 설정 성공", response));
return ResponseEntity.ok().body(CommonResponse.of("카테고리 설정 성공", response));
}

@GetMapping("/kakao/callback")
Expand All @@ -161,7 +157,6 @@ public ResponseEntity<CommonResponse<UserInfoResponseDTO>> kakaoLogin(@RequestPa
// username으로 UserInfoResponseDTO를 얻음
UserInfoResponseDTO userInfo = userService.kakaoLogin(username);

return ResponseEntity.ok()
.body(CommonResponse.of(HttpStatus.CREATED.value(), "카카오 로그인 성공", userInfo));
return ResponseEntity.ok().body(CommonResponse.of("카카오 로그인 성공", userInfo));
}
}
Loading
Loading