From 378a1bb3f775d1850e728ce897d2ee38560c5c18 Mon Sep 17 00:00:00 2001 From: 600gramSik Date: Sun, 10 Mar 2024 22:43:46 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20RespondRequest?= =?UTF-8?q?&Response=EC=97=90=EC=84=9C=20=EC=A7=81=EC=A0=91=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EB=A5=BC=20=EC=A0=9C=EC=99=B8=ED=95=98=EA=B3=A0=20id=EA=B0=92?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=8C=80=EC=8B=A0=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=98=A8=20=EC=9E=91=EC=97=85(#52)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AgreementController.java | 31 ------------------- .../controller/RespondController.java | 10 +++--- .../domain/petition/dto/RespondRequest.java | 6 ++-- .../domain/petition/dto/RespondResponse.java | 9 +++--- .../domain/petition/entity/Petition.java | 4 +++ .../domain/petition/entity/Respond.java | 3 +- .../repository/PetitionRepository.java | 2 -- .../repository/RespondRepository.java | 1 - 8 files changed, 18 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/com/smunity/petition/domain/petition/controller/AgreementController.java diff --git a/src/main/java/com/smunity/petition/domain/petition/controller/AgreementController.java b/src/main/java/com/smunity/petition/domain/petition/controller/AgreementController.java deleted file mode 100644 index 576a496..0000000 --- a/src/main/java/com/smunity/petition/domain/petition/controller/AgreementController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.smunity.petition.domain.petition.controller; - -import com.smunity.petition.domain.petition.dto.AgreementRequest; -import com.smunity.petition.domain.petition.dto.AgreementResponse; -import com.smunity.petition.domain.petition.dto.PetitionResponse; -import com.smunity.petition.domain.petition.service.AgreementService; -import com.smunity.petition.global.common.ApiResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequiredArgsConstructor -@RequestMapping("/api/v1/agreements") -public class AgreementController { - private final AgreementService agreementService; - -// @GetMapping -// public ApiResponse> getPetitionList() { -// List petitionLists = petitionService.getPetitions(); -// return ApiResponse.onSuccess(petitionLists); -// } - -// @PostMapping -// public ApiResponse createAgreement(@RequestBody AgreementRequest request) { -// -// } - - -} diff --git a/src/main/java/com/smunity/petition/domain/petition/controller/RespondController.java b/src/main/java/com/smunity/petition/domain/petition/controller/RespondController.java index 49de863..d2f1079 100644 --- a/src/main/java/com/smunity/petition/domain/petition/controller/RespondController.java +++ b/src/main/java/com/smunity/petition/domain/petition/controller/RespondController.java @@ -21,11 +21,11 @@ public ApiResponse getRespondDetail(@PathVariable return ApiResponse.onSuccess(respondDetail); } - @GetMapping - public ApiResponse> getRespondList() { - List respondLists = respondService.getResponds(); - return ApiResponse.onSuccess(respondLists); - } +// @GetMapping +// public ApiResponse> getRespondList() { +// List respondLists = respondService.getResponds(); +// return ApiResponse.onSuccess(respondLists); +// } @PostMapping public ApiResponse createRespond(@RequestBody RespondRequest.CreateRespondDTO request) { diff --git a/src/main/java/com/smunity/petition/domain/petition/dto/RespondRequest.java b/src/main/java/com/smunity/petition/domain/petition/dto/RespondRequest.java index 089d702..b73aa84 100644 --- a/src/main/java/com/smunity/petition/domain/petition/dto/RespondRequest.java +++ b/src/main/java/com/smunity/petition/domain/petition/dto/RespondRequest.java @@ -10,13 +10,13 @@ public class RespondRequest { @Getter public static class CreateRespondDTO { - private Petition petition; + private Long petitionId; private String content; - + //절대 엔티티 자체를 넣지 말자 public Respond toEntity() { return Respond.builder() - .petition(petition) + .petition(new Petition(petitionId)) .content(content) .build(); } diff --git a/src/main/java/com/smunity/petition/domain/petition/dto/RespondResponse.java b/src/main/java/com/smunity/petition/domain/petition/dto/RespondResponse.java index 488f2ef..4ad4649 100644 --- a/src/main/java/com/smunity/petition/domain/petition/dto/RespondResponse.java +++ b/src/main/java/com/smunity/petition/domain/petition/dto/RespondResponse.java @@ -15,14 +15,14 @@ public class RespondResponse { @AllArgsConstructor(access = AccessLevel.PRIVATE) public static class respondDetail { private Long id; - private Petition petition; + private Long petitionId; private Long userId; private LocalDateTime createdDate; private LocalDateTime modifiedDate; public static respondDetail from(Respond respond) { return respondDetail.builder() - .petition(respond.getPetition()) + .petitionId(respond.getPetition().getId()) .userId(respond.getUser().getId()) .createdDate(respond.getCreateDate()) .modifiedDate(respond.getModifyDate()) @@ -37,14 +37,13 @@ public static respondDetail from(Respond respond) { public static class respondList { private Long id; private Long userId; - private Petition petition; - + private Long petitionId; public static respondList from(Respond respond) { return respondList.builder() .id(respond.getId()) .userId(respond.getUser().getId()) - .petition(respond.getPetition()) + .petitionId(respond.getPetition().getId()) .build(); } public static List from(List responds) { diff --git a/src/main/java/com/smunity/petition/domain/petition/entity/Petition.java b/src/main/java/com/smunity/petition/domain/petition/entity/Petition.java index 39cf3a4..6a168d7 100644 --- a/src/main/java/com/smunity/petition/domain/petition/entity/Petition.java +++ b/src/main/java/com/smunity/petition/domain/petition/entity/Petition.java @@ -52,6 +52,10 @@ public void setUser(User user) { this.user.getPetitions().add(this); } + public Petition(Long id) { + this.id = id; + } + public void updatePetition(PetitionRequest.UpdateDTO updateDTO){ this.subject = updateDTO.getSubject(); this.content = updateDTO.getContent(); diff --git a/src/main/java/com/smunity/petition/domain/petition/entity/Respond.java b/src/main/java/com/smunity/petition/domain/petition/entity/Respond.java index c5221b0..4182329 100644 --- a/src/main/java/com/smunity/petition/domain/petition/entity/Respond.java +++ b/src/main/java/com/smunity/petition/domain/petition/entity/Respond.java @@ -23,7 +23,8 @@ public class Respond extends BaseEntity { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "petition_id") - private Petition petition; + Petition petition; + private String content; diff --git a/src/main/java/com/smunity/petition/domain/petition/repository/PetitionRepository.java b/src/main/java/com/smunity/petition/domain/petition/repository/PetitionRepository.java index 554591d..25342e6 100644 --- a/src/main/java/com/smunity/petition/domain/petition/repository/PetitionRepository.java +++ b/src/main/java/com/smunity/petition/domain/petition/repository/PetitionRepository.java @@ -15,6 +15,4 @@ public interface PetitionRepository extends JpaRepository { @Query("select p from Petition p") List findAllPetition(); - - List findAll(); } diff --git a/src/main/java/com/smunity/petition/domain/petition/repository/RespondRepository.java b/src/main/java/com/smunity/petition/domain/petition/repository/RespondRepository.java index 39d583d..90b2a8a 100644 --- a/src/main/java/com/smunity/petition/domain/petition/repository/RespondRepository.java +++ b/src/main/java/com/smunity/petition/domain/petition/repository/RespondRepository.java @@ -15,5 +15,4 @@ public interface RespondRepository extends JpaRepository { //RespondResponse.respondDetail -> Respond Respond findByPetitionId(@Param("petitionId") Long petitionId); - List findAll(); }