made firebase config optional so backend starts without a key present
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -5,7 +5,7 @@ import SuMoC.backend.meteo.MeteoClient;
|
||||
import SuMoC.backend.scheduling.ScheduledTasks;
|
||||
import SuMoC.backend.trend.services.StatTableUpdateService;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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;
|
||||
@@ -18,19 +18,27 @@ import java.time.LocalDate;
|
||||
@RestController
|
||||
@RequestMapping("/dev")
|
||||
@Profile("dev")
|
||||
@RequiredArgsConstructor
|
||||
public class DevController {
|
||||
|
||||
private final ScheduledTasks scheduledTasks;
|
||||
|
||||
private final StatTableUpdateService statTableUpdateService;
|
||||
|
||||
private final FirebaseMessaging firebaseMessaging;
|
||||
|
||||
private final MeteoClient meteoClient;
|
||||
|
||||
private final ForecastService forecastService;
|
||||
|
||||
public DevController(
|
||||
ScheduledTasks scheduledTasks,
|
||||
StatTableUpdateService statTableUpdateService,
|
||||
@Autowired(required = false) FirebaseMessaging firebaseMessaging,
|
||||
MeteoClient meteoClient,
|
||||
ForecastService forecastService) {
|
||||
this.scheduledTasks = scheduledTasks;
|
||||
this.statTableUpdateService = statTableUpdateService;
|
||||
this.firebaseMessaging = firebaseMessaging;
|
||||
this.meteoClient = meteoClient;
|
||||
this.forecastService = forecastService;
|
||||
}
|
||||
|
||||
@PostMapping("/trigger-trend-calculation")
|
||||
public void triggerTrendCalculation() {
|
||||
LocalDate dayOfLastWeek = LocalDate.now().minusDays(7);
|
||||
@@ -43,6 +51,10 @@ public class DevController {
|
||||
|
||||
@GetMapping("/test-firebase")
|
||||
public ResponseEntity<String> testFirebaseConnection() {
|
||||
if (firebaseMessaging == null) {
|
||||
return ResponseEntity.status(503)
|
||||
.body("✗ Firebase is not configured (firebase.config.enabled=false)");
|
||||
}
|
||||
try {
|
||||
// Send to a topic (no device registration needed)
|
||||
String message = firebaseMessaging.sendAsync(
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.FirebaseOptions;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -15,6 +16,7 @@ import java.io.InputStream;
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(FirebaseProperties.class)
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "firebase.config", name = "enabled", havingValue = "true", matchIfMissing = false)
|
||||
public class FirebaseConfiguration {
|
||||
|
||||
private final FirebaseProperties firebaseProperties;
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
@ConfigurationProperties(prefix = "firebase.config")
|
||||
public record FirebaseProperties(
|
||||
Boolean enabled,
|
||||
Resource serviceAccount
|
||||
) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user