Skip to content
Snippets Groups Projects
Commit ecc614fa authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add API to list plugin descriptions

parent 6626a7a2
No related branches found
No related tags found
No related merge requests found
/.idea/
/settings.properties
/target
/deploy
/build/
/deploy_docker/
/storage/
.env
target/
config/
\ No newline at end of file
......@@ -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>
......
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);
......
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();
}
}
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;
}
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>>()
{
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment