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:
		@@ -6,25 +6,23 @@ 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) {
 | 
			
		||||
@@ -34,14 +32,15 @@ public class DatasetController {
 | 
			
		||||
    @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) {
 | 
			
		||||
    // @PutMapping("/{id}")
 | 
			
		||||
    // public Dataset updateDataset(@PathVariable("id") Long id, @RequestBody
 | 
			
		||||
    // Dataset dataset) {
 | 
			
		||||
    // return datasetService.updateDataset(id, dataset);
 | 
			
		||||
    //}
 | 
			
		||||
    // }
 | 
			
		||||
    //
 | 
			
		||||
 | 
			
		||||
    @DeleteMapping("/id/{id}")
 | 
			
		||||
@@ -88,8 +87,15 @@ public class DatasetController {
 | 
			
		||||
    @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>{
 | 
			
		||||
 | 
			
		||||
@@ -24,4 +26,9 @@ public interface dataRepository extends JpaRepository<Dataset, UUID>{
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user