refactor: Fixed return-types of the controller
[demos/kafka/chat] / src / main / java / de / juplo / kafka / chat / backend / ChatBackendApplication.java
index 287c9ee..0700496 100644 (file)
@@ -1,24 +1,31 @@
-package de.juplo.kafka.chatroom;
+package de.juplo.kafka.chat.backend;
 
+import de.juplo.kafka.chat.backend.domain.ChatHome;
+import de.juplo.kafka.chat.backend.persistence.StorageStrategy;
+import jakarta.annotation.PreDestroy;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.Bean;
-
-import java.time.Clock;
+import reactor.core.publisher.Flux;
 
 
 @SpringBootApplication
-public class ChatroomApplication
+public class ChatBackendApplication
 {
-       @Bean
-       public Clock clock()
+       @Autowired
+       ChatHome chatHome;
+       @Autowired
+       StorageStrategy storageStrategy;
+
+       @PreDestroy
+       public void onExit()
        {
-               return Clock.systemDefaultZone();
+               storageStrategy.writeChatrooms(Flux.fromStream(chatHome.list()));
        }
 
-
        public static void main(String[] args)
        {
-               SpringApplication.run(ChatroomApplication.class, args);
+               SpringApplication.run(ChatBackendApplication.class, args);
        }
 }