add demo endpoint for notification mocks
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-01-13 12:22:44 +01:00
parent f1a214b5db
commit ba642d10a5
13 changed files with 120 additions and 29 deletions
@@ -1,17 +1,21 @@
package SuMoC.backend.dev;
import SuMoC.backend.firebase.MessageBuilder;
import SuMoC.backend.meteo.ForecastService;
import SuMoC.backend.meteo.MeteoClient;
import SuMoC.backend.notification.enums.NotificationType;
import SuMoC.backend.notification.models.Notification;
import SuMoC.backend.scheduling.ScheduledTasks;
import SuMoC.backend.trend.dto.TrendDetectionDTO;
import SuMoC.backend.trend.services.StatTableUpdateService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.Message;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
@@ -25,18 +29,25 @@ public class DevController {
private final FirebaseMessaging firebaseMessaging;
private final MeteoClient meteoClient;
private final ForecastService forecastService;
private final MessageBuilder messageBuilder;
private final ObjectMapper objectMapper;
public DevController(
ScheduledTasks scheduledTasks,
StatTableUpdateService statTableUpdateService,
@Autowired(required = false) FirebaseMessaging firebaseMessaging,
MeteoClient meteoClient,
ForecastService forecastService) {
ForecastService forecastService,
MessageBuilder messageBuilder,
ObjectMapper objectMapper
) {
this.scheduledTasks = scheduledTasks;
this.statTableUpdateService = statTableUpdateService;
this.firebaseMessaging = firebaseMessaging;
this.meteoClient = meteoClient;
this.forecastService = forecastService;
this.messageBuilder = messageBuilder;
this.objectMapper = objectMapper;
}
@PostMapping("/trigger-trend-calculation")
@@ -49,19 +60,22 @@ public class DevController {
statTableUpdateService.updateWeeklyMobilityStatsForAllUsers(day3WeeksAgo);
}
@GetMapping("/test-firebase")
public ResponseEntity<String> testFirebaseConnection() {
@GetMapping("/test-firebase/{fcm_token}")
public ResponseEntity<String> testFirebaseConnection(@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.TREND);
notification.setData(objectMapper.writeValueAsString(TrendDetectionDTO.mockTrendDetectionDTO()));
Message mockTrendMessage = messageBuilder.generateMessage(notification, fcmToken);
// Send to a topic (no device registration needed)
String message = firebaseMessaging.sendAsync(
com.google.firebase.messaging.Message.builder()
.setTopic("test-topic")
.putData("test", "connection-check")
.build()
mockTrendMessage
).get();
return ResponseEntity.ok("✓ Firebase message sent to topic: " + message);
} catch (Exception e) {