diff --git a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java index 5a77673..a1964eb 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java +++ b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java @@ -19,23 +19,27 @@ public class Anniversary extends TimeStamped { private Long anniversaryNo; private String anniversaryTitle; - public void setAnniversaryTitle(String anniversaryTitle){ this.anniversaryTitle = anniversaryTitle; } private LocalDate anniversaryDate; - public void setAnniversaryDate(LocalDate anniversaryDate){ this.anniversaryDate = anniversaryDate; } private Integer category; - public void setCategory(AnniversaryCategory anniversaryCategory){ - this.category = anniversaryCategory.getType(); - } private Boolean isPinned; - public void setIsPinned(Boolean isPinned){ this.isPinned = isPinned; } @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER) @JoinColumn(name = "user_user_no") private User user; + public void updateAnniversaryTitle(String anniversaryTitle){ this.anniversaryTitle = anniversaryTitle; } + + public void updateAnniversaryDate(LocalDate anniversaryDate){ this.anniversaryDate = anniversaryDate; } + + public void updateCategory(AnniversaryCategory anniversaryCategory){ + this.category = anniversaryCategory.getType(); + } + + public void updateIsPinned(Boolean isPinned){ this.isPinned = isPinned; } + @Builder public Anniversary(String anniversaryTitle, LocalDate anniversaryDate, Integer category, Boolean isPinned, User user) { this.anniversaryTitle = anniversaryTitle; diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java index 78a0151..c260ab3 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java @@ -14,9 +14,6 @@ import java.util.List; -import static com.favor.favor.common.DefaultResponseDto.resWithData; -import static com.favor.favor.common.DefaultResponseDto.resWithoutData; - @Api(tags = "Anniversary") @RestController @RequestMapping("/anniversaries") @@ -37,7 +34,6 @@ public class AnniversaryController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping public ResponseEntity> createAnniversary( @RequestBody AnniversaryRequestDto anniversaryRequestDto, @@ -45,13 +41,10 @@ public ResponseEntity> createAnniversary( Long userNo = loginUser.getUserNo(); - anniversaryService.isExistingUserNo(userNo); - - Anniversary anniversary = anniversaryService.createAnniversary(anniversaryRequestDto, userNo); - AnniversaryResponseDto dto = anniversaryService.returnDto(anniversary); + AnniversaryResponseDto anniversaryResponseDto = anniversaryService.createAnniversary(userNo, anniversaryRequestDto); - return ResponseEntity.status(201) - .body(resWithData("ANIVERSARY_CREATED", "기념일 생성 완료", dto)); + return ResponseEntity.status(HttpStatus.CREATED) + .body(DefaultResponseDto.from("ANNIVERSARY_CREATED", "기념일 생성 완료", anniversaryResponseDto)); } @ApiOperation("기념일 조회") @@ -66,17 +59,13 @@ public ResponseEntity> createAnniversary( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/{anniversaryNo}") public ResponseEntity> readAnniversary( @PathVariable Long anniversaryNo){ - anniversaryService.isExistingAnniversaryNo(anniversaryNo); - Anniversary anniversary = anniversaryService.findAnniversaryByAnniversaryNo(anniversaryNo); - AnniversaryResponseDto dto = anniversaryService.returnDto(anniversary); + AnniversaryResponseDto anniversaryResponseDto = anniversaryService.readAnniversary(anniversaryNo); - return ResponseEntity.status(200) - .body(resWithData("ANNIVERSARY_FOUND", "기념일 조회 완료", dto)); + return ResponseEntity.ok(DefaultResponseDto.from("ANNIVERSARY_FOUND", "기념일 조회 완료", anniversaryResponseDto)); } @ApiOperation("기념일 수정") @@ -91,20 +80,14 @@ public ResponseEntity> readAnniversary( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/{anniversaryNo}") public ResponseEntity> updateAnniversary( @RequestBody AnniversaryUpdateRequestDto anniversaryUpdateRequestDto, @PathVariable Long anniversaryNo){ - anniversaryService.isExistingAnniversaryNo(anniversaryNo); - - Anniversary anniversary = anniversaryService.findAnniversaryByAnniversaryNo(anniversaryNo); - anniversaryService.updateAnniversary(anniversaryUpdateRequestDto, anniversary); - AnniversaryResponseDto dto = anniversaryService.returnDto(anniversary); + AnniversaryResponseDto anniversaryResponseDto = anniversaryService.updateAnniversary(anniversaryNo, anniversaryUpdateRequestDto); - return ResponseEntity.status(200) - .body(resWithData("ANNIVERSARY_UPDATED", "기념일 수정 완료", dto)); + return ResponseEntity.ok(DefaultResponseDto.from("ANNIVERSARY_UPDATED", "기념일 수정 완료", anniversaryResponseDto)); } @ApiOperation("기념일 핀 여부 수정") @@ -119,19 +102,13 @@ public ResponseEntity> updateAnniversary( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/pin/{anniversaryNo}") public ResponseEntity> updateIsPinned( @PathVariable Long anniversaryNo){ - anniversaryService.isExistingAnniversaryNo(anniversaryNo); + AnniversaryResponseDto anniversaryResponseDto = anniversaryService.updateIsPinned(anniversaryNo); - Anniversary anniversary = anniversaryService.findAnniversaryByAnniversaryNo(anniversaryNo); - anniversaryService.updateIsPinned(anniversary); - AnniversaryResponseDto dto = anniversaryService.returnDto(anniversary); - - return ResponseEntity.status(200) - .body(resWithData("ANNIVERSARY_PIN_UPDATED", "기념일 핀 수정 완료", dto)); + return ResponseEntity.ok(DefaultResponseDto.from("ANNIVERSARY_PIN_UPDATED", "기념일 핀 수정 완료", anniversaryResponseDto)); } @ApiOperation("기념일 삭제") @@ -146,19 +123,13 @@ public ResponseEntity> updateIsPinned( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping("/{anniversaryNo}") public ResponseEntity> deleteAnniversary( @PathVariable Long anniversaryNo){ - anniversaryService.isExistingAnniversaryNo(anniversaryNo); - - Anniversary anniversary = anniversaryService.findAnniversaryByAnniversaryNo(anniversaryNo); - anniversaryService.deleteAnniversary(anniversaryNo); - return ResponseEntity.status(200) - .body(resWithoutData("ANNIVERSARY_DELETED", "기념일_삭제_완료")); + return ResponseEntity.ok(DefaultResponseDto.from("ANNIVERSARY_DELETED", "기념일_삭제_완료")); } @ApiOperation("전체 기념일 조회") @@ -171,13 +142,11 @@ public ResponseEntity> deleteAnniversary( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/admin") public ResponseEntity> readAll(){ List dto = anniversaryService.readAll(); - return ResponseEntity.status(200) - .body(resWithData("ANIVERSARIES_FOUND", "전체 기념일 조회 완료", dto)); + return ResponseEntity.ok(DefaultResponseDto.from("ANNIVERSARIES_FOUND", "전체 기념일 조회 완료", dto)); } } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java index 2cb5e9d..295bad8 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java @@ -12,7 +12,6 @@ @Getter @NoArgsConstructor -@AllArgsConstructor public class AnniversaryRequestDto { @ApiModelProperty(position = 1, required = true, value = "제목", example = "제목") private String anniversaryTitle; diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java index 55ca4aa..5467e58 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java @@ -1,7 +1,6 @@ package com.favor.favor.anniversary; import com.favor.favor.common.enums.AnniversaryCategory; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -9,7 +8,6 @@ import java.time.LocalDateTime; @Getter -@AllArgsConstructor public class AnniversaryResponseDto { private Long anniversaryNo; private String anniversaryTitle; @@ -21,14 +19,27 @@ public class AnniversaryResponseDto { private AnniversaryCategory anniversaryCategory; @Builder - public AnniversaryResponseDto(Anniversary anniversary){ - this.anniversaryNo = anniversary.getAnniversaryNo(); - this.anniversaryTitle = anniversary.getAnniversaryTitle(); - this.anniversaryDate = anniversary.getAnniversaryDate(); - this.isPinned = anniversary.getIsPinned(); - this.userNo = anniversary.getUser().getUserNo(); - this.createdAt = anniversary.getCreatedAt(); - this.modifiedAt = anniversary.getModifiedAt(); - this.anniversaryCategory = AnniversaryCategory.valueOf(anniversary.getCategory()); + private AnniversaryResponseDto(Long anniversaryNo, String anniversaryTitle, LocalDate anniversaryDate, Boolean isPinned, Long userNo, LocalDateTime createdAt, LocalDateTime modifiedAt, AnniversaryCategory anniversaryCategory) { + this.anniversaryNo = anniversaryNo; + this.anniversaryTitle = anniversaryTitle; + this.anniversaryDate = anniversaryDate; + this.isPinned = isPinned; + this.userNo = userNo; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.anniversaryCategory = anniversaryCategory; + } + + public static AnniversaryResponseDto from(Anniversary anniversary) { + return AnniversaryResponseDto.builder() + .anniversaryNo(anniversary.getAnniversaryNo()) + .anniversaryTitle(anniversary.getAnniversaryTitle()) + .anniversaryDate(anniversary.getAnniversaryDate()) + .isPinned(anniversary.getIsPinned()) + .userNo(anniversary.getUser().getUserNo()) + .createdAt(anniversary.getCreatedAt()) + .modifiedAt(anniversary.getModifiedAt()) + .anniversaryCategory(AnniversaryCategory.valueOf(anniversary.getCategory())) + .build(); } } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java index 0771768..1366399 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java @@ -12,6 +12,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import static com.favor.favor.exception.ExceptionCode.*; @@ -25,52 +26,80 @@ public class AnniversaryService { private final FriendRepository friendRepository; @Transactional - public Anniversary createAnniversary(AnniversaryRequestDto anniversaryRequestDto, Long userNo){ + public AnniversaryResponseDto createAnniversary(Long userNo, AnniversaryRequestDto anniversaryRequestDto){ + isExistingUserNo(userNo); User user = findUserByUserNo(userNo); - Anniversary anniversary = anniversaryRepository.save(anniversaryRequestDto.toEntity(anniversaryRequestDto.getAnniversaryTitle(), user)); - return anniversaryRepository.save(anniversary); + + Anniversary anniversary = anniversaryRequestDto.toEntity(anniversaryRequestDto.getAnniversaryTitle(), user); + anniversaryRepository.save(anniversary); + + return AnniversaryResponseDto.from(anniversary); + } + + public AnniversaryResponseDto readAnniversary(Long anniversaryNo) { + isExistingAnniversaryNo(anniversaryNo); + Anniversary anniversary = findAnniversaryByAnniversaryNo(anniversaryNo); + + return AnniversaryResponseDto.from(anniversary); } @Transactional - public void updateAnniversary(AnniversaryUpdateRequestDto dto, Anniversary anniversary){ - anniversary.setAnniversaryTitle(dto.getAnniversaryTitle()); - anniversary.setAnniversaryDate(LocalDate.parse(dto.getAnniversaryDate())); - anniversary.setCategory(dto.getAnniversaryCategory()); + public AnniversaryResponseDto updateAnniversary(Long anniversaryNo, AnniversaryUpdateRequestDto anniversaryUpdateRequestDto){ + isExistingAnniversaryNo(anniversaryNo); + Anniversary anniversary = findAnniversaryByAnniversaryNo(anniversaryNo); + + anniversary.updateAnniversaryTitle(anniversaryUpdateRequestDto.getAnniversaryTitle()); + anniversary.updateAnniversaryDate(LocalDate.parse(anniversaryUpdateRequestDto.getAnniversaryDate())); + anniversary.updateCategory(anniversaryUpdateRequestDto.getAnniversaryCategory()); anniversaryRepository.save(anniversary); + + return AnniversaryResponseDto.from(anniversary); } @Transactional - public void updateIsPinned(Anniversary anniversary){ - anniversary.setIsPinned(anniversary.getIsPinned() == true ? false : true); + public AnniversaryResponseDto updateIsPinned(Long anniversaryNo){ + isExistingAnniversaryNo(anniversaryNo); + Anniversary anniversary = findAnniversaryByAnniversaryNo(anniversaryNo); + + anniversary.updateIsPinned(anniversary.getIsPinned() == true ? false : true); anniversaryRepository.save(anniversary); + + return AnniversaryResponseDto.from(anniversary); } +// @Transactional +// public void deleteAnniversary(Long anniversaryNo){ +// List friendList = findAnniversaryByAnniversaryNo(anniversaryNo).getUser().getFriendList(); +// for(Friend friend : friendList){ +// if(friend.getAnniversaryNoList().contains(anniversaryNo)){ +// friend.getAnniversaryNoList().remove(anniversaryNo); +// friendRepository.save(friend); +// } +// } +// +// anniversaryRepository.deleteByAnniversaryNo(anniversaryNo); +// } + @Transactional public void deleteAnniversary(Long anniversaryNo){ - List friendList = findAnniversaryByAnniversaryNo(anniversaryNo).getUser().getFriendList(); - for(Friend friend : friendList){ - if(friend.getAnniversaryNoList().contains(anniversaryNo)){ - friend.getAnniversaryNoList().remove(anniversaryNo); - friendRepository.save(friend); - } - } + List updateRequiredFriends = findAnniversaryByAnniversaryNo(anniversaryNo).getUser().getFriendList().stream() + .filter(friend -> friend.getAnniversaryNoList().contains(anniversaryNo)) + .peek(friend -> friend.getAnniversaryNoList().remove(anniversaryNo)) + .collect(Collectors.toList()); + friendRepository.saveAll(updateRequiredFriends); anniversaryRepository.deleteByAnniversaryNo(anniversaryNo); } public List readAll(){ - List a_List = new ArrayList<>(); - for(Anniversary a : anniversaryRepository.findAll()){ - AnniversaryResponseDto dto = new AnniversaryResponseDto(a); - a_List.add(dto); - } - return a_List; + return anniversaryRepository.findAll().stream() + .map(AnniversaryResponseDto::from) + .collect(Collectors.toList()); } - - public User findUserByUserNo(Long userNo){ - User user = null; + private User findUserByUserNo(Long userNo){ + User user; try{ user = userRepository.findByUserNo(userNo).orElseThrow( () -> new RuntimeException() @@ -80,8 +109,9 @@ public User findUserByUserNo(Long userNo){ } return user; } - public Anniversary findAnniversaryByAnniversaryNo(Long anniversaryNo){ - Anniversary anniversary = null; + + private Anniversary findAnniversaryByAnniversaryNo(Long anniversaryNo){ + Anniversary anniversary; try{ anniversary = anniversaryRepository.findAnniversaryByAnniversaryNo(anniversaryNo).orElseThrow( () -> new RuntimeException() @@ -93,12 +123,8 @@ public Anniversary findAnniversaryByAnniversaryNo(Long anniversaryNo){ } - public AnniversaryResponseDto returnDto(Anniversary anniversary){ - return new AnniversaryResponseDto(anniversary); - } - - public void isExistingAnniversaryNo(Long anniversaryNo){ - Boolean isExistingNo = null; + private void isExistingAnniversaryNo(Long anniversaryNo){ + Boolean isExistingNo; try{ isExistingNo = anniversaryRepository.existsByAnniversaryNo(anniversaryNo); }catch(RuntimeException e){ @@ -109,8 +135,8 @@ public void isExistingAnniversaryNo(Long anniversaryNo){ } } - public void isExistingUserNo (Long userNo){ - Boolean isExistingNo = null; + private void isExistingUserNo (Long userNo){ + Boolean isExistingNo; try{ isExistingNo = userRepository.existsByUserNo(userNo); } catch(RuntimeException e){ diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java index 66eb64f..09bd568 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java @@ -9,7 +9,6 @@ @Getter @NoArgsConstructor -@AllArgsConstructor public class AnniversaryUpdateRequestDto { @ApiModelProperty(position = 1, required = true, value = "제목", example = "제목") diff --git a/favor/src/main/java/com/favor/favor/common/DefaultResponseDto.java b/favor/src/main/java/com/favor/favor/common/DefaultResponseDto.java index c61d0ee..781a7f5 100644 --- a/favor/src/main/java/com/favor/favor/common/DefaultResponseDto.java +++ b/favor/src/main/java/com/favor/favor/common/DefaultResponseDto.java @@ -23,14 +23,14 @@ private DefaultResponseDto(String responseCode, String responseMessage, T data){ this.data = data; } - public static DefaultResponseDto resWithoutData(final String responseCode, final String responseMessage){ + public static DefaultResponseDto from(String responseCode, String responseMessage){ return DefaultResponseDto.builder() .responseCode(responseCode) .responseMessage(responseMessage) .build(); } - public static DefaultResponseDto resWithData(final String responseCode, final String responseMessage, final T data){ + public static DefaultResponseDto from(String responseCode, String responseMessage, T data){ return DefaultResponseDto.builder() .responseCode(responseCode) .responseMessage(responseMessage) diff --git a/favor/src/main/java/com/favor/favor/friend/FriendController.java b/favor/src/main/java/com/favor/favor/friend/FriendController.java index 13f2279..5cd335d 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendController.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendController.java @@ -10,15 +10,14 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.util.List; -import static com.favor.favor.common.DefaultResponseDto.resWithData; -import static com.favor.favor.common.DefaultResponseDto.resWithoutData; +import static com.favor.favor.common.DefaultResponseDto.from; +import static com.favor.favor.common.DefaultResponseDto.from; @Api(tags = "Friend") @@ -40,7 +39,6 @@ public class FriendController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping public ResponseEntity> addFriend( @RequestBody FriendRequestDto friendRequestDto, @@ -55,7 +53,7 @@ public ResponseEntity> addFriend( FriendResponseDto dto = friendService.returnDto(friend); return ResponseEntity.status(201) - .body(resWithData("FRIEND_ADDED", "친구 추가 완료", dto)); + .body(DefaultResponseDto.from("FRIEND_ADDED", "친구 추가 완료", dto)); } @ApiOperation("친구 조회") @@ -70,7 +68,6 @@ public ResponseEntity> addFriend( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/{friendNo}") public ResponseEntity> readFriend( @PathVariable Long friendNo){ @@ -81,7 +78,7 @@ public ResponseEntity> readFriend( FriendResponseDto dto = friendService.returnDto(friend); return ResponseEntity.status(200) - .body(resWithData("FRIEND_FOUND", "친구 조회 완료", dto)); + .body(DefaultResponseDto.from("FRIEND_FOUND", "친구 조회 완료", dto)); } @ApiOperation("친구 메모 수정") @@ -96,7 +93,6 @@ public ResponseEntity> readFriend( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/{friendNo}") public ResponseEntity> updateFriend( @PathVariable Long friendNo, @@ -111,7 +107,7 @@ public ResponseEntity> updateFriend( FriendResponseDto dto = friendService.returnDto(friend); return ResponseEntity.status(200) - .body(resWithData("FRIEND_MEMO_UPDATED", "친구 메모 수정 완료", dto)); + .body(DefaultResponseDto.from("FRIEND_MEMO_UPDATED", "친구 메모 수정 완료", dto)); } @ApiOperation("친구 삭제") @@ -126,7 +122,6 @@ public ResponseEntity> updateFriend( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping("/{friendNo}") public ResponseEntity> deleteFriend( @PathVariable Long friendNo){ @@ -138,7 +133,7 @@ public ResponseEntity> deleteFriend( friendService.deleteFriend(friendNo); return ResponseEntity.status(200) - .body(resWithoutData("FRIEND_DELETED", "친구 삭제 완료")); + .body(from("FRIEND_DELETED", "친구 삭제 완료")); } @ApiOperation("전체 친구 조회") @@ -151,14 +146,13 @@ public ResponseEntity> deleteFriend( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/admin") public ResponseEntity> readAll(){ List dto = friendService.readAll(); return ResponseEntity.status(200) - .body(resWithData("FRIENDS_FOUND", "전체 친구 조회 완료", dto)); + .body(DefaultResponseDto.from("FRIENDS_FOUND", "전체 친구 조회 완료", dto)); } @ApiOperation("친구의 선물 전체 조회") @@ -171,7 +165,6 @@ public ResponseEntity> readAll(){ @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/total-gifts/{friendNo}") public ResponseEntity> readTotalGiftList( @PathVariable Long friendNo){ @@ -179,7 +172,7 @@ public ResponseEntity> readTotalGiftList( List dto = friendService.findGiftListByFriendNo(friendNo); return ResponseEntity.status(200) - .body(resWithData("GIFTS_FOUND", "친구의 선물 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_FOUND", "친구의 선물 전체 조회 완료", dto)); } @ApiOperation("친구가 준 선물 전체 조회") @@ -192,7 +185,6 @@ public ResponseEntity> readTotalGiftList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/given-gifts/{friendNo}") public ResponseEntity> readGivenGiftList( @PathVariable Long friendNo){ // 유저 입장에서 받은 선물이므로 관련 친구가 준 선물임 @@ -200,7 +192,7 @@ public ResponseEntity> readGivenGiftList( List dto = friendService.findReceivedGiftList(friendNo); return ResponseEntity.status(200) - .body(resWithData("GIFTS_FOUND", "친구가 준 선물 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_FOUND", "친구가 준 선물 전체 조회 완료", dto)); } @ApiOperation("친구가 받은 선물 전체 조회") @@ -213,7 +205,6 @@ public ResponseEntity> readGivenGiftList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/received-gifts/{friendNo}") public ResponseEntity> readReceivedGiftList( @PathVariable Long friendNo){// 유저 입장에서 준 선물이므로 관련 친구가 받은 선물임 @@ -221,6 +212,6 @@ public ResponseEntity> readReceivedGiftList( List dto = friendService.findGivenGiftList(friendNo); return ResponseEntity.status(200) - .body(resWithData("GIFTS_FOUND", "친구가 받은 선물 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_FOUND", "친구가 받은 선물 전체 조회 완료", dto)); } } diff --git a/favor/src/main/java/com/favor/favor/friend/FriendService.java b/favor/src/main/java/com/favor/favor/friend/FriendService.java index 29190d0..d1f67c3 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendService.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendService.java @@ -186,7 +186,7 @@ public FriendResponseDto returnDto(Friend friend){ } List anniversaryList = new ArrayList<>(); for(Anniversary a : friendUser.getAnniversaryList()){ - anniversaryList.add(new AnniversaryResponseDto(a)); + anniversaryList.add(AnniversaryResponseDto.from(a)); } HashMap giftInfo = returnGiftInfo(friend.getFriendNo()); diff --git a/favor/src/main/java/com/favor/favor/gift/GiftController.java b/favor/src/main/java/com/favor/favor/gift/GiftController.java index be1afed..766fac2 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftController.java @@ -8,15 +8,14 @@ import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.util.List; -import static com.favor.favor.common.DefaultResponseDto.resWithData; -import static com.favor.favor.common.DefaultResponseDto.resWithoutData; +import static com.favor.favor.common.DefaultResponseDto.from; +import static com.favor.favor.common.DefaultResponseDto.from; @Api(tags = "Gift") @RestController @@ -38,7 +37,6 @@ public class GiftController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping public ResponseEntity> createGift( @RequestBody GiftRequestDto giftRequestDto, @@ -55,7 +53,7 @@ public ResponseEntity> createGift( GiftResponseDto dto = giftService.returnDto(gift); return ResponseEntity.status(201) - .body(resWithData("GIFT_CREATED", "선물 생성 완료", dto)); + .body(DefaultResponseDto.from("GIFT_CREATED", "선물 생성 완료", dto)); } @ApiOperation("선물 조회") @@ -70,7 +68,6 @@ public ResponseEntity> createGift( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/{giftNo}") public ResponseEntity> readGift( @PathVariable Long giftNo){ @@ -82,7 +79,7 @@ public ResponseEntity> readGift( log.info("[Controller] [readGift] DTO 반환"); return ResponseEntity.status(200) - .body(resWithData("GIFT_FOUND", "선물 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFT_FOUND", "선물 조회 완료", dto)); } @ApiOperation("선물 수정") @@ -97,7 +94,6 @@ public ResponseEntity> readGift( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/{giftNo}") public ResponseEntity> updateGift( @RequestBody GiftUpdateRequestDto giftUpdateRequestDto, @@ -111,7 +107,7 @@ public ResponseEntity> updateGift( GiftResponseDto dto = giftService.returnDto(gift); return ResponseEntity.status(200) - .body(resWithData("GIFT_UPDATED", "선물 수정 완료", dto)); + .body(DefaultResponseDto.from("GIFT_UPDATED", "선물 수정 완료", dto)); } @ApiOperation("선물 임시친구목록 수정") @@ -126,7 +122,6 @@ public ResponseEntity> updateGift( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/temp-friend-list/{giftNo}") public ResponseEntity> updateTempFriendListGift( @PathVariable Long giftNo, @@ -141,7 +136,7 @@ public ResponseEntity> updateTempFriendListGift( GiftResponseDto dto = giftService.returnDto(gift); return ResponseEntity.status(200) - .body(resWithData("GIFT_TEMP_FRIEND_LIST_UPDATED", "선물 임시친구목록 수정 완료", dto)); + .body(DefaultResponseDto.from("GIFT_TEMP_FRIEND_LIST_UPDATED", "선물 임시친구목록 수정 완료", dto)); } @ApiOperation("선물 핀 여부 수정") @@ -156,7 +151,6 @@ public ResponseEntity> updateTempFriendListGift( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/pin/{giftNo}") public ResponseEntity> updateIsPinned( @PathVariable Long giftNo){ @@ -169,7 +163,7 @@ public ResponseEntity> updateIsPinned( GiftResponseDto dto = giftService.returnDto(gift); return ResponseEntity.status(200) - .body(resWithData("GIFT_PIN_UPDATED", "선물 핀 여부 수정 완료", dto)); + .body(DefaultResponseDto.from("GIFT_PIN_UPDATED", "선물 핀 여부 수정 완료", dto)); } @ApiOperation("선물 삭제") @@ -184,7 +178,6 @@ public ResponseEntity> updateIsPinned( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping("/{giftNo}") public ResponseEntity> deleteGift( @PathVariable Long giftNo){ @@ -203,7 +196,7 @@ public ResponseEntity> deleteGift( log.info("[SYSTEM] giftService.deleteGift(giftNo) 완료"); return ResponseEntity.status(200) - .body(resWithoutData("GIFT_DELETED", "선물 삭제 완료")); + .body(from("GIFT_DELETED", "선물 삭제 완료")); } @ApiOperation("전체 선물 조회") @@ -216,14 +209,13 @@ public ResponseEntity> deleteGift( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/admin") public ResponseEntity> readAll(){ List dto = giftService.readAll(); return ResponseEntity.status(200) - .body(resWithData("GIFTS_FOUND", "전체 선물 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_FOUND", "전체 선물 조회 완료", dto)); } } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java b/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java index 2f483ec..ca733cd 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java @@ -13,11 +13,10 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import javax.transaction.Transactional; import java.util.List; -import static com.favor.favor.common.DefaultResponseDto.resWithData; -import static com.favor.favor.common.DefaultResponseDto.resWithoutData; +import static com.favor.favor.common.DefaultResponseDto.from; +import static com.favor.favor.common.DefaultResponseDto.from; @Api(tags = "Gift-Photo") @RestController @@ -54,7 +53,7 @@ public ResponseEntity> addGiftPhotoList( List dto = giftPhotoService.getGiftPhotoList(giftNo); return ResponseEntity.status(201) - .body(resWithData("GIFT_PHOTO_LIST_ADDED", "선물 사진 추가", dto)); + .body(DefaultResponseDto.from("GIFT_PHOTO_LIST_ADDED", "선물 사진 추가", dto)); } @ApiOperation("선물 사진 목록 조회") @@ -77,7 +76,7 @@ public ResponseEntity> getUserProfilePhoto(Long giftN List dto = giftPhotoService.getGiftPhotoList(giftNo); return ResponseEntity.status(200) - .body(resWithData("GIFT_PHOTO_LIST_FOUND", "선물 사진 목록 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFT_PHOTO_LIST_FOUND", "선물 사진 목록 조회 완료", dto)); } @ApiOperation("선물 사진 삭제") @@ -100,6 +99,6 @@ public ResponseEntity> deleteUserProfilePhoto( giftPhotoService.deleteGiftPhoto(giftNo, fileUrl); return ResponseEntity.status(200) - .body(resWithoutData("GIFT_PHOTO_DELETED", "선물 사진 삭제 완료")); + .body(from("GIFT_PHOTO_DELETED", "선물 사진 삭제 완료")); } } diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoController.java b/favor/src/main/java/com/favor/favor/photo/PhotoController.java index 03bab9c..883bdc3 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoController.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoController.java @@ -31,7 +31,6 @@ public class PhotoController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PostMapping public ResponseEntity> savePhoto( @ModelAttribute MultipartFile photo){ @@ -58,7 +57,6 @@ public ResponseEntity> savePhoto( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping public ResponseEntity> deletePhoto( String filename){ diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java index 78ceb05..12c1aff 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java @@ -8,16 +8,14 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; -import lombok.extern.log4j.Log4j2; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.util.List; -import static com.favor.favor.common.DefaultResponseDto.resWithData; -import static com.favor.favor.common.DefaultResponseDto.resWithoutData; +import static com.favor.favor.common.DefaultResponseDto.from; +import static com.favor.favor.common.DefaultResponseDto.from; @Api(tags = "Reminder") @RestController @@ -39,7 +37,6 @@ public class ReminderController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping("/new") public ResponseEntity> createReminder( @RequestBody ReminderRequestDto reminderRequestDto, @@ -60,7 +57,7 @@ public ResponseEntity> createReminder( ReminderResponseDto dto = reminderService.returnDto(reminder); return ResponseEntity.status(201) - .body(resWithData("REMINDER_CREATED", "리마인더 생성 완료", dto)); + .body(DefaultResponseDto.from("REMINDER_CREATED", "리마인더 생성 완료", dto)); } @ApiOperation("친구의 기념일을 리마인더로 추가") @@ -75,7 +72,6 @@ public ResponseEntity> createReminder( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{anniversaryNo}") public ResponseEntity> addReminder( @AuthenticationPrincipal User loginUser, @@ -90,7 +86,7 @@ public ResponseEntity> addReminder( ReminderResponseDto dto = reminderService.returnDto(reminder); return ResponseEntity.status(201) - .body(resWithData("REMINDER_ADDED", "리마인더 추가 완료", dto)); + .body(DefaultResponseDto.from("REMINDER_ADDED", "리마인더 추가 완료", dto)); } @ApiOperation("리마인더 조회") @@ -105,7 +101,6 @@ public ResponseEntity> addReminder( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/{reminderNo}") public ResponseEntity> readReminder( @PathVariable Long reminderNo){ @@ -115,12 +110,7 @@ public ResponseEntity> readReminder( ReminderResponseDto dto = reminderService.returnDto(reminder); return ResponseEntity.status(200) - .body(resWithData("REMINDER_FOUND", "리마인더 조회 완료", dto)); -// .body(DefaultResponseDto.builder() -// .responseCode("REMINDER_FOUND") -// .responseMessage("리마인더 조회 완료") -// .data(dto) -// .build()); + .body(DefaultResponseDto.from("REMINDER_FOUND", "리마인더 조회 완료", dto)); } @ApiOperation("리마인더 수정") @@ -135,7 +125,6 @@ public ResponseEntity> readReminder( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/{reminderNo}") public ResponseEntity> updateReminder( @RequestBody ReminderUpdateRequestDto reminderUpdateRequestDto, @@ -148,7 +137,7 @@ public ResponseEntity> updateReminder( ReminderResponseDto dto = reminderService.returnDto(reminder); return ResponseEntity.status(200) - .body(resWithData("REMINDER_UPDATED", "리마인더 수정 완료", dto)); + .body(DefaultResponseDto.from("REMINDER_UPDATED", "리마인더 수정 완료", dto)); } @ApiOperation("리마인더 삭제") @@ -163,7 +152,6 @@ public ResponseEntity> updateReminder( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping("/{reminderNo}") public ResponseEntity> deleteReminder( @PathVariable Long reminderNo){ @@ -176,7 +164,7 @@ public ResponseEntity> deleteReminder( reminderService.deleteReminder(reminderNo); return ResponseEntity.status(200) - .body(resWithoutData("REMINDER_DELETED", "리마인더 삭제 완료")); + .body(from("REMINDER_DELETED", "리마인더 삭제 완료")); } @ApiOperation("전체 리마인더 조회") @@ -189,14 +177,13 @@ public ResponseEntity> deleteReminder( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/admin") public ResponseEntity> readAll(){ List dto = reminderService.readAll(); return ResponseEntity.status(200) - .body(resWithData("REMINDERS_FOUND", "전체 리마인더 조회 완료", dto)); + .body(DefaultResponseDto.from("REMINDERS_FOUND", "전체 리마인더 조회 완료", dto)); } diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index c8f5103..a680046 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -10,7 +10,6 @@ import com.favor.favor.reminder.ReminderSimpleDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -18,8 +17,8 @@ import javax.validation.Valid; import java.util.List; -import static com.favor.favor.common.DefaultResponseDto.resWithData; -import static com.favor.favor.common.DefaultResponseDto.resWithoutData; +import static com.favor.favor.common.DefaultResponseDto.from; +import static com.favor.favor.common.DefaultResponseDto.from; @Api(tags = "User") @RestController @@ -45,7 +44,6 @@ public class UserController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping("/sign-up") public ResponseEntity> signUp( @RequestBody @Valid SignDto signDto @@ -56,7 +54,7 @@ public ResponseEntity> signUp( UserResponseDto dto = userService.signUp(signDto); return ResponseEntity.status(201) - .body(resWithData("USER_REGISTERED", "회원가입 완료", dto)); + .body(DefaultResponseDto.from("USER_REGISTERED", "회원가입 완료", dto)); } @ApiOperation("프로필 생성") @@ -75,7 +73,6 @@ public ResponseEntity> signUp( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PatchMapping("/profile") public ResponseEntity> createProfile( @RequestBody @Valid ProfileDto profileDto, @@ -88,7 +85,7 @@ public ResponseEntity> createProfile( UserResponseDto dto = userService.createProfile(profileDto, userNo); return ResponseEntity.status(200) - .body(resWithData("PROFILE_UPDATED", "프로필 생성 완료", dto)); + .body(DefaultResponseDto.from("PROFILE_UPDATED", "프로필 생성 완료", dto)); } @ApiOperation(value = "로그인") @@ -107,7 +104,6 @@ public ResponseEntity> createProfile( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping("/sign-in") public ResponseEntity> signIn( @RequestBody @Valid SignDto signDto @@ -116,7 +112,7 @@ public ResponseEntity> signIn( SignInResponseDto dto = userService.signIn(signDto); return ResponseEntity.status(201) - .body(resWithData("LOG_IN_SUCCESS", "로그인 완료", dto)); + .body(DefaultResponseDto.from("LOG_IN_SUCCESS", "로그인 완료", dto)); } @@ -132,7 +128,6 @@ public ResponseEntity> signIn( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping public ResponseEntity> readUser( @AuthenticationPrincipal User loginUser @@ -145,7 +140,7 @@ public ResponseEntity> readUser( UserResponseDto dto = userService.readUserInfo(userNo); return ResponseEntity.status(200) - .body(resWithData("USER_FOUND", "회원 조회 완료", dto)); + .body(DefaultResponseDto.from("USER_FOUND", "회원 조회 완료", dto)); } @ApiOperation("회원 수정") @@ -160,7 +155,6 @@ public ResponseEntity> readUser( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping public ResponseEntity> updateUser( @AuthenticationPrincipal User loginUser, @@ -172,7 +166,7 @@ public ResponseEntity> updateUser( UserResponseDto dto = userService.updateUser(userNo, userUpdateRequestDto); return ResponseEntity.status(200) - .body(resWithData("USER_UPDATED", "회원 수정 완료", dto)); + .body(DefaultResponseDto.from("USER_UPDATED", "회원 수정 완료", dto)); } @@ -188,7 +182,6 @@ public ResponseEntity> updateUser( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping public ResponseEntity> deleteUser( @AuthenticationPrincipal User loginUser){ @@ -203,7 +196,7 @@ public ResponseEntity> deleteUser( userService.deleteUser(userNo); return ResponseEntity.status(200) - .body(resWithoutData("USER_DELETED", "회원 탈퇴 완료")); + .body(from("USER_DELETED", "회원 탈퇴 완료")); } @ApiOperation("비밀번호 변경") @@ -218,7 +211,6 @@ public ResponseEntity> deleteUser( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @PatchMapping("/password") public ResponseEntity> updatePassword( @RequestBody @Valid UserUpdatePasswordRequestDto passwordDto){ @@ -228,7 +220,7 @@ public ResponseEntity> updatePassword( UserResponseDto dto = userService.updatePassword(passwordDto.getEmail(), passwordDto.getPassword()); return ResponseEntity.status(200) - .body(resWithData("PASSWORD_UPDATED", "비밀번호 변경 완료", dto)); + .body(DefaultResponseDto.from("PASSWORD_UPDATED", "비밀번호 변경 완료", dto)); } @@ -244,7 +236,6 @@ public ResponseEntity> updatePassword( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/reminders") public ResponseEntity> readReminderList( @AuthenticationPrincipal User loginUser){ @@ -256,7 +247,7 @@ public ResponseEntity> readReminderList( List dto = userService.readReminderList(userNo); return ResponseEntity.status(200) - .body(resWithData("REMINDERS_FOUND", "회원의 리마인더 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("REMINDERS_FOUND", "회원의 리마인더 전체 조회 완료", dto)); } @ApiOperation("회원의 리마인더 필터 조회") @ApiResponses(value={ @@ -270,7 +261,6 @@ public ResponseEntity> readReminderList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/reminders/{year}/{month}") public ResponseEntity> readReminderListByFMonthAndYear( @AuthenticationPrincipal User loginUser, @@ -284,7 +274,7 @@ public ResponseEntity> readReminderListByFMonthAndYea List dto = userService.readReminderListByFMonthAndYear(userNo, year, month); return ResponseEntity.status(200) - .body(resWithData("REMINDER_FOUND_BY_FILTER", "회원가입 완료", dto)); + .body(DefaultResponseDto.from("REMINDER_FOUND_BY_FILTER", "회원가입 완료", dto)); } @ApiOperation("회원의 선물 전체 조회") @@ -299,7 +289,6 @@ public ResponseEntity> readReminderListByFMonthAndYea @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/gifts") public ResponseEntity> readGiftList( @AuthenticationPrincipal User loginUser){ @@ -311,7 +300,7 @@ public ResponseEntity> readGiftList( List dto = userService.readGiftList(userNo); return ResponseEntity.status(200) - .body(resWithData("GIFTS_FOUND", "회원의 선물 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_FOUND", "회원의 선물 전체 조회 완료", dto)); } @ApiOperation("회원의 친구 전체 조회") @@ -326,7 +315,6 @@ public ResponseEntity> readGiftList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/friends") public ResponseEntity> readFriendList( @AuthenticationPrincipal User loginUser){ @@ -338,7 +326,7 @@ public ResponseEntity> readFriendList( List dto = userService.readFriendList(userNo); return ResponseEntity.status(200) - .body(resWithData("FRIENDS_FOUND", "회원의 친구 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("FRIENDS_FOUND", "회원의 친구 전체 조회 완료", dto)); } @ApiOperation("회원의 기념일 전체 조회") @@ -353,7 +341,6 @@ public ResponseEntity> readFriendList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/anniversaries") public ResponseEntity> readAnniversaryList( @AuthenticationPrincipal User loginUser){ @@ -365,7 +352,7 @@ public ResponseEntity> readAnniversaryList( List dto = userService.readAnniversaryList(userNo); return ResponseEntity.status(200) - .body(resWithData("ANNIVERSARY_FOUND", "회원의 기념일 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("ANNIVERSARY_FOUND", "회원의 기념일 전체 조회 완료", dto)); } @@ -379,14 +366,13 @@ public ResponseEntity> readAnniversaryList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/admin") public ResponseEntity> readAll(){ List dto = userService.readAll(); return ResponseEntity.status(200) - .body(resWithData("USERS_FOUND", "전체 회원 조회 완료", dto)); + .body(DefaultResponseDto.from("USERS_FOUND", "전체 회원 조회 완료", dto)); } @@ -402,7 +388,6 @@ public ResponseEntity> readAll(){ @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/gifts-by-name/{giftName}") public ResponseEntity> readGiftListByName ( @AuthenticationPrincipal User loginUser, @@ -415,7 +400,7 @@ public ResponseEntity> readGiftListByName ( List dto = userService.readGiftListByName(userNo, giftName); return ResponseEntity.status(200) - .body(resWithData("GIFTS_BY_NAME_FOUND", "이름으로 회원 선물 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_BY_NAME_FOUND", "이름으로 회원 선물 조회 완료", dto)); } @ApiOperation("카테고리로 회원 선물 조회") @@ -430,7 +415,6 @@ public ResponseEntity> readGiftListByName ( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/gifts-by-category/{category}") public ResponseEntity> readGiftListByCategory( @AuthenticationPrincipal User loginUser, @@ -442,7 +426,7 @@ public ResponseEntity> readGiftListByCategory( List dto = userService.readGiftListByCategory(userNo, giftCategory); return ResponseEntity.status(200) - .body(resWithData("GIFTS_BY_CATEGORY_FOUND", "카테고리로 회원 선물 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_BY_CATEGORY_FOUND", "카테고리로 회원 선물 조회 완료", dto)); } @ApiOperation("감정으로 회원 선물 조회") @@ -457,7 +441,6 @@ public ResponseEntity> readGiftListByCategory( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/gifts-by-emotion/{emotion}") public ResponseEntity> readGiftListByEmotion( @AuthenticationPrincipal User loginUser, @@ -469,7 +452,7 @@ public ResponseEntity> readGiftListByEmotion( List dto = userService.readGiftListByEmotion(userNo, emotion); return ResponseEntity.status(200) - .body(resWithData("GIFTS_BY_CATEGORY_FOUND", "감정으로 회원 선물 조회 완료", dto)); + .body(DefaultResponseDto.from("GIFTS_BY_CATEGORY_FOUND", "감정으로 회원 선물 조회 완료", dto)); } @ApiOperation("아이디로 회원 조회") @@ -484,7 +467,6 @@ public ResponseEntity> readGiftListByEmotion( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/{userId}") public ResponseEntity> readUserByUserId( @PathVariable("userId") String userId){ @@ -493,7 +475,7 @@ public ResponseEntity> readUserByUserId( UserResponseDto dto = userService.readUserInfo(user.getUserNo()); return ResponseEntity.status(200) - .body(resWithData("USER_BY_ID_FOUND", "아이디로 회원 조회 완료", dto)); + .body(DefaultResponseDto.from("USER_BY_ID_FOUND", "아이디로 회원 조회 완료", dto)); } @ApiOperation("유저가 준 선물 전체 조회") @@ -506,7 +488,6 @@ public ResponseEntity> readUserByUserId( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/gifts-given") public ResponseEntity> readGivenGiftList( @AuthenticationPrincipal User loginUser){ @@ -516,7 +497,7 @@ public ResponseEntity> readGivenGiftList( List dto = userService.readGivenGiftList(userNo); return ResponseEntity.status(200) - .body(resWithData("GIVEN_GIFTS_FOUND", "유저가 준 선물 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("GIVEN_GIFTS_FOUND", "유저가 준 선물 전체 조회 완료", dto)); } @ApiOperation("유저가 받은 선물 전체 조회") @@ -529,7 +510,6 @@ public ResponseEntity> readGivenGiftList( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/gifts-received") public ResponseEntity> readReceivedGiftList( @AuthenticationPrincipal User loginUser){ @@ -539,7 +519,7 @@ public ResponseEntity> readReceivedGiftList( List dto = userService.readReceivedGiftList(userNo); return ResponseEntity.status(200) - .body(resWithData("RECEIVED_GIFTS_FOUND", "유저가 받은 선물 전체 조회 완료", dto)); + .body(DefaultResponseDto.from("RECEIVED_GIFTS_FOUND", "유저가 받은 선물 전체 조회 완료", dto)); } } diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java index c298e57..6852378 100644 --- a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java @@ -7,7 +7,6 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -37,7 +36,6 @@ public class UserPhotoController { @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping("/profile") public ResponseEntity> updateUserProfilePhoto( @ModelAttribute MultipartFile file, @@ -50,7 +48,7 @@ public ResponseEntity> updateUserProfilePhoto( UserPhoto dto = user.getUserProfilePhoto(); return ResponseEntity.status(201) - .body(resWithData("USER_PROFILE_PHOTO_UPDATED", "회원 사진 수정 완료", dto)); + .body(DefaultResponseDto.from("USER_PROFILE_PHOTO_UPDATED", "회원 사진 수정 완료", dto)); } @ApiOperation("회원 프로필 사진 조회") @@ -65,7 +63,6 @@ public ResponseEntity> updateUserProfilePhoto( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/profile") public ResponseEntity> getUserProfilePhoto( @AuthenticationPrincipal User loginUser @@ -73,7 +70,7 @@ public ResponseEntity> getUserProfilePhoto( UserPhoto dto = userPhotoService.getUserProfilePhoto(loginUser.getUserNo()); return ResponseEntity.status(200) - .body(resWithData("USER_PROFILE_PHOTO_FOUND", "회원 사진 조회 완료", dto)); + .body(DefaultResponseDto.from("USER_PROFILE_PHOTO_FOUND", "회원 사진 조회 완료", dto)); } @ApiOperation("회원 프로필 사진 삭제") @@ -88,7 +85,6 @@ public ResponseEntity> getUserProfilePhoto( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping("/profile") public ResponseEntity> deleteUserProfilePhoto(@AuthenticationPrincipal User loginUser) { @@ -97,7 +93,7 @@ public ResponseEntity> deleteUserProfilePhoto(@Authen userPhotoService.deleteUserProfilePhoto(userNo); return ResponseEntity.status(200) - .body(resWithoutData("USER_PROFILE_PHOTO_DELETED", "회원 사진 삭제 완료")); + .body(from("USER_PROFILE_PHOTO_DELETED", "회원 사진 삭제 완료")); } @@ -115,7 +111,6 @@ public ResponseEntity> deleteUserProfilePhoto(@Authen @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.CREATED) @PostMapping("/background") public ResponseEntity> updateUserBackgroundPhoto( @ModelAttribute MultipartFile file, @@ -128,7 +123,7 @@ public ResponseEntity> updateUserBackgroundPhoto( UserPhoto dto = user.getUserBackgroundPhoto(); return ResponseEntity.status(201) - .body(resWithData("USER_BACKGROUND_PHOTO_UPDATED", "회원 배경 사진 수정 완료", dto)); + .body(DefaultResponseDto.from("USER_BACKGROUND_PHOTO_UPDATED", "회원 배경 사진 수정 완료", dto)); } @ApiOperation("회원 배경 사진 조회") @@ -143,7 +138,6 @@ public ResponseEntity> updateUserBackgroundPhoto( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @GetMapping("/background") public ResponseEntity> getUserBackgroundPhoto( @AuthenticationPrincipal User loginUser @@ -151,7 +145,7 @@ public ResponseEntity> getUserBackgroundPhoto( UserPhoto dto = userPhotoService.getUserBackgroundPhoto(loginUser.getUserNo()); return ResponseEntity.status(200) - .body(resWithData("USER_BACKGROUND_PHOTO_FOUND", "회원 배경 사진 조회 완료", dto)); + .body(DefaultResponseDto.from("USER_BACKGROUND_PHOTO_FOUND", "회원 배경 사진 조회 완료", dto)); } @ApiOperation("회원 배경 사진 삭제") @@ -166,7 +160,6 @@ public ResponseEntity> getUserBackgroundPhoto( @ApiResponse(code = 500, message = "SERVER_ERROR") }) - @ResponseStatus(HttpStatus.OK) @DeleteMapping("/background") public ResponseEntity> deleteUserBackgroundPhoto( @AuthenticationPrincipal User loginUser @@ -176,6 +169,6 @@ public ResponseEntity> deleteUserBackgroundPhoto( userPhotoService.deleteUserBackgroundPhoto(userNo); return ResponseEntity.status(200) - .body(resWithoutData("USER_BACKGROUND_PHOTO_DELETED", "회원 배경 사진 수정 완료")); + .body(from("USER_BACKGROUND_PHOTO_DELETED", "회원 배경 사진 수정 완료")); } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index cd68d5c..016ec68 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -301,7 +301,7 @@ public List readFriendList(Long userNo) { public List readAnniversaryList(Long userNo) { User user = findUserByUserNo(userNo); return user.getAnniversaryList().stream() - .map(AnniversaryResponseDto::new).collect(Collectors.toList()); + .map(AnniversaryResponseDto::from).collect(Collectors.toList()); } public List readFavorList(Long userNo) {