Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor] contents 기초 코드 수정 #10

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {
}
27 changes: 18 additions & 9 deletions src/main/java/wanted/media/content/domain/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand All @@ -14,33 +13,43 @@

@Entity
@Getter
@Setter
@Table(name="contents")
@NoArgsConstructor
@Table(name = "contents")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전 PR에서 제안한 의견 반영해 주신거 확인했습니다!

@AllArgsConstructor
@Builder
@ToString
@EntityListeners(AuditingEntityListener.class)
public class Content {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "content_id", nullable = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테이블의 pk를 content_id라고 설정해 놓으셨나요? id라고 설정해 놓으셨으면 name은 따로 작성 안하셔도 돼요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 DB 모델링 할 때 content_id로 했었습니다.

private Long id;

@Column(name = "like_count")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카멜 케이스는 알아서 스네이크 케이스로 변경되기 때문에 어노테이션 따로 작성 안하셔도 괜찮습니다!

private Long likeCount;
@Size(max = 50)
private String type;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Type type;

@Size(max = 150)
@Column(nullable = false)
private String title;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

37라인부터 43라인까지 공백은 없어도 괜찮은거 같아요 ~!

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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/wanted/media/content/domain/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package wanted.media.content.domain;

public enum Type {
FACEBOOK, TWITTER, INSTAGRAM, THREADS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import org.springframework.data.jpa.repository.JpaRepository;
import wanted.media.content.domain.Content;

public interface ContentRepository extends JpaRepository<Content,Long> {
public interface ContentRepository extends JpaRepository<Content, Long> {
}
10 changes: 2 additions & 8 deletions src/main/java/wanted/media/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
@Column(name = "user_id", nullable = false)
private UUID userId;

@OneToMany(mappedBy = "user")
@Builder.Default
List<Content> interviews = new ArrayList<>();
}