Skip to content

Commit

Permalink
♻️ refactor: RespondRequest&Response에서 직접적인 엔티티 추가를 제외하고 id값으로 대신 받아온…
Browse files Browse the repository at this point in the history
… 작업(#52)
  • Loading branch information
600gramSik committed Mar 10, 2024
1 parent f755ce9 commit 378a1bb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 48 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public ApiResponse<RespondResponse.respondDetail> getRespondDetail(@PathVariable
return ApiResponse.onSuccess(respondDetail);
}

@GetMapping
public ApiResponse<List<RespondResponse.respondList>> getRespondList() {
List<RespondResponse.respondList> respondLists = respondService.getResponds();
return ApiResponse.onSuccess(respondLists);
}
// @GetMapping
// public ApiResponse<List<RespondResponse.respondList>> getRespondList() {
// List<RespondResponse.respondList> respondLists = respondService.getResponds();
// return ApiResponse.onSuccess(respondLists);
// }

@PostMapping
public ApiResponse<RespondResponse.respondDetail> createRespond(@RequestBody RespondRequest.CreateRespondDTO request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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<respondList> from(List<Respond> responds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ public interface PetitionRepository extends JpaRepository<Petition, Long> {

@Query("select p from Petition p")
List<PetitionResponse.petitionList> findAllPetition();

List<Petition> findAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public interface RespondRepository extends JpaRepository<Respond, Long> {
//RespondResponse.respondDetail -> Respond
Respond findByPetitionId(@Param("petitionId") Long petitionId);

List<Respond> findAll();
}

0 comments on commit 378a1bb

Please sign in to comment.