diff --git a/.gitignore b/.gitignore index 307df119a2cd3bffa11d58342f0f491ff5a4fad4..856fccf815303cb1dc3d12c3d6a7b778d4559f73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,4 @@ /.idea/ - -/settings.properties -/target -/deploy -/build/ -/deploy_docker/ -/storage/ - -.env \ No newline at end of file +.env +target/ +config/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index f7afa1b7ab3b591dc311b725239848119513f49b..5c1d591f19913529897adb5b998347eb6bbd04cd 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,16 @@ <artifactId>spring-boot-starter-web</artifactId> </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <optional>true</optional> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> diff --git a/src/main/java/de/tobias/playwall/PlaywallServerApplication.java b/src/main/java/de/tobias/playwall/PlaywallServerApplication.java index dbdf3b8f5caf4c7a12215ed45ffe200e9473d619..67865c02bb2a0f18e056c29c93b61b019d3cf61b 100644 --- a/src/main/java/de/tobias/playwall/PlaywallServerApplication.java +++ b/src/main/java/de/tobias/playwall/PlaywallServerApplication.java @@ -1,12 +1,29 @@ package de.tobias.playwall; +import lombok.SneakyThrows; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.FileUrlResource; +import org.springframework.core.io.Resource; @SpringBootApplication public class PlaywallServerApplication { + @SneakyThrows + @Bean + public static PropertySourcesPlaceholderConfigurer properties() + { + PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); + Resource[] resources = new Resource[]{new FileUrlResource("/Users/tobias/Documents/Programmieren/Projects/PlayWall/PlayWallServer/config/plugins.yaml")}; + pspc.setLocations(resources); + pspc.setIgnoreUnresolvablePlaceholders(true); + return pspc; + } + public static void main(String[] args) { SpringApplication.run(PlaywallServerApplication.class, args); diff --git a/src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java b/src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java new file mode 100644 index 0000000000000000000000000000000000000000..3683f293f8db59c4423ba7d7455a4ea39c7119fe --- /dev/null +++ b/src/main/java/de/tobias/playwall/controller/PluginDescriptionController.java @@ -0,0 +1,24 @@ +package de.tobias.playwall.controller; + +import de.tobias.playwall.model.PluginDescription; +import de.tobias.playwall.repository.PluginDescriptionRepository; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/plugins") +@AllArgsConstructor +public class PluginDescriptionController +{ + private final PluginDescriptionRepository repository; + + @GetMapping + List<PluginDescription> getAllPlugins() + { + return repository.findAll(); + } +} diff --git a/src/main/java/de/tobias/playwall/model/PluginDescription.java b/src/main/java/de/tobias/playwall/model/PluginDescription.java new file mode 100644 index 0000000000000000000000000000000000000000..6b33fbc93c228cdc799fc33d939b4b27c6644d4c --- /dev/null +++ b/src/main/java/de/tobias/playwall/model/PluginDescription.java @@ -0,0 +1,16 @@ +package de.tobias.playwall.model; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class PluginDescription +{ + private String name; + private String displayName; + private String icon; + private String description; +} diff --git a/src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java b/src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..4509c532b67496f3d4c4e1d25d984b9a60178a7c --- /dev/null +++ b/src/main/java/de/tobias/playwall/repository/PluginDescriptionRepository.java @@ -0,0 +1,40 @@ +package de.tobias.playwall.repository; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import de.tobias.playwall.model.PluginDescription; +import jakarta.annotation.PostConstruct; +import lombok.SneakyThrows; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Service; + +import java.nio.charset.StandardCharsets; +import java.util.List; + +@Service +@EnableConfigurationProperties +public class PluginDescriptionRepository +{ + @Value("${playwall.plugin.description}") + private Resource pluginDescriptionFile; + + private ObjectMapper mapper; + + @PostConstruct + private void init() + { + mapper = new ObjectMapper(new YAMLFactory()); + mapper.findAndRegisterModules(); + } + + @SneakyThrows + public List<PluginDescription> findAll() + { + return mapper.readValue(pluginDescriptionFile.getContentAsString(StandardCharsets.UTF_8), new TypeReference<List<PluginDescription>>() + { + }); + } +}