chore: Refactor DatasetController and DatasetService, add upvote and downvote functionality and create new search quirey to use with request parameters
This commit is contained in:
parent
4a09da87d3
commit
35fcd0513b
@ -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<Dataset> getAllDatasets() {
|
||||
return datasetService.getAllDatasets();
|
||||
}
|
||||
|
||||
|
||||
// @GetMapping
|
||||
// public List<Dataset> 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<Dataset> getByAuthor(@PathVariable("author") String author) {
|
||||
return datasetService.getDatasetsByAuthorLike(author);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/abst/{abst}")
|
||||
public List<Dataset> 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<Dataset> 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);
|
||||
}
|
||||
|
||||
}
|
@ -72,4 +72,8 @@ public class DatasetService {
|
||||
dataset.downvote();
|
||||
datasetRepository.save(dataset);
|
||||
}
|
||||
|
||||
public List<Dataset> getDatasetsBy(String title, String author, String abst, String description) {
|
||||
return datasetRepository.findBy(title, author, abst, description);
|
||||
}
|
||||
}
|
@ -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<Dataset, UUID>{
|
||||
|
||||
@ -23,5 +25,10 @@ public interface dataRepository extends JpaRepository<Dataset, UUID>{
|
||||
List<Dataset> findByDateBefore(Date date);
|
||||
List<Dataset> findByDateBetween(Date date1, Date date2);
|
||||
List<Dataset> 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<Dataset> findBy(@Param("title") String title, @Param("author") String author, @Param("abst") String abst, @Param("description") String description);
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user