Skip to content

아티클에 대한 코멘트 #1

@pasudo123

Description

@pasudo123
  • 아티클에 대한 코멘트를 등록
  • 코멘트에 대해 코멘트를 등록 (대댓글)
  • 코멘트는 등록도 가능하지만, 수정 및 삭제도 가능

확인사항

아티클을 삭제했을 때, 댓글도 삭제
유저가 삭제되었을 때, 아티클 보관 (=> 댓글 보관)

궁금사항

  1. 코멘트 서비스 레이어에서 아티클에 대한 레파지토리를 오토와이어링하는게 맞는지? 혹은 코멘트 서비스 레이어에서 아티클 서비스를 호출하는게 맞는지. 아티클 서비스를 호출한다면, 따로 서비스 레이어 즉 클래스를 따로 만들어두는게 좋은지 (e.g. ArticleXXXService 형태??)

  2. 코멘트를 하나 등록함에 있어서 해당 dto 의 구성을 내부에 아티클 ID 를 하나 갖고 있는게 맞는 것인지?

2번과 3번에 궁금증이 생겨 질문을 하였다. 답변링크


  1. 편의 메소드는 어떻게 쓰는게 올바른 것인가?

  2. TestEntityManager 와 사용하는 베스트 프랙티스??

  3. 코멘트에 해당 유저에 대한 정보를 들고오면 fetch = FetchType.LAZY 하여도 N 명의 유저에 대해서 댓글 한번에 N 번의 유저를 조회한다. 이렇게 되면 페이징 처리를 하면 그 페이지의 사이즈만큼 댓글과 유저를 들고오니 괜찮을까?

@Getter
@NoArgsConstructor
public class ArticleOneResponseDto {

    private Long id;
    private String title;
    private ArticleType articleType;
    private String content;
    private LocalDate registrationDate;

    private List<CommentOneResponseDto> commentList = new ArrayList<>();

    public ArticleOneResponseDto(Article article){
        this.id = article.getId();
        this.title = article.getTitle();
        this.articleType = article.getArticleType();
        this.content = article.getContent();
        this.registrationDate = article.getRegistrationDate();

        if(article.getCommentList().size() == 0){
            return;
        }

        if(commentList == null){
            this.commentList = new ArrayList<>();
        }

        for(Comment comment : article.getCommentList()){
            commentList.add(new CommentOneResponseDto(comment));
        }
    }
}
@Getter
public class CommentOneResponseDto {

    private Long id;
    private String comment;
    private LocalDateTime createDateTime;
    private LocalDate createDate;

    @JsonProperty("writer")
    private WriterDto writerDto;

    public CommentOneResponseDto(Comment comment){
        this.id = comment.getId();
        this.comment = comment.getComment();
        this.createDateTime = comment.getCreatedDate();
        this.createDate = this.createDateTime.toLocalDate();

        this.writerDto = WriterDto.builder()
                .userRegistrationId(comment.getWriterUser().getUserRegistrationId())
                .name(comment.getWriterUser().getName())
                .profileImage(comment.getWriterUser().getProfileImage())
                .build();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    developmentTo Be / Completed (custom label)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions