From 8a1cdda040f4e75b2b3a115cb8c43b9c04b73e21 Mon Sep 17 00:00:00 2001 From: ssunnykku <108388578+ssunnykku@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:31:14 +0900 Subject: [PATCH 1/5] =?UTF-8?q?refactor:=20contents=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/controller/ContentController.java | 4 +-- .../wanted/media/content/domain/Content.java | 25 +++++++++++++------ .../content/repository/ContentRepository.java | 2 +- .../java/wanted/media/user/domain/User.java | 8 +----- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/wanted/media/content/controller/ContentController.java b/src/main/java/wanted/media/content/controller/ContentController.java index 025e10a..00583de 100644 --- a/src/main/java/wanted/media/content/controller/ContentController.java +++ b/src/main/java/wanted/media/content/controller/ContentController.java @@ -1,9 +1,9 @@ package wanted.media.content.controller; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -@Controller +@RestController @RequestMapping("/contents") public class ContentController { } diff --git a/src/main/java/wanted/media/content/domain/Content.java b/src/main/java/wanted/media/content/domain/Content.java index 0ef7ad2..3f4ae85 100644 --- a/src/main/java/wanted/media/content/domain/Content.java +++ b/src/main/java/wanted/media/content/domain/Content.java @@ -3,8 +3,10 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.*; - +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -14,33 +16,40 @@ @Entity @Getter -@Setter -@Table(name="contents") +@Table(name = "contents") @NoArgsConstructor @AllArgsConstructor @Builder -@ToString @EntityListeners(AuditingEntityListener.class) public class Content { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "content_id", nullable = false) private Long id; + private Long likeCount; + @Size(max = 50) - private String type; + private Enum type; + @Size(max = 150) private String title; + private String content; + private String hashtags; + private Long viewCount; + private Long shareCount; + @LastModifiedDate private LocalDateTime updatedAt; + @CreatedDate private LocalDateTime createdAt; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") @NotNull private User user; diff --git a/src/main/java/wanted/media/content/repository/ContentRepository.java b/src/main/java/wanted/media/content/repository/ContentRepository.java index 06eaa31..510a593 100644 --- a/src/main/java/wanted/media/content/repository/ContentRepository.java +++ b/src/main/java/wanted/media/content/repository/ContentRepository.java @@ -3,5 +3,5 @@ import org.springframework.data.jpa.repository.JpaRepository; import wanted.media.content.domain.Content; -public interface ContentRepository extends JpaRepository { +public interface ContentRepository extends JpaRepository { } diff --git a/src/main/java/wanted/media/user/domain/User.java b/src/main/java/wanted/media/user/domain/User.java index 0c4cca0..c5f60d5 100644 --- a/src/main/java/wanted/media/user/domain/User.java +++ b/src/main/java/wanted/media/user/domain/User.java @@ -4,24 +4,18 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.NoArgsConstructor; -import wanted.media.content.domain.Content; -import java.util.ArrayList; -import java.util.List; import java.util.UUID; @NoArgsConstructor @AllArgsConstructor @Builder @Entity -@Table(name="users") +@Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.UUID) @Column(name = "userId", nullable = false) private UUID userId; - @OneToMany(mappedBy = "user") - @Builder.Default - List interviews = new ArrayList<>(); } From e831bcd1ce5b41720badf0b3eacb2d39306cd96a Mon Sep 17 00:00:00 2001 From: ssunnykku <108388578+ssunnykku@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:46:58 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor:=20type=20=EC=97=B4=EA=B1=B0?= =?UTF-8?q?=ED=98=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/wanted/media/content/domain/Content.java | 5 +++-- src/main/java/wanted/media/content/domain/Type.java | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 src/main/java/wanted/media/content/domain/Type.java diff --git a/src/main/java/wanted/media/content/domain/Content.java b/src/main/java/wanted/media/content/domain/Content.java index 3f4ae85..49dbc32 100644 --- a/src/main/java/wanted/media/content/domain/Content.java +++ b/src/main/java/wanted/media/content/domain/Content.java @@ -29,8 +29,9 @@ public class Content { private Long likeCount; - @Size(max = 50) - private Enum type; + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private Type type; @Size(max = 150) private String title; diff --git a/src/main/java/wanted/media/content/domain/Type.java b/src/main/java/wanted/media/content/domain/Type.java new file mode 100644 index 0000000..539f7fa --- /dev/null +++ b/src/main/java/wanted/media/content/domain/Type.java @@ -0,0 +1,5 @@ +package wanted.media.content.domain; + +public enum Type { + FACEBOOK, TWITTER, INSTAGRAM, THREADS; +} From cddb317adf08ddfff67c94fe6a7441520a637912 Mon Sep 17 00:00:00 2001 From: ssunnykku <108388578+ssunnykku@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:49:19 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20content=20entity=20anotation=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/wanted/media/content/domain/Content.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/wanted/media/content/domain/Content.java b/src/main/java/wanted/media/content/domain/Content.java index 49dbc32..2d908d0 100644 --- a/src/main/java/wanted/media/content/domain/Content.java +++ b/src/main/java/wanted/media/content/domain/Content.java @@ -27,6 +27,7 @@ public class Content { @Column(name = "content_id", nullable = false) private Long id; + @Column(name = "like_count") private Long likeCount; @Enumerated(EnumType.STRING) @@ -34,12 +35,14 @@ public class Content { private Type type; @Size(max = 150) + @Column(nullable = false) private String title; private String content; private String hashtags; + private Long viewCount; private Long shareCount; From d2875c7ae24c17e57abd40d6c56fb55376e665c4 Mon Sep 17 00:00:00 2001 From: ssunnykku <108388578+ssunnykku@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:17:06 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20Entity=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content: NoArgsConstructor AccessLevel 설정 User: user_id 컬럼명 변경 --- src/main/java/wanted/media/content/domain/Content.java | 8 ++------ src/main/java/wanted/media/user/domain/User.java | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/wanted/media/content/domain/Content.java b/src/main/java/wanted/media/content/domain/Content.java index 2d908d0..fed9efd 100644 --- a/src/main/java/wanted/media/content/domain/Content.java +++ b/src/main/java/wanted/media/content/domain/Content.java @@ -3,10 +3,7 @@ import jakarta.persistence.*; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -17,7 +14,7 @@ @Entity @Getter @Table(name = "contents") -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Builder @EntityListeners(AuditingEntityListener.class) @@ -42,7 +39,6 @@ public class Content { private String hashtags; - private Long viewCount; private Long shareCount; diff --git a/src/main/java/wanted/media/user/domain/User.java b/src/main/java/wanted/media/user/domain/User.java index c5f60d5..d9c57c3 100644 --- a/src/main/java/wanted/media/user/domain/User.java +++ b/src/main/java/wanted/media/user/domain/User.java @@ -15,7 +15,7 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.UUID) - @Column(name = "userId", nullable = false) + @Column(name = "user_Id", nullable = false) private UUID userId; } From 6461960f8626ec62935d667b3a38bac35afadeee Mon Sep 17 00:00:00 2001 From: ssunnykku <108388578+ssunnykku@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:59:01 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20User=20Entity=20user=5Fid=20?= =?UTF-8?q?=EC=BB=AC=EB=9F=BC=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/wanted/media/user/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/wanted/media/user/domain/User.java b/src/main/java/wanted/media/user/domain/User.java index d9c57c3..e415dfd 100644 --- a/src/main/java/wanted/media/user/domain/User.java +++ b/src/main/java/wanted/media/user/domain/User.java @@ -15,7 +15,7 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.UUID) - @Column(name = "user_Id", nullable = false) + @Column(name = "user_id", nullable = false) private UUID userId; }