패스트캠퍼스
패스트캠퍼스 환급챌린지 6일차 : 9개 도메인 프로젝트로 끝내는 백엔드 웹 개발 (Java/Spring) 초격차 패키지 Online 강의 후기
이태우(1990년)
2025. 3. 10. 22:18
본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성하였습니다.
공부 시작 시각 인증
수강 인증 사진
PositiveIntegerCounter.java
package org.fastcampus.common.domain;
public class PositiveIntegerCounter {
private int count;
public PositiveIntegerCounter() {
this.count = 0;
}
public void increase() {
this.count++;
}
public void decrease() {
if (count <= 0) {
return;
}
this.count--;
}
}
※ 기존 UserRelationCounter.java 파일은 삭제됨!
DatetimeInfo.java
package org.fastcampus.post.domain.common;
import java.time.LocalDateTime;
public class DatetimeInfo {
private boolean isEdited;
private LocalDateTime dateTime;
public DatetimeInfo() {
this.isEdited = false;
this.dateTime = LocalDateTime.now();
}
public void updateEditDatetime() {
this.isEdited = true;
this.dateTime = LocalDateTime.now();
}
public boolean isEdited() {
return isEdited;
}
public LocalDateTime getDateTime() {
return dateTime;
}
}
Content.java
package org.fastcampus.post.domain.content;
import org.fastcampus.post.domain.common.*;
public abstract class Content {
String contentText;
final DatetimeInfo datetimeInfo;
protected Content(String contentText) {
checkText(contentText);
this.contentText = contentText;
this.datetimeInfo = new DatetimeInfo();
}
public void updateContent(String updateContent) {
checkText(updateContent);
this.contentText = updateContent;
this.datetimeInfo.updateEditDatetime();
}
protected abstract void checkText(String contentText);
public String getContentText() {
return contentText;
}
}
Post.java
package org.fastcampus.post.domain;
import org.fastcampus.common.domain.*;
import org.fastcampus.post.domain.content.PostContent;
import org.fastcampus.post.domain.content.PostPublicationState;
import org.fastcampus.user.domain.User;
public class Post {
private final Long id;
private final User author;
private final PostContent content;
private final PositiveIntegerCounter likeCount;
private PostPublicationState state;
public Post(Long id, User author, PostContent content) {
if (author == null) {
throw new IllegalArgumentException();
}
this.id = id;
this.author = author;
this.content = content;
this.likeCount = new PositiveIntegerCounter();
this.state = PostPublicationState.PUBLIC;
}
public void like(User user) {
if (this.author.equals(user)) {
throw new IllegalArgumentException();
}
likeCount.increase();
}
public void unlike(User user) {
if (this.author.equals(user)) {
throw new IllegalArgumentException();
}
likeCount.decrease();
}
public void updatePost(User user, String updateContent, PostPublicationState state) {
if (!this.author.equals(user)) {
throw new IllegalArgumentException();
}
this.content.updateContent(updateContent);
this.state = state;
}
}
PostContent.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();
}
}
}
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.user.domain.User;
class Comment {
private final Long id;
private final Post post;
private final User author;
private final CommentContent content;
private final PositiveIntegerCounter likeCount;
public Comment(Long id, Post post, User author, CommentContent 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(User user) {
if (this.author.equals(user)) {
throw new IllegalArgumentException();
}
likeCount.decrease();
}
public void updateComment(User user, String updateContent) {
if (!this.author.equals(user)) {
throw new IllegalArgumentException();
}
this.content.updateContent(updateContent);
}
}
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();
}
}
}
※ 기존 User 클래스에서는 'public'으로 전환되었고, Counter 변수는 'common.domain' 패키지 내 Counter 클래스로 참조하는 것으로 변경되었다.