| Line 1354... |
Line 1354... |
| 1354 |
response.put("status", true);
|
1354 |
response.put("status", true);
|
| 1355 |
response.put("message", "Beat deleted");
|
1355 |
response.put("message", "Beat deleted");
|
| 1356 |
return responseSender.ok(response);
|
1356 |
return responseSender.ok(response);
|
| 1357 |
}
|
1357 |
}
|
| 1358 |
|
1358 |
|
| - |
|
1359 |
// Unschedule the beat from ONE specific date — does NOT delete the beat.
|
| - |
|
1360 |
// The beat (and its route template) stays; only the matching beat_schedule
|
| - |
|
1361 |
// row is removed. If no real-date schedules remain, a placeholder
|
| - |
|
1362 |
// (9999-12-31) row is added so the beat still shows up as "unscheduled".
|
| - |
|
1363 |
@PostMapping(value = "/beatPlan/unscheduleDate")
|
| - |
|
1364 |
public ResponseEntity<?> unscheduleDate(
|
| - |
|
1365 |
@RequestParam String planGroupId,
|
| - |
|
1366 |
@RequestParam String date) {
|
| - |
|
1367 |
int beatId = Integer.parseInt(planGroupId);
|
| - |
|
1368 |
LocalDate target = LocalDate.parse(date);
|
| - |
|
1369 |
|
| - |
|
1370 |
Beat beat = beatRepository.selectById(beatId);
|
| - |
|
1371 |
if (beat == null) return responseSender.badRequest("Beat not found");
|
| - |
|
1372 |
|
| - |
|
1373 |
List<BeatSchedule> schedules = beatScheduleRepository.selectByBeatId(beatId);
|
| - |
|
1374 |
int removed = 0;
|
| - |
|
1375 |
for (BeatSchedule s : schedules) {
|
| - |
|
1376 |
if (s.getStartDate() != null && s.getStartDate().equals(target)) {
|
| - |
|
1377 |
beatScheduleRepository.delete(s);
|
| - |
|
1378 |
removed++;
|
| - |
|
1379 |
}
|
| - |
|
1380 |
}
|
| - |
|
1381 |
if (removed == 0) return responseSender.badRequest("No schedule found for that date");
|
| - |
|
1382 |
|
| - |
|
1383 |
// If no real-date schedules left, drop in a placeholder so the beat
|
| - |
|
1384 |
// remains visible in the unscheduled bucket.
|
| - |
|
1385 |
boolean hasReal = schedules.stream()
|
| - |
|
1386 |
.filter(s -> !s.getStartDate().equals(target))
|
| - |
|
1387 |
.anyMatch(s -> s.getStartDate() != null && s.getStartDate().getYear() != 9999);
|
| - |
|
1388 |
if (!hasReal) {
|
| - |
|
1389 |
boolean hasPlaceholder = schedules.stream()
|
| - |
|
1390 |
.filter(s -> !s.getStartDate().equals(target))
|
| - |
|
1391 |
.anyMatch(s -> s.getStartDate() != null && s.getStartDate().getYear() == 9999);
|
| - |
|
1392 |
if (!hasPlaceholder) {
|
| - |
|
1393 |
BeatSchedule ph = new BeatSchedule();
|
| - |
|
1394 |
ph.setBeatId(beatId);
|
| - |
|
1395 |
ph.setStartDate(LocalDate.of(9999, 12, 31));
|
| - |
|
1396 |
ph.setDayNumber(1);
|
| - |
|
1397 |
ph.setEndAction("HOME");
|
| - |
|
1398 |
ph.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
1399 |
beatScheduleRepository.persist(ph);
|
| - |
|
1400 |
}
|
| - |
|
1401 |
}
|
| - |
|
1402 |
|
| - |
|
1403 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
1404 |
response.put("status", true);
|
| - |
|
1405 |
response.put("message", "Unscheduled from " + date);
|
| - |
|
1406 |
return responseSender.ok(response);
|
| - |
|
1407 |
}
|
| - |
|
1408 |
|
| - |
|
1409 |
// Move a beat from one date to another — used by calendar drag-and-drop.
|
| - |
|
1410 |
// Just updates the start_date of the matching beat_schedule row.
|
| - |
|
1411 |
@PostMapping(value = "/beatPlan/moveScheduleDate")
|
| - |
|
1412 |
public ResponseEntity<?> moveScheduleDate(
|
| - |
|
1413 |
@RequestParam String planGroupId,
|
| - |
|
1414 |
@RequestParam String fromDate,
|
| - |
|
1415 |
@RequestParam String toDate) {
|
| - |
|
1416 |
int beatId = Integer.parseInt(planGroupId);
|
| - |
|
1417 |
LocalDate from = LocalDate.parse(fromDate);
|
| - |
|
1418 |
LocalDate to = LocalDate.parse(toDate);
|
| - |
|
1419 |
|
| - |
|
1420 |
if (from.equals(to)) {
|
| - |
|
1421 |
Map<String, Object> ok = new HashMap<>();
|
| - |
|
1422 |
ok.put("status", true);
|
| - |
|
1423 |
ok.put("message", "Same date — no change");
|
| - |
|
1424 |
return responseSender.ok(ok);
|
| - |
|
1425 |
}
|
| - |
|
1426 |
|
| - |
|
1427 |
Beat beat = beatRepository.selectById(beatId);
|
| - |
|
1428 |
if (beat == null) return responseSender.badRequest("Beat not found");
|
| - |
|
1429 |
|
| - |
|
1430 |
List<BeatSchedule> schedules = beatScheduleRepository.selectByBeatId(beatId);
|
| - |
|
1431 |
|
| - |
|
1432 |
// Reject if the beat is already on the target date
|
| - |
|
1433 |
boolean conflict = schedules.stream()
|
| - |
|
1434 |
.anyMatch(s -> s.getStartDate() != null && s.getStartDate().equals(to));
|
| - |
|
1435 |
if (conflict) return responseSender.badRequest("Beat is already scheduled on " + toDate);
|
| - |
|
1436 |
|
| - |
|
1437 |
BeatSchedule match = schedules.stream()
|
| - |
|
1438 |
.filter(s -> s.getStartDate() != null && s.getStartDate().equals(from))
|
| - |
|
1439 |
.findFirst().orElse(null);
|
| - |
|
1440 |
if (match == null) return responseSender.badRequest("No schedule found for " + fromDate);
|
| - |
|
1441 |
|
| - |
|
1442 |
match.setStartDate(to);
|
| - |
|
1443 |
// Recompute endDate as the max across all (post-update) schedules
|
| - |
|
1444 |
LocalDate newEnd = schedules.stream()
|
| - |
|
1445 |
.map(s -> s == match ? to : s.getStartDate())
|
| - |
|
1446 |
.filter(d -> d != null && d.getYear() != 9999)
|
| - |
|
1447 |
.max(LocalDate::compareTo).orElse(to);
|
| - |
|
1448 |
for (BeatSchedule s : schedules) {
|
| - |
|
1449 |
if (s.getStartDate() != null && s.getStartDate().getYear() != 9999) {
|
| - |
|
1450 |
s.setEndDate(newEnd);
|
| - |
|
1451 |
}
|
| - |
|
1452 |
}
|
| - |
|
1453 |
|
| - |
|
1454 |
Map<String, Object> response = new HashMap<>();
|
| - |
|
1455 |
response.put("status", true);
|
| - |
|
1456 |
response.put("message", "Moved from " + fromDate + " to " + toDate);
|
| - |
|
1457 |
return responseSender.ok(response);
|
| - |
|
1458 |
}
|
| - |
|
1459 |
|
| 1359 |
@GetMapping(value = "/beatPlan/calendar")
|
1460 |
@GetMapping(value = "/beatPlan/calendar")
|
| 1360 |
public ResponseEntity<?> getCalendar(
|
1461 |
public ResponseEntity<?> getCalendar(
|
| 1361 |
@RequestParam int authUserId,
|
1462 |
@RequestParam int authUserId,
|
| 1362 |
@RequestParam String month) {
|
1463 |
@RequestParam String month) {
|
| 1363 |
|
1464 |
|