Skip to content

Commit

Permalink
[feat] #5 카테고리 엔티티 클래스 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
SunwoongH committed Nov 9, 2023
1 parent a11b986 commit 0d08210
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/org/sopt/seminar/domain/post/domain/Category.java
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;
}
}

0 comments on commit 0d08210

Please sign in to comment.