From 35fcd0513bdc0bf4493b340d919018dae74535c5 Mon Sep 17 00:00:00 2001 From: Erik Foris Date: Tue, 18 Jun 2024 13:35:15 +0200 Subject: [PATCH] chore: Refactor DatasetController and DatasetService, add upvote and downvote functionality and create new search quirey to use with request parameters --- .../DataDash/controler/DatasetController.java | 46 +++++++++++-------- .../group3/DataDash/model/DatasetService.java | 4 ++ .../group3/DataDash/model/dataRepository.java | 7 +++ 3 files changed, 37 insertions(+), 20 deletions(-) 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 index 47a8829..5121e6d 100644 --- 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 @@ -6,42 +6,41 @@ 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 de.uni_passau.fim.PADAS.group3.DataDash.model.Type; + +import java.sql.Date; import java.util.List; import java.util.UUID; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; - - - - @RestController @RequestMapping("/api/v1/datasets") public class DatasetController { @Autowired private DatasetService datasetService; - - @GetMapping - public List getAllDatasets() { - return datasetService.getAllDatasets(); - } - + + // @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 + // 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); - //} + + // @PutMapping("/{id}") + // public Dataset updateDataset(@PathVariable("id") Long id, @RequestBody + // Dataset dataset) { + // return datasetService.updateDataset(id, dataset); + // } // @DeleteMapping("/id/{id}") @@ -63,7 +62,7 @@ public class DatasetController { 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); @@ -81,15 +80,22 @@ public class DatasetController { @PostMapping("/id/{id}/upvote") public Dataset upvote(@PathVariable("id") UUID id) { - datasetService.upvoteDataset(id); + datasetService.upvoteDataset(id); return null; } @PostMapping("/id/{id}/downvote") public Dataset downvote(@PathVariable("id") UUID id) { datasetService.downvoteDataset(id); - return null; //new ResponseEntity<>(null, HttpStatus.OK); + return null; // new ResponseEntity<>(null, HttpStatus.OK); } + @GetMapping + public List getDatasetsByDateAfter(@RequestParam(value = "author", required = false, defaultValue = "%") String author, + @RequestParam(value = "title", required = false, defaultValue = "%") String title, + @RequestParam(value = "description", required = false, defaultValue = "%") String description, + @RequestParam(value = "abst", required = false, defaultValue = "%") String abst) { + return datasetService.getDatasetsBy(title, author, abst, description); + } } \ 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 index 0ddefef..fb5c824 100644 --- 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 @@ -72,4 +72,8 @@ public class DatasetService { dataset.downvote(); datasetRepository.save(dataset); } + + public List getDatasetsBy(String title, String author, String abst, String description) { + return datasetRepository.findBy(title, author, abst, description); + } } \ 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 1462932..f616455 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 @@ -5,6 +5,8 @@ import java.util.UUID; import java.sql.Date; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface dataRepository extends JpaRepository{ @@ -23,5 +25,10 @@ public interface dataRepository extends JpaRepository{ List findByDateBefore(Date date); List findByDateBetween(Date date1, Date date2); List findAll(); + + @Query("SELECT d FROM Dataset d WHERE d.title LIKE :title AND d.author LIKE :author AND d.abst LIKE :abst AND d.description LIKE :description") + List findBy(@Param("title") String title, @Param("author") String author, @Param("abst") String abst, @Param("description") String description); + + } \ No newline at end of file