-
Couldn't load subscription status.
- Fork 1
[feat] 박수 기능 엔티티(Stamp, Clap) 구조 추가 및 동시성 대응 - #623 #625
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
Changes from 2 commits
2cef114
86e6675
ca69ac5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package org.sopt.app.domain.entity.soptamp; | ||
|
|
||
| import org.hibernate.annotations.Check; | ||
| import org.sopt.app.domain.entity.BaseEntity; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.persistence.UniqueConstraint; | ||
| import jakarta.persistence.Version; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Table( | ||
| name = "clap", | ||
| uniqueConstraints = @UniqueConstraint( | ||
| name = "uk_clap_stamp_user", | ||
| columnNames = {"stamp_id", "user_id"} | ||
| ) | ||
| ) | ||
| @Check(constraints = "clap_count >= 0 AND clap_count <= 50") | ||
|
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. DB 가드도 좋네요 👍🏻👍🏻 |
||
| public class Clap extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "stamp_id", nullable = false) | ||
| private Long stampId; | ||
|
|
||
| @Column(name = "user_id", nullable = false) | ||
| private Long userId; | ||
|
|
||
| @Column(name = "clap_count", nullable = false) | ||
| private int clapCount = 0; | ||
|
|
||
| @Version | ||
| private Long version; | ||
|
|
||
| public void incrementClapCount(int increment) { | ||
| if (increment <= 0) return; | ||
| int nextCount = this.clapCount + increment; | ||
| this.clapCount = Math.min(nextCount, 50); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,13 @@ public class Stamp extends BaseEntity { | |
| @Column(length = 10) | ||
| private String activityDate; | ||
|
|
||
| private int clapCount = 0; | ||
|
|
||
| private int viewCount = 0; | ||
|
|
||
| @Version | ||
| private Long version; | ||
|
Comment on lines
+41
to
+42
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. PR에 적어주신대로 낙관적 락을 위한 필드로 이해하고 있을게요 ~~ |
||
|
|
||
| public void changeContents(String contents) { | ||
| this.contents = contents; | ||
| } | ||
|
|
@@ -61,4 +68,13 @@ public void validate() { | |
| } | ||
| } | ||
|
|
||
| public void incrementClapCount(int increment) { | ||
| if (increment <= 0) return; | ||
| this.clapCount += increment; | ||
| } | ||
|
|
||
| public void incrementViewCount() { | ||
| this.viewCount += 1; | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.