-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
상품 조회수, 좋아요
- Loading branch information
Showing
10 changed files
with
271 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/market/saessag/domain/product/entity/ProductLike.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.market.saessag.domain.product.entity; | ||
|
||
import com.market.saessag.domain.user.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.OnDelete; | ||
import org.hibernate.annotations.OnDeleteAction; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"product_id", "user_id"})}) | ||
public class ProductLike { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "product_id", nullable = false) | ||
@OnDelete(action = OnDeleteAction.CASCADE) // 상품 삭제 시 좋아요도 삭제 | ||
private Product product; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/market/saessag/domain/product/entity/ProductView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.market.saessag.domain.product.entity; | ||
|
||
import com.market.saessag.domain.user.entity.User; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.OnDelete; | ||
import org.hibernate.annotations.OnDeleteAction; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
@Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"product_id", "user_id"})}) | ||
public class ProductView { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "product_id", nullable = false) | ||
@OnDelete(action = OnDeleteAction.CASCADE) | ||
private Product product; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
|
||
private LocalDateTime viewTime; | ||
|
||
@PrePersist | ||
public void prePersist() { | ||
this.viewTime = LocalDateTime.now(); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/market/saessag/domain/product/repository/ProductLikeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.market.saessag.domain.product.repository; | ||
|
||
import com.market.saessag.domain.product.entity.Product; | ||
import com.market.saessag.domain.product.entity.ProductLike; | ||
import com.market.saessag.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
|
||
public interface ProductLikeRepository extends JpaRepository<ProductLike, Long> { | ||
ProductLike findByProductAndUser(Product product, User user); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/market/saessag/domain/product/repository/ProductViewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.market.saessag.domain.product.repository; | ||
|
||
import com.market.saessag.domain.product.entity.Product; | ||
import com.market.saessag.domain.product.entity.ProductView; | ||
import com.market.saessag.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProductViewRepository extends JpaRepository<ProductView, Long> { | ||
boolean existsByProductAndUser(Product product, User user); | ||
} |
Oops, something went wrong.