-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
2cef114
[#623] feat(Stamp): Stamp 엔티티에 clapCount·viewCount·version 필드 추가
hyerinhwang-sailin 86e6675
[#623] feat(Clap): Clap 엔티티 생성 (유저별 박수 정보, 상한 50, (stamp_id, user_id)…
hyerinhwang-sailin ca69ac5
[#623] feat(Clap): protected 접근제한자를 걸어 빌더만 사용하도록 강제
hyerinhwang-sailin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/org/sopt/app/domain/entity/soptamp/Clap.java
This file contains hidden or 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,56 @@ | ||
| 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.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table( | ||
| name = "clap", | ||
| uniqueConstraints = @UniqueConstraint( | ||
| name = "uk_clap_stamp_user", | ||
| columnNames = {"stamp_id", "user_id"} | ||
| ) | ||
| ) | ||
| @Check(constraints = "clap_count >= 0 AND clap_count <= 50") | ||
| 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); | ||
| } | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
DB 가드도 좋네요 👍🏻👍🏻