From 16966b00c1afa9286f4f7b4834a06cb9ff729fa5 Mon Sep 17 00:00:00 2001 From: AN-SOHYEON Date: Fri, 19 Jan 2024 17:43:49 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20static=20method=20=EC=88=98=EC=A0=95=20(#175)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel/jdon/faq/dto/request/CreateFaqRequest.java | 9 ++++++--- .../main/java/kernel/jdon/faq/service/FaqService.java | 11 +++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/module-api/src/main/java/kernel/jdon/faq/dto/request/CreateFaqRequest.java b/module-api/src/main/java/kernel/jdon/faq/dto/request/CreateFaqRequest.java index 0ef67b40f..a37705cb4 100644 --- a/module-api/src/main/java/kernel/jdon/faq/dto/request/CreateFaqRequest.java +++ b/module-api/src/main/java/kernel/jdon/faq/dto/request/CreateFaqRequest.java @@ -1,17 +1,20 @@ package kernel.jdon.faq.dto.request; import kernel.jdon.faq.domain.Faq; +import lombok.AccessLevel; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class CreateFaqRequest { private String title; private String content; - public static Faq toEntity(CreateFaqRequest createFaqRequest) { + public Faq toEntity() { return Faq.builder() - .title(createFaqRequest.title) - .content(createFaqRequest.content) + .title(this.title) + .content(this.content) .build(); } } diff --git a/module-api/src/main/java/kernel/jdon/faq/service/FaqService.java b/module-api/src/main/java/kernel/jdon/faq/service/FaqService.java index 3a6d30b3d..eedfc609b 100644 --- a/module-api/src/main/java/kernel/jdon/faq/service/FaqService.java +++ b/module-api/src/main/java/kernel/jdon/faq/service/FaqService.java @@ -1,10 +1,5 @@ package kernel.jdon.faq.service; -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import kernel.jdon.faq.domain.Faq; import kernel.jdon.faq.dto.request.CreateFaqRequest; import kernel.jdon.faq.dto.request.UpdateFaqRequest; @@ -16,6 +11,10 @@ import kernel.jdon.faq.repository.FaqRepository; import kernel.jdon.global.exception.ApiException; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; @Service @Transactional(readOnly = true) @@ -30,7 +29,7 @@ private Faq findById(Long faqId) { @Transactional public CreateFaqResponse create(CreateFaqRequest createFaqRequest) { - Faq savedFaq = faqRepository.save(CreateFaqRequest.toEntity(createFaqRequest)); + Faq savedFaq = faqRepository.save(createFaqRequest.toEntity()); return CreateFaqResponse.of(savedFaq.getId()); }