diff --git a/src/main/java/SuMoC/backend/dev/DevController.java b/src/main/java/SuMoC/backend/dev/DevController.java index f2fca27..8265526 100644 --- a/src/main/java/SuMoC/backend/dev/DevController.java +++ b/src/main/java/SuMoC/backend/dev/DevController.java @@ -7,6 +7,7 @@ import SuMoC.backend.notification.enums.NotificationStatus; import SuMoC.backend.notification.enums.NotificationType; import SuMoC.backend.notification.models.Notification; import SuMoC.backend.notification.repositories.NotificationRepository; +import SuMoC.backend.routing.dtos.RouteDTO; import SuMoC.backend.scheduling.ScheduledTasks; import SuMoC.backend.trend.dto.TrendDetectionDTO; import SuMoC.backend.trend.services.StatTableUpdateService; @@ -27,6 +28,7 @@ import org.springframework.web.bind.annotation.*; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; @RestController @RequestMapping("/dev") @@ -76,9 +78,9 @@ public class DevController { statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(day3WeeksAgo); } - @GetMapping("/test-firebase/{fcm_token}") + @GetMapping("/test-firebase-trend-notification/{fcm_token}") @Operation(description = "Immediately sends a test notification of type TREND to the provided FCM token.") - public ResponseEntity testFirebaseConnection(@PathVariable("fcm_token") @NotNull String fcmToken) { + public ResponseEntity SendTestTrendNotificationFirebase(@PathVariable("fcm_token") @NotNull String fcmToken) { if (firebaseMessaging == null) { return ResponseEntity.status(503) .body("✗ Firebase is not configured (firebase.config.enabled=false)"); @@ -100,6 +102,32 @@ public class DevController { } } + @GetMapping("/test-firebase-adhoc-route-notification/{fcm_token}") + @Operation(description = "Immediately sends a test notification of type ADHOC_ALTERNATIVE to the provided FCM token.") + public ResponseEntity SendTestAdhocRouteNotificationFirebase(@PathVariable("fcm_token") @NotNull String fcmToken) { + if (firebaseMessaging == null) { + return ResponseEntity.status(503) + .body("✗ Firebase is not configured (firebase.config.enabled=false)"); + } + try { + Notification notification = new Notification(); + notification.setType(NotificationType.ADHOC_ALTERNATIVE); + // Using TrendDetectionDTO as a placeholder, replace with actual AdhocAlternativeDTO when available + List mockRoutes = List.of(RouteDTO.getMockRouteDTO(), RouteDTO.getMockRouteDTO()); + notification.setData(objectMapper.writeValueAsString(mockRoutes)); + + Message mockAdhocMessage = firebaseMessageBuilder.generateMessage(notification, fcmToken); + + // Send to a topic (no device registration needed) + String message = firebaseMessaging.sendAsync( + mockAdhocMessage + ).get(); + return ResponseEntity.ok("✓ Firebase message sent to topic: " + message); + } catch (Exception e) { + return ResponseEntity.status(500).body("✗ Failed: " + e.getMessage()); + } + } + @Operation(description = "Immediately queues a notification to the fcm key specified in application-dev.properties to be processed by the notification queue.") @GetMapping("/queue-test-notification") public ResponseEntity queueTestNotification() {