Skip to content

Commit

Permalink
Refactor: 응답 DTO Record 타입으로 변경 (#159)
Browse files Browse the repository at this point in the history
* refactor: 응답 DTO 반환 클래스 Record로 변경

- 불변 클래스 record를 사용

* refactor: 응답 DTO 및 Generation Entity 필드를 래퍼클래스로 통일

* refactor: 정적 팩토리 메서드 네이밍 패턴에 따른 메서드 이름 변경

- 변수가 여러개 -> of
- 변수가 1개라면 -> from

* style: 코드 공백 조정
  • Loading branch information
Youthhing authored May 7, 2024
1 parent dbc6e05 commit 6cfa00a
Show file tree
Hide file tree
Showing 26 changed files with 98 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package cotato.csquiz.controller.dto;

import cotato.csquiz.domain.entity.Education;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class AllEducationResponse {
private Long educationId;
private String subject;
private int educationNumber;
private int sessionNumber;
public record AllEducationResponse(
Long educationId,
String subject,
Integer educationNumber,
Integer sessionNumber
) {

public static AllEducationResponse convertFromEducation(Education education) {
return AllEducationResponse.builder()
.educationId(education.getId())
.subject(education.getSubject())
.educationNumber(education.getNumber())
.sessionNumber(education.getSession().getNumber())
.build();
public static AllEducationResponse from(Education education) {
return new AllEducationResponse(
education.getId(),
education.getSubject(),
education.getNumber(),
education.getSession().getNumber()
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package cotato.csquiz.controller.dto.auth;

import cotato.csquiz.domain.entity.Member;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ApplyMemberInfoResponse {

private Long id;
private String name;
private String backFourNumber;
public record ApplyMemberInfoResponse(
Long id,
String name,
String backFourNumber
) {

public static ApplyMemberInfoResponse from(Member member, String backFourNumber) {
return new ApplyMemberInfoResponse(
Expand All @@ -23,4 +15,4 @@ public static ApplyMemberInfoResponse from(Member member, String backFourNumber)
backFourNumber
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package cotato.csquiz.controller.dto.auth;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class FindPasswordResponse {

private String accessToken;
}
public record FindPasswordResponse(
String accessToken
) {
public static FindPasswordResponse from(String accessToken) {
return new FindPasswordResponse(accessToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cotato.csquiz.controller.dto.education;

import lombok.Builder;
import lombok.Data;
import cotato.csquiz.domain.entity.Education;

@Data
@Builder
public class CreateEducationResponse {

private Long educationId;
public record CreateEducationResponse(
Long educationId
) {
public static CreateEducationResponse from(Education education) {
return new CreateEducationResponse(education.getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cotato.csquiz.controller.dto.education;

import cotato.csquiz.domain.entity.Education;
import cotato.csquiz.domain.enums.EducationStatus;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class FindEducationStatusResponse {

private EducationStatus status;
public record FindEducationStatusResponse(
EducationStatus status
) {
public static FindEducationStatusResponse from(Education education) {
return new FindEducationStatusResponse(education.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cotato.csquiz.controller.dto.generation;

import lombok.Builder;
import lombok.Data;
import cotato.csquiz.domain.entity.Generation;

@Data
@Builder
public class AddGenerationResponse {

private Long generationId;
public record AddGenerationResponse(
Long generationId
) {
public static AddGenerationResponse from(Generation generation) {
return new AddGenerationResponse(generation.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public record GenerationInfoResponse(
Long generationId,
int generationNumber,
int sessionCount
Integer generationNumber,
Integer sessionCount
) {

public static GenerationInfoResponse from(Generation generation) {
Expand All @@ -15,4 +15,4 @@ public static GenerationInfoResponse from(Generation generation) {
generation.getSessionCount()
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
import cotato.csquiz.domain.entity.Member;
import cotato.csquiz.domain.enums.MemberPosition;
import cotato.csquiz.domain.enums.MemberRole;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MemberEnrollInfoResponse {
public record MemberEnrollInfoResponse(
Long memberId,
String memberName,
MemberPosition position,
Integer generationNumber,
MemberRole role
) {

private Long memberId;
private String memberName;
private MemberPosition position;
private int generationNumber;
private MemberRole role;

public static MemberEnrollInfoResponse from(Member member) {
return new MemberEnrollInfoResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public record MemberMyPageInfoResponse(
Long memberId,
String email,
String name,
int generationNumber,
Integer generationNumber,
MemberPosition memberPosition,
String phoneNumber
) {
public static MemberMyPageInfoResponse from(Member member, String originPhoneNumber) {
public static MemberMyPageInfoResponse of(Member member, String originPhoneNumber) {
return new MemberMyPageInfoResponse(
member.getId(),
member.getEmail(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record HallOfFameInfo(
String name,
long count
) {
public static HallOfFameInfo from(Member member, long count) {
public static HallOfFameInfo of(Member member, long count) {
return new HallOfFameInfo(
member.getId(),
member.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record MyPageMemberInfoResponse(
Long memberId,
String memberName,
String phoneNumber,
int generationNumber,
Integer generationNumber,
MemberRole memberRole,
MemberPosition memberPosition
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class FindMultipleQuizResponse extends QuizResponse {

private List<ChoiceResponse> choices;

private FindMultipleQuizResponse(Long id, int number, String question, String image, List<ChoiceResponse> choices) {
private FindMultipleQuizResponse(Long id, Integer number, String question, String image,
List<ChoiceResponse> choices) {
super(id, number, QuizType.MULTIPLE_QUIZ, question, image);
this.choices = choices;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public record QuizInfoInCsQuizResponse(
Long quizId,
QuizType quizType,
int quizNumber,
Integer quizNumber,
String question,
List<String> answer
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class QuizResponse {

private Long id;
private int number;
private Integer number;
private QuizType quizType;
private String question;
private String image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public record QuizResultInfo(
Long quizId,
int quizNumber,
Integer quizNumber,
Long scorerId,
String scorerName,
String backFourNumber
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package cotato.csquiz.controller.dto.session;

import lombok.Builder;
import lombok.Data;
import cotato.csquiz.domain.entity.Session;

@Data
@Builder
public class AddSessionResponse {
private Long sessionId;
private int sessionNumber;
public record AddSessionResponse(
Long sessionId,
Integer sessionNumber
) {
public static AddSessionResponse from(Session session) {
return new AddSessionResponse(
session.getId(),
session.getNumber()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public record CsEducationOnSessionNumberResponse(
Long sessionId,
int sessionNumber
Integer sessionNumber
) {
public static CsEducationOnSessionNumberResponse from(Session session) {
return new CsEducationOnSessionNumberResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public record SessionListResponse(
Long sessionId,
int sessionNumber,
Integer sessionNumber,
String photoUrl,
String description,
Long generationId,
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/cotato/csquiz/domain/entity/Generation.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package cotato.csquiz.domain.entity;

import cotato.csquiz.global.entity.BaseTimeEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.time.LocalDate;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -26,10 +23,10 @@ public class Generation extends BaseTimeEntity {
private Long id;

@Column(name = "generation_number", unique = true, nullable = false)
private int number;
private Integer number;

@Column(name = "generation_session_count")
private int sessionCount;
@Column(name = "generation_session_count", nullable = false)
private Integer sessionCount;

@Column(name = "generation_start_date")
private LocalDate startDate;
Expand All @@ -41,20 +38,20 @@ public class Generation extends BaseTimeEntity {
private Boolean isRecruit;

@Builder
public Generation(int number, int sessionCount ,LocalDate startDate, LocalDate endDate) {
public Generation(Integer number, Integer sessionCount, LocalDate startDate, LocalDate endDate) {
this.number = number;
this.sessionCount = sessionCount;
this.startDate = startDate;
this.endDate = endDate;
isRecruit = false;
}

public void changeRecruit(boolean isRecruit){
public void changeRecruit(Boolean isRecruit) {
this.isRecruit = isRecruit;
}

public void changePeriod(LocalDate startDate, LocalDate endDate) {
this.startDate=startDate;
this.startDate = startDate;
this.endDate = endDate;
}
}
4 changes: 1 addition & 3 deletions src/main/java/cotato/csquiz/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ public FindPasswordResponse verifyPasswordCode(String email, String code) {
String role = findMember.getRole().getKey();

Token token = jwtTokenProvider.createToken(findMember.getId(), role);
return FindPasswordResponse.builder()
.accessToken(token.getAccessToken())
.build();
return FindPasswordResponse.from(token.getAccessToken());
}

public MemberEmailResponse findMemberEmail(String name, String phoneNumber) {
Expand Down
Loading

0 comments on commit 6cfa00a

Please sign in to comment.