Skip to content

Commit a5b21c8

Browse files
committed
feat: MyBarRepository에 소프트 삭제 기능 추가
- MyBar 엔티티를 삭제 시 실제 DB에서 삭제하는 대신, status를 'DELETED'로 변경하는 소프트 삭제 로직을 추가
1 parent b2b9aff commit a5b21c8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/com/back/domain/mybar/repository/MyBarRepository.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.springframework.data.domain.Page;
66
import org.springframework.data.domain.Pageable;
77
import org.springframework.data.jpa.repository.JpaRepository;
8+
import org.springframework.data.jpa.repository.Modifying;
9+
import org.springframework.data.jpa.repository.Query;
810
import org.springframework.stereotype.Repository;
911

1012
import java.util.Optional;
@@ -22,4 +24,14 @@ public interface MyBarRepository extends JpaRepository<MyBar, Long> {
2224

2325
/** 복원/재킵을 위해 status 무시하고 한 건 찾기 (없으면 Optional.empty) */
2426
Optional<MyBar> findByUser_IdAndCocktail_CocktailId(Long userId, Long cocktailId);
27+
28+
@Modifying(clearAutomatically = true, flushAutomatically = true)
29+
@Query("""
30+
update MyBar m
31+
set m.status = 'DELETED', m.deletedAt = CURRENT_TIMESTAMP
32+
where m.user.id = :userId
33+
and m.cocktail.cocktailId = :cocktailId
34+
and m.status = 'ACTIVE'
35+
""")
36+
int softDeleteByUserAndCocktail(Long userId, Long cocktailId);
2537
}

0 commit comments

Comments
 (0)