Refactor DatasetController and DatasetService, improve search query and add optional criteria
This commit refactors the `DatasetController` and `DatasetService` classes. It updates the request mappings in the `DatasetController` class to `/api/v1/datasets` and adds new methods for upvoting and downvoting datasets. In the `DatasetService` class, it adds the `upvoteDataset` and `downvoteDataset` methods to handle dataset upvoting and downvoting. Additionally, it improves the search query in the `getDatasetsByDateAfter` method by adding optional criteria for title, description, author, abstract, type, and minimum rating. This refactoring enhances code organization, functionality, and search capabilities.
This commit is contained in:
parent
35fcd0513b
commit
c0de764f15
@ -7,11 +7,8 @@ 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")
|
||||
@ -91,11 +88,13 @@ public class DatasetController {
|
||||
}
|
||||
|
||||
@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);
|
||||
public List<Dataset> getDatasetsByDateAfter(@RequestParam(value = "author", required = false) String author,
|
||||
@RequestParam(value = "title", required = false) String title,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "abst", required = false) String abst,
|
||||
@RequestParam(value = "type", required = false) Type type,
|
||||
@RequestParam(value = "min-raiting", required = false) Float raiting) {
|
||||
return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, raiting);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -73,7 +75,15 @@ public class DatasetService {
|
||||
datasetRepository.save(dataset);
|
||||
}
|
||||
|
||||
public List<Dataset> getDatasetsBy(String title, String author, String abst, String description) {
|
||||
return datasetRepository.findBy(title, author, abst, description);
|
||||
//public List<Dataset> getDatasetsBy(String title, String author, String abst, String description) {
|
||||
// return datasetRepository.findBy(title, author, abst, description);
|
||||
//}
|
||||
|
||||
public List<Dataset> getDatasetsByOptionalCriteria(String title, String description, String author, String abst,
|
||||
Type type, Float raiting) {
|
||||
String[] categories = null;
|
||||
return datasetRepository.findByOptionalCriteria(Optional.ofNullable(title), Optional.ofNullable(description),
|
||||
Optional.ofNullable(author), Optional.ofNullable(abst), Optional.ofNullable(type),
|
||||
Optional.ofNullable(categories), Optional.ofNullable(raiting));
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.sql.Date;
|
||||
|
||||
@ -26,9 +27,24 @@ 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);
|
||||
//@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);
|
||||
|
||||
|
||||
@Query("SELECT d FROM Dataset d WHERE " +
|
||||
"(COALESCE(:title, '') = '' OR d.title LIKE :title) AND " +
|
||||
"(COALESCE(:description, '') = '' OR d.description LIKE :description) AND" +
|
||||
"(COALESCE(:author, '') = '' OR d.author LIKE :author) AND" +
|
||||
"(COALESCE(:abst, '') = '' OR d.abst LIKE :abst) AND" +
|
||||
"(:type IS NULL OR d.type = :type) AND"+
|
||||
"(:categories IS NULL OR d.categories = :categories) AND" +
|
||||
"(:raiting IS NULL OR d.raiting > :raiting)")
|
||||
List<Dataset> findByOptionalCriteria(@Param("title") Optional<String> title,
|
||||
@Param("description") Optional<String> description,
|
||||
@Param("author") Optional<String> author,
|
||||
@Param("abst") Optional<String> abst,
|
||||
@Param("type") Optional<Type> type,
|
||||
@Param("categories") Optional<String[]> categories,
|
||||
@Param("raiting") Optional<Float> raiting);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user