Skip to content
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
56 changes: 56 additions & 0 deletions src/main/java/org/sopt/app/domain/entity/soptamp/Clap.java
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")
Copy link
Member

Choose a reason for hiding this comment

The 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);
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/sopt/app/domain/entity/soptamp/Stamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

PR에 적어주신대로 낙관적 락을 위한 필드로 이해하고 있을게요 ~~


public void changeContents(String contents) {
this.contents = contents;
}
Expand Down Expand Up @@ -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;
}

}