728x90
public static List<ReplyResponseDto> toDtoList(List<Reply> replys) {
NestedConvertHelper helper = NestedConvertHelper.newInstance(
replys,
r -> new ReplyResponseDto(r.getId(), r.isDeleted() ? null : r.getContent(), r.isDeleted() ? null : ParticipantResponseDto.toDto(r.getParticipant()), r.getCreatedDate(), new ArrayList<>()),
r -> r.getParent(),
r -> r.getId(),
d -> d.getChildren());
return helper.convert();
에서 ParticipantResponseDto.toDto 부분에 값을 못 받아와서
Participant에 빌드 패턴으로 만들어서
값 넣어주고 아래와 같이 불러온 다음.
아래와 같이 만들어 준 다음.
public ParticipantResponseDto(Participant entity) {
this.id = entity.getId();
this.event = entity.getEvent();
this.user = entity.getUser();
this.name = entity.getName();
this.state = entity.getState();
this.createDate = entity.getCreatedDate();
this.modifiedDate = entity.getModifiedDate();
}
public static List<ReplyResponseDto> toDtoList(List<Reply> replys) {
NestedConvertHelper helper = NestedConvertHelper.newInstance(
replys,
r -> new ReplyResponseDto(r.getId(), r.isDeleted() ? null : r.getContent(), r.isDeleted() ? null : new ParticipantResponseDto(r.getParticipant()), r.getCreatedDate(), new ArrayList<>()),
r -> r.getParent(),
r -> r.getId(),
d -> d.getChildren());
return helper.convert();
}
new ParticipantResponseDto(r.getParticipant())
만들어주어서 해결함
# api 테스트 할 때 사용
http://localhost:8080/api/v1/reply?opinionId=1 ==> get 조회
{
"title" : "제목
"content" : "내용",
}
생성
http://localhost:8080/api/v1/reply
{
"content" : "hi",
"participantId" : 1,
"opinionId" : 1,
"parentId" : 2
}
삭제
http://localhost:8080/api/v1/reply/9
'개발 > JAVA' 카테고리의 다른 글
[JAVA] Generic 정의 (0) | 2022.11.29 |
---|---|
Java 대용량 데이터 DB 처리 방법, batch (0) | 2022.11.24 |
return 필요 없으면 void로 하기 (0) | 2022.11.14 |
private final 변수가 다른 곳에서 먼저 생성자로 사용하고 있을 때? (0) | 2022.10.31 |
Files 관련 StandardCopyOption 정의 (0) | 2022.10.20 |