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
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {

implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0")
implementation("io.jsonwebtoken:jjwt-api:0.12.3")
implementation("org.springframework.boot:spring-boot-starter-batch")
testImplementation("org.springframework.batch:spring-batch-test")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.3")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.3")
compileOnly("org.projectlombok:lombok")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import java.time.LocalDateTime;

@Entity
@Table(
name = "cocktail_comment",
uniqueConstraints = @UniqueConstraint(columnNames = {"cocktail_id", "user_id"}) // 사용자 1개 댓글 제한
)
@Table(name = "cocktail_comment")
@Getter
@EntityListeners(AuditingEntityListener.class)
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.back.domain.cocktail.comment.repository;

import com.back.domain.cocktail.comment.entity.CocktailComment;
import com.back.domain.post.comment.enums.CommentStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -13,5 +14,5 @@ public interface CocktailCommentRepository extends JpaRepository<CocktailComment

List<CocktailComment> findTop10ByCocktailIdAndIdLessThanOrderByIdDesc(Long cocktailId, Long lastId);

boolean existsByCocktailIdAndUserId(Long cocktailId, Long id);
boolean existsByCocktailIdAndUserIdAndStatusNot(Long cocktailId, Long id, CommentStatus status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public CocktailCommentResponseDto createCocktailComment(Long cocktailId, Cocktai
.orElseThrow(() -> new IllegalArgumentException("칵테일이 존재하지 않습니다. id=" + cocktailId));

// 사용자당 댓글 1개 제한 체크
boolean exists = cocktailCommentRepository.existsByCocktailIdAndUserId(cocktailId, user.getId());
boolean exists = cocktailCommentRepository.existsByCocktailIdAndUserIdAndStatusNot(
cocktailId,
user.getId(),
CommentStatus.DELETED // DELETED 상태는 제외하고 검사
);

if (exists) {
throw new IllegalArgumentException("이미 댓글을 작성하셨습니다.");
}
Expand Down