패스트캠퍼스 환급챌린지 23일차 : 9개 도메인 프로젝트로 끝내는 백엔드 웹 개발 (Java/Spring) 초격차 패키지 Online 강의 후기
이태우(1990년)2025. 3. 27. 22:37
본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성하였습니다.
공부 시작 시각 인증
공부 시작 시각 인증
수강 인증 사진
수강 인증 사진
Post.java
package org.fastcampus.post.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.fastcampus.common.domain.*;
import org.fastcampus.post.domain.content.*;
import org.fastcampus.user.domain.User;
@Builder
@Getter
@AllArgsConstructor
public class Post {
private final Long id;
private final User author;
private final Content content;
private PostPublicationState state;
private final PositiveIntegerCounter likeCount;
public static Post createPost(Long id, User author, String content, PostPublicationState state) {
return new Post(id, author, new PostContent(content), state);
}
public static Post createDefaultPost(Long id, User author, String content) {
return new Post(id, author, new PostContent(content), PostPublicationState.PUBLIC);
}
public Post(Long id, User author, Content content, PostPublicationState state) {
if (author == null) {
throw new IllegalArgumentException("author should not be null");
}
if (content == null) {
throw new IllegalArgumentException("content should not be null or empty");
}
this.id = id;
this.author = author;
this.content = content;
this.state = state;
this.likeCount = new PositiveIntegerCounter();
}
public void updatePost(User user, String updateContent, PostPublicationState state) {
if (!this.author.equals(user)) {
throw new IllegalArgumentException("only author can update content");
}
this.content.updateContent(updateContent);
this.state = state;
}
public void like(User user) {
if (this.author.equals(user)) {
throw new IllegalArgumentException();
}
likeCount.increase();
}
public void unlike() {
likeCount.decrease();
}
public String getContent() {
return content.getContentText();
}
public int getLikeCount() {
return likeCount.getCount();
}
}
package org.fastcampus.post.repository.entity.post;
import jakarta.persistence.AttributeConverter;
import org.fastcampus.post.domain.content.PostPublicationState;
public class PostPublicationStateConverter implements AttributeConverter<PostPublicationState, String> {
@Override
public String convertToDatabaseColumn(PostPublicationState state) {
return state.name();
}
@Override
public PostPublicationState convertToEntityAttribute(String s) {
return PostPublicationState.valueOf(s);
}
}
Comment.java
package org.fastcampus.post.domain.comment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
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;
@Builder
@Getter
@AllArgsConstructor
public class Comment {
private final Long id;
private final Post post;
private final User author;
private final Content content;
private final 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 String getContent() {
return content.getContentText();
}
public Content getContentObject() {
return content;
}
public int getLikeCount() {
return likeCount.getCount();
}
}