Skip to content

Commit

Permalink
refactor: TempTalkPickDto 공통 필드 분리 (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanjaemo authored Nov 6, 2024
1 parent a7084af commit 58e9a4e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 55 deletions.
12 changes: 12 additions & 0 deletions src/main/java/balancetalk/talkpick/dto/BaseTalkPickFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,16 @@ public class BaseTalkPickFields {

@Schema(description = "출처 URL", example = "https://github.com/CHZZK-Study/Balance-Talk-Backend/issues/506")
private String sourceUrl;

public static BaseTalkPickFields from(String title, String content,
String optionA, String optionB,
String sourceUrl) {
return BaseTalkPickFields.builder()
.title(title)
.content(content)
.optionA(optionA)
.optionB(optionB)
.sourceUrl(sourceUrl)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import balancetalk.talkpick.domain.TalkPick;
import com.querydsl.core.annotations.QueryProjection;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import lombok.Data;

@Schema(description = "톡픽 검색 응답")
@Data
Expand Down
71 changes: 18 additions & 53 deletions src/main/java/balancetalk/talkpick/dto/TempTalkPickDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,30 @@
import balancetalk.member.domain.Member;
import balancetalk.talkpick.domain.TempTalkPick;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.util.List;

public class TempTalkPickDto {

@Schema(description = "톡픽 임시 저장 요청")
@Data
@AllArgsConstructor
public static class SaveTempTalkPickRequest {

@Schema(description = "제목", example = "제목")
@NotBlank
@Size(max = 50)
private String title;

@Schema(description = "본문 내용", example = "본문 내용")
@NotBlank
private String content;

@Schema(description = "선택지 A 이름", example = "선택지 A 이름")
@NotBlank
@Size(max = 10)
private String optionA;

@Schema(description = "선택지 B 이름", example = "선택지 B 이름")
@NotBlank
@Size(max = 10)
private String optionB;

@Schema(description = "출처 URL", example = "https://github.com/CHZZK-Study/Balance-Talk-Backend/issues/506")
private String sourceUrl;
private BaseTalkPickFields baseFields;

@Schema(description = "첨부한 이미지 ID 목록", example = "[214, 24]")
private List<Long> fileIds;

public TempTalkPick toEntity(Member member) {
return TempTalkPick.builder()
.title(title)
.content(content)
.optionA(optionA)
.optionB(optionB)
.sourceUrl(sourceUrl)
.title(baseFields.getTitle())
.content(baseFields.getContent())
.optionA(baseFields.getOptionA())
.optionB(baseFields.getOptionB())
.sourceUrl(baseFields.getSourceUrl())
.member(member)
.build();
}
Expand All @@ -61,38 +38,26 @@ public TempTalkPick toEntity(Member member) {
@AllArgsConstructor
public static class FindTempTalkPickResponse {

@Schema(description = "제목", example = "제목")
private String title;

@Schema(description = "본문 내용", example = "본문 내용")
private String content;

@Schema(description = "선택지 A 이름", example = "선택지 A 이름")
private String optionA;

@Schema(description = "선택지 B 이름", example = "선택지 B 이름")
private String optionB;

@Schema(description = "출처 URL", example = "https://github.com/CHZZK-Study/Balance-Talk-Backend/issues/506")
private String sourceUrl;
private BaseTalkPickFields baseFields;

@Schema(description = "톡픽 작성 시 첨부한 이미지 URL 목록",
example = "[" +
"\"https://picko-image.s3.ap-northeast-2.amazonaws.com/temp-talk-pick/9b4856fe-b624-4e54-ad80-a94e083301d2_czz.png\",\n" +
"\"https://picko-image.s3.ap-northeast-2.amazonaws.com/temp-talk-pick/fdcbd97b-f9be-45d1-b855-43f3fd17d5a6_6d588490-d5d4-4e47-b5d0-957e6ed4830b_prom.jpeg\"" +
"]")
example = "["
+ "\"https://picko-image.amazonaws.com/temp-talks/4e54-ad80-a94e083301d2_czz.png\",\n"
+ "\"https://picko-image.amazonaws.com/temp-talks/d5d4-4e47-b5d0-957e6ed4830b_prom.jpeg\""
+ "]")
private List<String> imgUrls;

@Schema(description = "첨부한 이미지 ID 목록", example = "[214, 24]")
private List<Long> fileIds;

public static FindTempTalkPickResponse from(TempTalkPick entity, List<String> imgUrls, List<Long> fileIds) {
return FindTempTalkPickResponse.builder()
.title(entity.getTitle())
.content(entity.getContent())
.optionA(entity.getOptionA())
.optionB(entity.getOptionB())
.sourceUrl(entity.getSourceUrl())
.baseFields(BaseTalkPickFields.from(
entity.getTitle(),
entity.getContent(),
entity.getOptionA(),
entity.getOptionB(),
entity.getSourceUrl()))
.imgUrls(imgUrls)
.fileIds(fileIds)
.build();
Expand Down

0 comments on commit 58e9a4e

Please sign in to comment.