Skip to content

Commit 03cd211

Browse files
authored
[feat] 나만의 bar soft delete 기능 구현 #31 (#36)
* feat: MyBarRepository에 소프트 삭제 기능 추가 - MyBar 엔티티를 삭제 시 실제 DB에서 삭제하는 대신, status를 'DELETED'로 변경하는 소프트 삭제 로직을 추가 * feat: 마이바(MyBar) 킵 해제 기능 추가 (소프트 삭제) * feat: MyBarController에 칵테일 킵(Keep) 해제 API 추가
1 parent b2b9aff commit 03cd211

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/main/java/com/back/domain/mybar/controller/MyBarController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ public RsData<Void> keep(
3737
myBarService.keep(userId, cocktailId);
3838
return RsData.of(201, "kept"); // Aspect가 HTTP 201로 설정
3939
}
40+
41+
/** 킵 해제(소프트 삭제) — 멱등 */
42+
@DeleteMapping("/{cocktailId}/keep")
43+
public RsData<Void> unkeep(
44+
@AuthenticationPrincipal(expression = "id") Long userId,
45+
@PathVariable Long cocktailId
46+
) {
47+
myBarService.unkeep(userId, cocktailId);
48+
return RsData.of(200, "deleted");
49+
}
4050
}

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
}

src/main/java/com/back/domain/mybar/service/MyBarService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ public void keep(Long userId, Long cocktailId) {
6868

6969
myBarRepository.save(myBar);
7070
}
71+
72+
/** 킵 해제(소프트 삭제) */
73+
@Transactional
74+
public void unkeep(Long userId, Long cocktailId) {
75+
myBarRepository.softDeleteByUserAndCocktail(userId, cocktailId);
76+
}
7177
}

0 commit comments

Comments
 (0)