-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/sopt/seminar/domain/post/domain/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.sopt.seminar.domain.post.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.sopt.seminar.global.common.BaseTimeEntity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@Getter | ||
@Entity | ||
public class Category extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue | ||
@Column(name = "category_id") | ||
private Short id; | ||
private String content; | ||
@OneToMany | ||
@Builder.Default | ||
private List<Post> posts = new ArrayList<>(); | ||
|
||
public static Category createCategory(final String content) { | ||
return Category.builder() | ||
.content(content) | ||
.build(); | ||
} | ||
|
||
public void addPost(Post post) { | ||
posts.add(post); | ||
} | ||
|
||
public void removePost(Post post) { | ||
posts.remove(post); | ||
} | ||
|
||
public void updateContent(String content) { | ||
this.content = content; | ||
} | ||
} |