Skip to content

Commit

Permalink
entity -> dto 코드 변동
Browse files Browse the repository at this point in the history
  • Loading branch information
mintaek22 committed Dec 15, 2023
1 parent a4b2a81 commit 09e1296
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public ResponseEntity<ResGuestDto> getGuest(@PathVariable @Schema(description =

Guest guest = guestService.find(id);

return ResponseEntity.ok(guest.toResGuestDto());
return ResponseEntity.ok(new ResGuestDto(guest));
}
@Operation(summary = "게스트 정보 등록하기")
@PostMapping("/guest")
public ResponseEntity<ResGuestDto> registerGuest(@RequestBody ReqGuestDto reqGuestDto) {

Guest guest = guestService.registerGuest(reqGuestDto);

return ResponseEntity.ok(guest.toResGuestDto());
return ResponseEntity.ok(new ResGuestDto(guest));
}

@Operation(summary = "게스트 정보 수정하기")
Expand All @@ -43,7 +43,7 @@ public ResponseEntity<ResGuestDto> updateGuest(@PathVariable Long id, @RequestBo

Guest guest = guestService.editGuestInfo(id, reqGuestDto);

return ResponseEntity.ok(guest.toResGuestDto());
return ResponseEntity.ok(new ResGuestDto(guest));
}

@Operation(summary = "게스트 정보 삭제하기")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ResponseEntity<ResWorkerDto> getWorker(@PathVariable @Schema(description

Worker worker = workerService.find(id);

return ResponseEntity.ok(worker.toResWorkerDto());
return ResponseEntity.ok(new ResWorkerDto(worker));
}
@Operation(summary = "직원 정보 등록하기")
@PostMapping( value = "/worker" ,consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -40,7 +40,7 @@ public ResponseEntity<ResWorkerDto> registerWorker(@Parameter(description = "직

Worker worker = workerService.registerWorker(faceImg,reqWorkerDto);

return ResponseEntity.ok(worker.toResWorkerDto());
return ResponseEntity.ok(new ResWorkerDto(worker));
}

@Operation(summary = "직원 정보 수정하기")
Expand All @@ -49,7 +49,7 @@ public ResponseEntity<ResWorkerDto> updateWorker(@PathVariable @Schema(descripti
@RequestPart ReqWorkerDto reqWorkerDto) throws IOException {
Worker worker = workerService.editWorker(id,faceImg ,reqWorkerDto);

return ResponseEntity.ok(worker.toResWorkerDto());
return ResponseEntity.ok(new ResWorkerDto(worker));
}


Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/Han2m/portLogistics/user/domain/Guest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import com.Han2m.portLogistics.user.dto.req.ReqGuestDto;
import com.Han2m.portLogistics.user.dto.res.ResGuestDto;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
Expand All @@ -12,7 +11,6 @@
import lombok.experimental.SuperBuilder;

import java.time.LocalDate;
import java.util.stream.Collectors;

@Entity
@Getter
Expand Down Expand Up @@ -51,20 +49,4 @@ public void updateGuest(ReqGuestDto reqGuestDto){
this.date = reqGuestDto.getDate();

}

public ResGuestDto toResGuestDto(){
return ResGuestDto.builder().
personId(getPersonId()).
birth(getBirth()).
sex(getSex()).
name(getName()).
nationality(getNationality()).
phone(getPhone()).
goal(getGoal()).
reason(getReason()).
date(getDate()).
wharfs(getPersonWharfList().stream().map(PersonWharf::getWharf).map(Wharf::getName).collect(Collectors.toList())).
build();
}

}
16 changes: 1 addition & 15 deletions src/main/java/com/Han2m/portLogistics/user/domain/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.Han2m.portLogistics.admin.domain.Account;
import com.Han2m.portLogistics.user.dto.req.ReqWorkerDto;
import com.Han2m.portLogistics.user.dto.res.ResWorkerDto;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Entity
@Getter
Expand Down Expand Up @@ -43,17 +41,5 @@ public void updateWorker(ReqWorkerDto reqWorkerDto){
this.setBirth(reqWorkerDto.getBirth());
}

public ResWorkerDto toResWorkerDto(){
return ResWorkerDto.builder().
personId(getPersonId()).
birth(getBirth()).
faceUrl(getFaceUrl()).
sex(getSex()).
name(getName()).
nationality(getNationality()).
phone(getPhone()).
position(getPosition()).
wharfs(getPersonWharfList().stream().map(PersonWharf::getWharf).map(Wharf::getName).collect(Collectors.toList())).
build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.Han2m.portLogistics.user.dto.res;

import com.Han2m.portLogistics.user.domain.Guest;
import com.Han2m.portLogistics.user.domain.PersonWharf;
import com.Han2m.portLogistics.user.domain.Wharf;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -30,5 +33,17 @@ public class ResGuestDto{
private List<String> wharfs;



public ResGuestDto(Guest guest) {
this.nationality = guest.getNationality();
this.name = guest.getName();
this.sex = guest.getSex();
this.birth = guest.getBirth();
this.phone = guest.getPhone();
this.personId = guest.getPersonId();
this.date = guest.getDate();
this.reason = guest.getReason();
this.goal = guest.getGoal();
this.workerId = guest.getPersonId();
this.wharfs = guest.getPersonWharfList().stream().map(PersonWharf::getWharf).map(Wharf::getName).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.Han2m.portLogistics.user.dto.res;

import com.Han2m.portLogistics.user.domain.PersonWharf;
import com.Han2m.portLogistics.user.domain.Wharf;
import com.Han2m.portLogistics.user.domain.Worker;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -9,18 +12,29 @@

@Getter
@Setter
@AllArgsConstructor
@Builder
@AllArgsConstructor
public class ResWorkerDto{

private String nationality;
private String name;
private Boolean sex;
private String birth;
private String phone;
private Long personId;
private Long workerId;
private String position;
private String faceUrl;
private List<String> wharfs;

public ResWorkerDto(Worker worker) {
this.nationality = worker.getNationality();
this.name = worker.getName();
this.sex = worker.getSex();
this.birth = worker.getBirth();
this.phone = worker.getPhone();
this.workerId = worker.getPersonId();
this.position = worker.getPosition();
this.faceUrl = worker.getFaceUrl();
this.wharfs = worker.getPersonWharfList().stream().map(PersonWharf::getWharf).map(Wharf::getName).toList();
}
}

0 comments on commit 09e1296

Please sign in to comment.