dev add violation notion
Test Workflow / test (push) Successful in 4s

This commit is contained in:
vladp
2026-03-18 16:26:47 +07:00
parent 9e5ff7ce97
commit 9024d3aaca
2 changed files with 6 additions and 5 deletions
@@ -58,8 +58,9 @@ public class PaymentController {
} }
} }
@PostMapping("/auto-renewal/disable") @PostMapping("/auto-renewal")
public ResponseEntity<?> disableAutoRenewal(@RequestHeader(value = "Authorization", required = false) String tokenHeader) { public ResponseEntity<?> disableAutoRenewal(@RequestParam(value = "renewal") Boolean renewal,
@RequestHeader(value = "Authorization", required = false) String tokenHeader) {
try { try {
if (tokenHeader == null || tokenHeader.isBlank()) { if (tokenHeader == null || tokenHeader.isBlank()) {
Map<String, Object> errorData = new HashMap<>(); Map<String, Object> errorData = new HashMap<>();
@@ -68,7 +69,7 @@ public class PaymentController {
return ResponseEntity.ok().body(Map.of("error", errorData)); return ResponseEntity.ok().body(Map.of("error", errorData));
} }
paymentService.disableAutoRenewal(authService.useUserAuthToken(tokenHeader)); paymentService.changeAutoRenewal(authService.useUserAuthToken(tokenHeader), renewal);
return ResponseEntity.ok(Map.of("message", "Auto-renewal disabled")); return ResponseEntity.ok(Map.of("message", "Auto-renewal disabled"));
} catch (UserNotFoundException e) { } catch (UserNotFoundException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND) return ResponseEntity.status(HttpStatus.NOT_FOUND)
@@ -120,12 +120,12 @@ public class PaymentService {
} }
@Transactional @Transactional
public void disableAutoRenewal(Long userId) { public void changeAutoRenewal(Long userId, boolean autoRenewal) {
User user = userRepository.findById(userId).orElseThrow(); User user = userRepository.findById(userId).orElseThrow();
TariffInfo tariffInfo = user.getActiveTariffInfo(); TariffInfo tariffInfo = user.getActiveTariffInfo();
if (tariffInfo != null) { if (tariffInfo != null) {
tariffInfo.setAutoRenewal(false); tariffInfo.setAutoRenewal(autoRenewal);
tariffInfoRepository.save(tariffInfo); tariffInfoRepository.save(tariffInfo);
} }
} }