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
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ public RsData<Void> keep(
myBarService.keep(userId, cocktailId);
return RsData.of(201, "kept"); // Aspect가 HTTP 201로 설정
}

/** 킵 해제(소프트 삭제) — 멱등 */
@DeleteMapping("/{cocktailId}/keep")
public RsData<Void> unkeep(
@AuthenticationPrincipal(expression = "id") Long userId,
@PathVariable Long cocktailId
) {
myBarService.unkeep(userId, cocktailId);
return RsData.of(200, "deleted");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

/** 복원/재킵을 위해 status 무시하고 한 건 찾기 (없으면 Optional.empty) */
Optional<MyBar> findByUser_IdAndCocktail_CocktailId(Long userId, Long cocktailId);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("""
update MyBar m
set m.status = 'DELETED', m.deletedAt = CURRENT_TIMESTAMP
where m.user.id = :userId
and m.cocktail.cocktailId = :cocktailId
and m.status = 'ACTIVE'
""")
int softDeleteByUserAndCocktail(Long userId, Long cocktailId);
}
6 changes: 6 additions & 0 deletions src/main/java/com/back/domain/mybar/service/MyBarService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ public void keep(Long userId, Long cocktailId) {

myBarRepository.save(myBar);
}

/** 킵 해제(소프트 삭제) */
@Transactional
public void unkeep(Long userId, Long cocktailId) {
myBarRepository.softDeleteByUserAndCocktail(userId, cocktailId);
}
}