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.Dataset;
 | 
				
			||||||
import de.uni_passau.fim.PADAS.group3.DataDash.model.DatasetService;
 | 
					import de.uni_passau.fim.PADAS.group3.DataDash.model.DatasetService;
 | 
				
			||||||
import de.uni_passau.fim.PADAS.group3.DataDash.model.Type;
 | 
					import de.uni_passau.fim.PADAS.group3.DataDash.model.Type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.sql.Date;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
import org.springframework.web.bind.annotation.PostMapping;
 | 
					import org.springframework.web.bind.annotation.PostMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestBody;
 | 
					import org.springframework.web.bind.annotation.RequestBody;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@RestController
 | 
					@RestController
 | 
				
			||||||
@RequestMapping("/api/v1/datasets")
 | 
					@RequestMapping("/api/v1/datasets")
 | 
				
			||||||
public class DatasetController {
 | 
					public class DatasetController {
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private DatasetService datasetService;
 | 
					    private DatasetService datasetService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping
 | 
					    // @GetMapping
 | 
				
			||||||
    public List<Dataset> getAllDatasets() {
 | 
					    // public List<Dataset> getAllDatasets() {
 | 
				
			||||||
        return datasetService.getAllDatasets();
 | 
					    // return datasetService.getAllDatasets();
 | 
				
			||||||
    }
 | 
					    // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping("/id/{id}")
 | 
					    @GetMapping("/id/{id}")
 | 
				
			||||||
    public Dataset getDatasetById(@PathVariable("id") UUID id) {
 | 
					    public Dataset getDatasetById(@PathVariable("id") UUID id) {
 | 
				
			||||||
@@ -39,7 +37,8 @@ public class DatasetController {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // @PutMapping("/{id}")
 | 
					    // @PutMapping("/{id}")
 | 
				
			||||||
    //public Dataset updateDataset(@PathVariable("id") Long id, @RequestBody Dataset dataset) {
 | 
					    // public Dataset updateDataset(@PathVariable("id") Long id, @RequestBody
 | 
				
			||||||
 | 
					    // Dataset dataset) {
 | 
				
			||||||
    // return datasetService.updateDataset(id, dataset);
 | 
					    // return datasetService.updateDataset(id, dataset);
 | 
				
			||||||
    // }
 | 
					    // }
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
@@ -91,5 +90,12 @@ public class DatasetController {
 | 
				
			|||||||
        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();
 | 
					        dataset.downvote();
 | 
				
			||||||
        datasetRepository.save(dataset);
 | 
					        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 java.sql.Date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
					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>{
 | 
					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> findByDateBetween(Date date1, Date date2);
 | 
				
			||||||
    List<Dataset> findAll();
 | 
					    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