-
Notifications
You must be signed in to change notification settings - Fork 0
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] Anniversary 리팩터링 #86
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
package com.favor.favor.anniversary; | ||
|
||
import com.favor.favor.common.enums.AnniversaryCategory; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AllArgsConstructor가 있음에도 사용하지 않았기 때문에 어노테이션을 삭제한거고, |
||
public class AnniversaryResponseDto { | ||
private Long anniversaryNo; | ||
private String anniversaryTitle; | ||
|
@@ -21,14 +19,27 @@ public class AnniversaryResponseDto { | |
private AnniversaryCategory anniversaryCategory; | ||
|
||
@Builder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리팩토링 이유 : 파라미터 1개인데 빌더 사용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 파라미터가 1개인데 빌더 어노테이션을 사용해서 리팩토링을 진행한게 아니라, 그래서 private 접근 제한자로 모든 매개변수에 대한 생성자를 정의하고, |
||
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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기능은 같은 것으로 알고 있는데
가독성 위한 리팩토링 맞을까?
다른 이점이 있다면 알려줘!
AnniversaryController
외 다른 컨트롤러는 아직status
를 사용하고 있어서 물어봤어There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created도 메소드가 존재하는데
찾아보면 created(URI location)이라고 나와있어
이 부분은 created라는 메소드가 매개변수로 body를 요구하지 않는 걸 확인할 수 있어
이때 location은 header에 location=""에 해당해서 응답 DTO를 담아서 반환해주는 우리 코드에서는 적용하려면
ResponseEntity.created(null).body(~); 로 작성해야해
그래서 200 OK와 같은 경우에는 ok(T body)로 더 줄일 수 있어서 줄였고
201 CREATED는 그대로 놔둔거지