Skip to content

Commit 1e5a8b7

Browse files
committed
refactor: builder 패턴으로 변경
1 parent 8768c8c commit 1e5a8b7

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/main/java/com/example/log4u/domain/reports/dto/ReportCreateRequestDto.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public record ReportCreateRequestDto(
1515
String content
1616
) {
1717
public Report toEntity(Report.ReportTargetType reportTargetType, Long targetId){
18-
return new Report(reportTargetType, reportType, targetId, content);
18+
return Report.builder()
19+
.reportTargetType(reportTargetType)
20+
.reportType(reportType)
21+
.reportTargetId(targetId)
22+
.content(content)
23+
.build();
1924
}
2025
}

src/main/java/com/example/log4u/domain/reports/entity/Report.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package com.example.log4u.domain.reports.entity;
22

3-
import com.example.log4u.domain.reports.dto.ReportCreateRequestDto;
43
import com.example.log4u.domain.reports.reportType.ReportType;
54
import jakarta.persistence.*;
65
import lombok.*;
76
import org.springframework.data.annotation.CreatedDate;
87
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
9-
108
import java.time.LocalDateTime;
119

12-
@Entity
10+
@Builder
1311
@Getter
14-
@EntityListeners(AuditingEntityListener.class)
1512
@NoArgsConstructor(access = AccessLevel.PROTECTED)
13+
@AllArgsConstructor(access = AccessLevel.PACKAGE)
14+
15+
@Entity
16+
@EntityListeners(AuditingEntityListener.class)
1617
public class Report {
1718
public enum ReportTargetType{
1819
DIARY,
@@ -35,11 +36,4 @@ public enum ReportTargetType{
3536

3637
@CreatedDate
3738
private LocalDateTime createdAt;
38-
39-
public Report(ReportTargetType reportTargetType, ReportType reportType, Long reportTargetId, String content) {
40-
this.reportTargetType = reportTargetType;
41-
this.reportType = reportType;
42-
this.reportTargetId = reportTargetId;
43-
this.content = content;
44-
}
4539
}

src/main/java/com/example/log4u/domain/supports/dto/SupportCreateRequestDto.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public record SupportCreateRequestDto(
1919
String content
2020
) {
2121
public Support toEntity(){
22-
return new Support(supportType, title, content);
22+
return Support.builder()
23+
.supportType(supportType)
24+
.title(title)
25+
.content(content)
26+
.build();
2327
}
2428
}

src/main/java/com/example/log4u/domain/supports/entity/Support.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
import com.example.log4u.domain.supports.supportType.SupportType;
44
import jakarta.persistence.*;
5-
import lombok.Getter;
6-
import lombok.NoArgsConstructor;
5+
import lombok.*;
76
import org.springframework.data.annotation.CreatedDate;
87
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
98

109
import java.time.LocalDateTime;
10+
11+
@Builder
1112
@Getter
12-
@NoArgsConstructor
13+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
14+
@AllArgsConstructor(access = AccessLevel.PACKAGE)
15+
1316
@Entity
1417
@EntityListeners(AuditingEntityListener.class)
1518
public class Support {
@@ -29,10 +32,4 @@ public class Support {
2932
private String answerContent;
3033

3134
private LocalDateTime answeredAt;
32-
33-
public Support (SupportType supportType, String title, String content) {
34-
this.supportType = supportType;
35-
this.title = title;
36-
this.content = content;
37-
}
3835
}

0 commit comments

Comments
 (0)