패스트캠퍼스 환급챌린지 16일차 : 9개 도메인 프로젝트로 끝내는 백엔드 웹 개발 (Java/Spring) 초격차 패키지 Online 강의 후기
이태우(1990년)2025. 3. 20. 19:01
본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성하였습니다.
공부 시작 시각 인증
공부 시작 시각 인증
수강 인증 사진
수강 인증 사진
Comment.java
package org.fastcampus.post.domain.comment;
import org.fastcampus.common.domain.*;
import org.fastcampus.post.domain.Post;
import org.fastcampus.post.domain.content.CommentContent;
import org.fastcampus.post.domain.content.Content;
import org.fastcampus.user.domain.User;
public class Comment {
private final Long id;
private final Post post;
private final User author;
private final Content content;
private PositiveIntegerCounter likeCount;
public static Comment createComment(Post post, User author, String content) {
return new Comment(null, post, author, new CommentContent(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;
this.likeCount = new PositiveIntegerCounter();
}
public void like(User user) {
if (this.author.equals(user)) {
throw new IllegalArgumentException();
}
likeCount.increase();
}
public void unlike() {
likeCount.decrease();
}
public void updateComment(User user, String updateContent) {
if (!this.author.equals(user)) {
throw new IllegalArgumentException();
}
this.content.updateContent(updateContent);
}
public int getLikeCount() {
return likeCount.getCount();
}
public String getContent() {
return content.getContentText();
}
}