알림삭제 기능 추가

This commit is contained in:
Macbook
2026-05-27 17:39:33 +09:00
parent 701a9b2881
commit 9cee6387c3
7 changed files with 344 additions and 4 deletions
@@ -69,6 +69,52 @@ public class TradeSignalService {
.stream().map(this::toDto).toList();
}
// ── 삭제 ─────────────────────────────────────────────────────────────────
public void deleteOne(Long id, Long userId, String deviceId) {
if (id == null) return;
repo.findById(id).ifPresent(entity -> {
if (!owns(entity, userId, deviceId)) return;
repo.delete(entity);
log.info("[TradeSignal] deleted id={} market={}", id, entity.getMarket());
});
}
public int deleteBatch(List<Long> ids, Long userId, String deviceId) {
if (ids == null || ids.isEmpty()) return 0;
List<GcTradeSignal> toDelete = ids.stream()
.distinct()
.map(repo::findById)
.filter(java.util.Optional::isPresent)
.map(java.util.Optional::get)
.filter(e -> owns(e, userId, deviceId))
.toList();
if (toDelete.isEmpty()) return 0;
repo.deleteAll(toDelete);
log.info("[TradeSignal] batch deleted count={}", toDelete.size());
return toDelete.size();
}
public int deleteAll(Long userId, String deviceId) {
if (userId != null) {
long count = repo.findByUserIdOrderByCreatedAtDesc(userId).size();
repo.deleteByUserId(userId);
log.info("[TradeSignal] deleted all for userId={} count≈{}", userId, count);
return (int) count;
}
String dev = deviceId != null ? deviceId : "";
long count = repo.findByDeviceIdOrderByCreatedAtDesc(dev).size();
repo.deleteByDeviceId(dev);
log.info("[TradeSignal] deleted all for deviceId={} count≈{}", dev, count);
return (int) count;
}
private static boolean owns(GcTradeSignal entity, Long userId, String deviceId) {
if (userId != null && userId.equals(entity.getUserId())) return true;
if (deviceId == null || deviceId.isBlank()) return false;
return deviceId.equals(entity.getDeviceId());
}
// ── 변환 ─────────────────────────────────────────────────────────────────
private TradeSignalDto toDto(GcTradeSignal e) {