Merge remote-tracking branch 'origin/11-add-api-for-getting-home-page-data' into 22-integrate-api-and-frontend
This commit is contained in:
commit
a883d8217e
@ -75,20 +75,20 @@ public class DatasetController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Page<Dataset> getDatasetsByDateAfter(@RequestParam(value = "author", required = false) String author,
|
||||
public Page<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,
|
||||
@RequestParam(value = "min-rating", required = false) Float rating,
|
||||
@RequestParam(value = "page", required = false, defaultValue = "0") int page,
|
||||
@RequestParam(value = "size", required = false, defaultValue = "20") int size,
|
||||
@RequestParam(value = "sort", required = false, defaultValue = "upvotes") String sort,
|
||||
@RequestParam(value = "direction", required = false, defaultValue = "desc") String direction,
|
||||
@RequestParam(value = "categorie", required = false) Category categories) {
|
||||
@RequestParam(value = "category", required = false) Category category) {
|
||||
Pageable pageable = PageRequest.of(page, size,
|
||||
Sort.by(direction.equals("asc") ? Sort.Direction.ASC : Sort.Direction.DESC, sort));
|
||||
return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, raiting, categories,pageable);
|
||||
return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, rating, category,pageable);
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
@ -96,10 +96,12 @@ public class DatasetController {
|
||||
@RequestParam(value = "page", required = false, defaultValue = "0") int page,
|
||||
@RequestParam(value = "size", required = false, defaultValue = "20") int size,
|
||||
@RequestParam(value = "sort", required = false, defaultValue = "upvotes") String sort,
|
||||
@RequestParam(value = "direction", required = false, defaultValue = "desc") String direction) {
|
||||
@RequestParam(value = "direction", required = false, defaultValue = "desc") String direction,
|
||||
@RequestParam(value = "category", required = false, defaultValue = "%") String category,
|
||||
@RequestParam(value = "type", required = false, defaultValue = "%") String type){
|
||||
Pageable pageable = PageRequest.of(page, size,
|
||||
Sort.by(direction.equals("asc") ? Sort.Direction.ASC : Sort.Direction.DESC, sort));
|
||||
return datasetService.searchByOptionalCriteria(search, pageable);
|
||||
return datasetService.searchByOptionalCriteria(search, category, type, pageable);
|
||||
}
|
||||
|
||||
}
|
@ -93,10 +93,11 @@ public class DatasetService {
|
||||
Optional.ofNullable(raiting), pageable);
|
||||
}
|
||||
|
||||
public Page<Dataset> searchByOptionalCriteria(String search, Pageable pageable) {
|
||||
if (search.equals("%")) {
|
||||
return datasetRepository.findAll(pageable);
|
||||
}
|
||||
return datasetRepository.searchByOptionalCriteria(Optional.ofNullable(search), pageable);
|
||||
public Page<Dataset> searchByOptionalCriteria(String search, String categories, String type, Pageable pageable) {
|
||||
//TODO: make it not Crash
|
||||
Category category = categories.equals("%") ? null : Category.valueOf(categories);
|
||||
Type t = type.equals("%") ? null : Type.valueOf(type);
|
||||
|
||||
return datasetRepository.searchByOptionalCriteria(Optional.ofNullable(search), Optional.ofNullable(category), Optional.ofNullable(t),pageable);
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ 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> {
|
||||
|
||||
Dataset getDatasetById(UUID id);
|
||||
@ -63,9 +62,13 @@ public interface dataRepository extends JpaRepository<Dataset, UUID> {
|
||||
Pageable pageable);
|
||||
|
||||
@Query("SELECT d FROM Dataset d WHERE " +
|
||||
"(LOWER(d.title) LIKE LOWER(:search)) OR " +
|
||||
"((LOWER(d.title) LIKE LOWER(:search)) OR " +
|
||||
"(LOWER(d.description) LIKE LOWER(:search)) OR " +
|
||||
"(LOWER(d.author) LIKE LOWER(:search))")
|
||||
"(LOWER(d.author) LIKE LOWER(:search))) AND" +
|
||||
"(:categorie IS NULL OR d.categorie = :categorie) AND" +
|
||||
"(:type IS NULL OR d.type = :type)")
|
||||
Page<Dataset> searchByOptionalCriteria(@Param("search") Optional<String> search,
|
||||
@Param("categorie") Optional<Category> categories,
|
||||
@Param("type") Optional<Type> type,
|
||||
Pageable pageable);
|
||||
}
|
Loading…
Reference in New Issue
Block a user