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

[feat] contents 공통 코드 작성 #5

Merged
merged 1 commit into from
Aug 22, 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
@@ -0,0 +1,9 @@
package wanted.media.content.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
Copy link
Contributor

Choose a reason for hiding this comment

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

@RestController 대신 @Controller를 사용하신 이유가 있을까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RestController로 수정하겠습니다.

@RequestMapping("/contents")
public class ContentController {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 EOL에 대해서 아시나용?

48 changes: 48 additions & 0 deletions src/main/java/wanted/media/content/domain/Content.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package wanted.media.content.domain;

import jakarta.persistence.*;
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;
import wanted.media.user.domain.User;

import java.time.LocalDateTime;

@Entity
@Getter
@Setter
Copy link
Contributor

Choose a reason for hiding this comment

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

@Setter를 사용하신 이유가 있을까요?

@Table(name="contents")
@NoArgsConstructor
Copy link
Contributor

Choose a reason for hiding this comment

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

@NoArgsConstructor@NoArgsConstructor (access = AccessLevel.PROTECTED) 로 변경하면 어떨지 제안합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

혹시 어떤 설정인가요?

Copy link
Contributor

Choose a reason for hiding this comment

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

기본 access 설정은 AccessLevel.PUBLIC이고, 별도로 access 속성을 설정하지 않으면 public 접근 수준으로 기본 생성자가 만들어진다고 합니다.
다른 패키지에서 엔티티에 대한 접근이 너무 자유로우면 안될것 같다고 생각해서 protected로 설정을 추가하자고 제안했던거였습니다.

@AllArgsConstructor
@Builder
@ToString
Copy link
Contributor

Choose a reason for hiding this comment

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

@ToString도 당장은 사용할 필요가 없어보여요 !

@EntityListeners(AuditingEntityListener.class)
public class Content {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
Copy link
Contributor

Choose a reason for hiding this comment

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

GenerationType을 SEQUENCE로 하신 이유가 있을까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

찾아보니 오라클 등은 sequence를 주로 사용하고 mysql의 경우에는 IDENTITY를 사용한다고 하네요! 수정하겠습니다.

@Column(name = "content_id", nullable = false)
private Long id;
private Long likeCount;
@Size(max = 50)
private String type;
Copy link
Contributor

Choose a reason for hiding this comment

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

type은 String이 아니라 Enum이네요 !

@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
Copy link
Contributor

Choose a reason for hiding this comment

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

@ManyToOne을 사용하실 때 즉시로딩과 지연로딩에 대해서 들어보신 적 있을까요!?

@JoinColumn(name = "user_id")
@NotNull
private User user;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package wanted.media.content.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import wanted.media.content.domain.Content;

public interface ContentRepository extends JpaRepository<Content,Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package wanted.media.content.service;

import org.springframework.stereotype.Service;

@Service
public class ContentService {
}
27 changes: 27 additions & 0 deletions src/main/java/wanted/media/user/domain/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package wanted.media.user.domain;

import jakarta.persistence.*;
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")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "userId", 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.

혹시 user_id로 통일해도 될까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네 알겠습니다!

private UUID userId;

@OneToMany(mappedBy = "user")
Copy link
Contributor

Choose a reason for hiding this comment

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

이거는 단방향 연관관계와 양방향 연관관계를 알아보시고, 어떻게 사용할지 저희끼리 회의를 해야할 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

저도 양방향 연관관계에 대한 논의가 필요하다고 생각합니다!

@Builder.Default
Copy link
Contributor

Choose a reason for hiding this comment

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

@Builder.Default는 처음보네요 ! 왜 사용하셨는지 궁금합니당💭

Copy link
Contributor Author

Choose a reason for hiding this comment

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

현재는 필요없는 설정이라 삭제하겠습니다.

List<Content> interviews = new ArrayList<>();
}