본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성하였습니다.
공부 시작 시각 인증
수강 인증 사진
4일차 이어서 이번에는 댓글 관련 초안 설계 실습한다.
- 댓글의 정보 입력 받기
- 유저 유효성 확인 - 존재하는 지
- 게시글 유효성 확인 - 존재하는 지
- 댓글 유효성 확인
- 댓글 DB 저장
학습 인증샷
Post.java
package org.fastcampus.post.domain;
import org.fastcampus.post.domain.content.PostContent;
import org.fastcampus.user.domain.User;
public class Post {
private final Long id;
private final User author;
private final PostContent content;
public Post(Long id, User author, PostContent content) {
if (author == null) {
throw new IllegalArgumentException();
}
this.id = id;
this.author = author;
this.content = content;
}
}
Content.java
package org.fastcampus.post.domain.content;
public abstract class Content {
String contentText;
protected Content(String contentText) {
checkText(contentText);
this.contentText = contentText;
}
protected abstract void checkText(String contentText);
public String getContentText() {
return contentText;
}
}
PostComment.java
package org.fastcampus.post.domain.content;
public class PostContent extends Content {
private static final int MIN_POST_LENGTH = 5;
private static final int MAX_POST_LENGTH = 500;
PostContent(String content) {
super(content);
}
@Override
protected void checkText(String contentText) {
if (contentText == null || contentText.isEmpty()) {
throw new IllegalArgumentException();
}
if (contentText.length() < MIN_POST_LENGTH && contentText.length() > MAX_POST_LENGTH) {
throw new IllegalArgumentException();
}
}
}
CommentContent.java
package org.fastcampus.post.domain.content;
public class CommentContent extends Content {
private static final int MAX_COMMENT_LENGTH = 100;
public CommentContent(String content) {
super(content);
}
@Override
protected void checkText(String contentText) {
if (contentText == null || contentText.isEmpty()) {
throw new IllegalArgumentException();
}
if (MAX_COMMENT_LENGTH < contentText.length()) {
throw new IllegalArgumentException();
}
}
}
Comment.java
package org.fastcampus.post.domain.comment;
import org.fastcampus.post.domain.Post;
import org.fastcampus.post.domain.content.Content;
import org.fastcampus.user.domain.User;
class Comment {
private final Long id;
private final Post post;
private final User author;
private final Content content;
public Comment(Long id, Post post, User author, Content content) {
if (author == null) {
throw new IllegalArgumentException();
}
if (post == null) {
throw new IllegalArgumentException();
}
if (content == null) {
throw new IllegalArgumentException();
}
this.id = id;
this.post = post;
this.author = author;
this.content = content;
}
}