Skip to content

Commit d8a34b2

Browse files
committed
refactor : soft Delete
1 parent 4a6f04a commit d8a34b2

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ dependencies {
3838

3939
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0")
4040
implementation("io.jsonwebtoken:jjwt-api:0.12.3")
41+
implementation("org.springframework.boot:spring-boot-starter-batch")
42+
testImplementation("org.springframework.batch:spring-batch-test")
4143
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.3")
4244
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.3")
4345
compileOnly("org.projectlombok:lombok")

src/main/java/com/back/domain/cocktail/comment/entity/CocktailComment.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
import java.time.LocalDateTime;
1616

1717
@Entity
18-
@Table(
19-
name = "cocktail_comment",
20-
uniqueConstraints = @UniqueConstraint(columnNames = {"cocktail_id", "user_id"}) // 사용자 1개 댓글 제한
21-
)
18+
@Table(name = "cocktail_comment")
2219
@Getter
2320
@EntityListeners(AuditingEntityListener.class)
2421
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)

src/main/java/com/back/domain/cocktail/comment/repository/CocktailCommentRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.back.domain.cocktail.comment.repository;
22

33
import com.back.domain.cocktail.comment.entity.CocktailComment;
4+
import com.back.domain.post.comment.enums.CommentStatus;
45
import org.springframework.data.jpa.repository.JpaRepository;
56
import org.springframework.stereotype.Repository;
67

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

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

16-
boolean existsByCocktailIdAndUserId(Long cocktailId, Long id);
17+
boolean existsByCocktailIdAndUserIdAndStatusNot(Long cocktailId, Long id, CommentStatus status);
1718
}

src/main/java/com/back/domain/cocktail/comment/service/CocktailCommentService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public CocktailCommentResponseDto createCocktailComment(Long cocktailId, Cocktai
3232
.orElseThrow(() -> new IllegalArgumentException("칵테일이 존재하지 않습니다. id=" + cocktailId));
3333

3434
// 사용자당 댓글 1개 제한 체크
35-
boolean exists = cocktailCommentRepository.existsByCocktailIdAndUserId(cocktailId, user.getId());
35+
boolean exists = cocktailCommentRepository.existsByCocktailIdAndUserIdAndStatusNot(
36+
cocktailId,
37+
user.getId(),
38+
CommentStatus.DELETED // DELETED 상태는 제외하고 검사
39+
);
40+
3641
if (exists) {
3742
throw new IllegalArgumentException("이미 댓글을 작성하셨습니다.");
3843
}

0 commit comments

Comments
 (0)