From 10e339f32b2ff8d66346b80305598e76f730170e Mon Sep 17 00:00:00 2001 From: Erik Foris Date: Mon, 17 Jun 2024 18:13:25 +0200 Subject: [PATCH] feature: add minimal API --- .../DataDash/controler/DatasetController.java | 84 +++++++++++++++++++ .../group3/DataDash/model/DatasetService.java | 65 ++++++++++++++ .../group3/DataDash/model/dataRepository.java | 3 + 3 files changed, 152 insertions(+) create mode 100644 src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/DatasetController.java create mode 100644 src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/DatasetService.java diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/DatasetController.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/DatasetController.java new file mode 100644 index 0000000..37cdf87 --- /dev/null +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/controler/DatasetController.java @@ -0,0 +1,84 @@ +package de.uni_passau.fim.PADAS.group3.DataDash.controler; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.web.bind.annotation.*; + +import de.uni_passau.fim.PADAS.group3.DataDash.model.Dataset; +import de.uni_passau.fim.PADAS.group3.DataDash.model.DatasetService; + +import java.util.List; +import java.util.UUID; +import de.uni_passau.fim.PADAS.group3.DataDash.model.Type; + +import javax.swing.text.html.HTML; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + + + + @RestController + @RequestMapping("/api/datasets") + public class DatasetController { + @Autowired + private DatasetService datasetService; + + @GetMapping + public List getAllDatasets() { + return datasetService.getAllDatasets(); + } + + @GetMapping("/id/{id}") + public Dataset getDatasetById(@PathVariable("id") UUID id) { + return datasetService.getDatasetById(id); + } + + @PostMapping + public Dataset createDataset(@RequestBody Dataset dataset) { + datasetService.addDataset(dataset); + //TODO: figure out what the fuck i need to do here + return null; + } + + //@PutMapping("/{id}") + //public Dataset updateDataset(@PathVariable("id") Long id, @RequestBody Dataset dataset) { + // return datasetService.updateDataset(id, dataset); + //} + // + + @DeleteMapping("/id/{id}") + public void deleteDataset(@PathVariable("id") UUID id) { + datasetService.deleteDataset(id); + } + + @GetMapping("/title/{title}") + public List getByTitle(@PathVariable("title") String title) { + return datasetService.getDatasetsByTitleLike(title); + } + + @GetMapping("/description/{description}") + public List getbyDescription(@PathVariable("description") String description) { + return datasetService.findByDescriptionLike(description); + } + + @GetMapping("/author/{author}") + public List getByAuthor(@PathVariable("author") String author) { + return datasetService.getDatasetsByAuthorLike(author); + } + + @GetMapping("/abst/{abst}") + public List getByAbstract(@PathVariable("abst") String abst) { + return datasetService.getDatasetsByAbstLike(abst); + } + + @GetMapping("/type/{type}") + public List getByType(@PathVariable("type") Type type) { + return datasetService.getDatasetsByType(type); + } + + @GetMapping("/rating/{rating}") + public List getByType(@PathVariable("rating") float rating) { + return datasetService.getDatasetsByRaitingGreaterThan(rating); + } + +} \ No newline at end of file diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/DatasetService.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/DatasetService.java new file mode 100644 index 0000000..0bf9a2f --- /dev/null +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/DatasetService.java @@ -0,0 +1,65 @@ +package de.uni_passau.fim.PADAS.group3.DataDash.model; +import java.util.List; +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class DatasetService { + private dataRepository datasetRepository; + + @Autowired + public DatasetService(dataRepository datasetRepository) { + this.datasetRepository = datasetRepository; + } + + public List getAllDatasets() { + return datasetRepository.findAll(); + } + + public Dataset getDatasetById(UUID id) { + return datasetRepository.getDatasetById(id); + } + + public void addDataset(Dataset dataset) { + datasetRepository.save(dataset); + } + + public void updateDatasetTitle(UUID id, String title) { + datasetRepository.getDatasetById(id).setTitle(title); + } + + public void deleteDataset(UUID id) { + Dataset dataset = datasetRepository.getDatasetById(id); + datasetRepository.delete(dataset); + } + + public List getDatasetsByTitle(String title) { + return datasetRepository.findByTitle(title); + } + + public List getDatasetsByTitleLike(String title) { + return datasetRepository.findByTitleLike(title); + } + + public List findByDescriptionLike(String description) { + return datasetRepository.findByDescriptionLike(description); + } + + public List getDatasetsByAuthorLike(String author) { + return datasetRepository.findByAuthorLike(author); + } + + public List getDatasetsByType(Type type) { + return datasetRepository.findByType(type); + } + + public List getDatasetsByAbstLike(String abst) { + return datasetRepository.findByAbstLike(abst); + } + + public List getDatasetsByRaitingGreaterThan(float raiting) { + return datasetRepository.findByRaitingGreaterThan(raiting); + } +} \ No newline at end of file diff --git a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/dataRepository.java b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/dataRepository.java index 46fd8d4..1462932 100644 --- a/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/dataRepository.java +++ b/src/main/java/de/uni_passau/fim/PADAS/group3/DataDash/model/dataRepository.java @@ -3,10 +3,12 @@ package de.uni_passau.fim.PADAS.group3.DataDash.model; import java.util.List; import java.util.UUID; import java.sql.Date; + import org.springframework.data.jpa.repository.JpaRepository; public interface dataRepository extends JpaRepository{ + Dataset getDatasetById(UUID id); List findByTitle(String title); List findByTitleLike(String title); List findByAuthorLike(String author); @@ -20,5 +22,6 @@ public interface dataRepository extends JpaRepository{ List findByDateAfter(Date date); List findByDateBefore(Date date); List findByDateBetween(Date date1, Date date2); + List findAll(); } \ No newline at end of file