-
Notifications
You must be signed in to change notification settings - Fork 6
JPA를 사용하여 네이버 예약 시스템 구현 #21
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
base: YooJisu826
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,27 @@ | ||
| package com.landvive.summer.mvc.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import lombok.*; | ||
|
|
||
| import javax.persistence.*; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 엔티티를 설정함에 있어서 setter의 사용은 지양하는 편이 좋습니다 |
||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Table(name= "category") | ||
| public class Category { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) // AI 형식으로 만들어짐! | ||
| private Long id; | ||
|
|
||
| private String name; | ||
| private Long count; //해당 카테고리의 Product 개수 | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| @OneToMany(mappedBy = "category") | ||
| private List<Product> productList; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,29 @@ | ||
| package com.landvive.summer.mvc.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import lombok.*; | ||
|
|
||
| import javax.persistence.*; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Entity | ||
| @Table(name= "product") | ||
| public class Product { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) // AI 형식으로 만들어짐! | ||
| private Long id; | ||
| private Long categoryId; | ||
|
|
||
| private String name; | ||
| private String description; | ||
| private LocalDateTime createdAt; | ||
|
|
||
| } | ||
| @ManyToOne | ||
| @JoinColumn(name="categoryId") | ||
| private Category category; | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.landvive.summer.mvc.repository; | ||
|
|
||
| import com.landvive.summer.mvc.entity.Category; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface CateRepository extends JpaRepository<Category, Long> { | ||
|
|
||
| @Query(value = "SELECT c FROM Category c WHERE c.name = :name") | ||
| Optional<Category> findByName2(String name); | ||
|
|
||
| @Modifying | ||
| @Query("UPDATE Category c SET c.count = c.count+1 WHERE c.id = :categoryId") | ||
| void plusProductCount(Long categoryId); | ||
|
|
||
| } |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘했는데 전반적으로 네이밍을 조금만 더 신경쓰면 좋을거 같아
우선 그냥 service라 던지 혹인 categoryRepository를 cateRepository라 쓰는 것과 같이 줄여쓰는게, 혼자 개발을 할때는 헷갈리지 않을 수 있어도 협업을 하거나 다른 누군가가 보기에는 가독성이 좋지 않다고 나는 생각해
그래서 웬만하면 네이밍에 있어서 줄임말은 쓰지 않는게좋다고 생각합니당