feat: Add Category enum for dataset classification & Add api endpoint
This commit is contained in:
parent
ca2f67cb25
commit
5ccfe8ddb2
@ -0,0 +1,18 @@
|
||||
package de.uni_passau.fim.PADAS.group3.DataDash.controler;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import de.uni_passau.fim.PADAS.group3.DataDash.model.Category;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/categories")
|
||||
public class CategoryController {
|
||||
@GetMapping
|
||||
public Category[] getMethodName() {
|
||||
return Category.values();
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import de.uni_passau.fim.PADAS.group3.DataDash.model.Category;
|
||||
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;
|
||||
@ -82,10 +84,11 @@ 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 = "categorie", required = false) Category categories) {
|
||||
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, pageable);
|
||||
return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, raiting,categories,pageable);
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
@ -99,4 +102,4 @@ public class DatasetController {
|
||||
return datasetService.searchByOptionalCriteria(search, pageable);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
||||
|
||||
public enum Category {
|
||||
HEALTH,
|
||||
ENVIRONMENT,
|
||||
ECONOMY,
|
||||
POLITICS,
|
||||
TECHNOLOGY,
|
||||
SPORTS,
|
||||
SCIENCE,
|
||||
CULTURE,
|
||||
EDUCATION,
|
||||
OTHER
|
||||
}
|
@ -38,10 +38,10 @@ public class Dataset {
|
||||
private int upvotes;
|
||||
|
||||
private URL url;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Category categorie;
|
||||
|
||||
private String[] categories;
|
||||
|
||||
public Dataset(String title, String abst, String description, String author, URL url, String[] categories, Type type) {
|
||||
public Dataset(String title, String abst, String description, String author, URL url, Category categories, Type type) {
|
||||
|
||||
this.raiting = 0;
|
||||
this.votes = 0;
|
||||
@ -51,7 +51,7 @@ public class Dataset {
|
||||
setDescription(description);
|
||||
setAuthor(author);
|
||||
setDate(LocalDate.now());
|
||||
setCategories(categories);
|
||||
setCategorie(categories);
|
||||
setType(type);
|
||||
setUrl(url);
|
||||
}
|
||||
@ -68,8 +68,8 @@ public class Dataset {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String[] getCategories() {
|
||||
return categories;
|
||||
public Category getCategorie() {
|
||||
return categorie;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
@ -116,8 +116,8 @@ public class Dataset {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public void setCategories(String[] categories) {
|
||||
this.categories = categories;
|
||||
public void setCategorie(Category categories) {
|
||||
this.categorie = categories;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate localDate) {
|
||||
|
@ -85,11 +85,10 @@ public class DatasetService {
|
||||
}
|
||||
|
||||
public Page<Dataset> getDatasetsByOptionalCriteria(String title, String description, String author, String abst,
|
||||
Type type, Float raiting, Pageable pageable) {
|
||||
String[] categories = null;
|
||||
Type type, Float raiting, Category category, Pageable pageable) {
|
||||
return datasetRepository.findByOptionalCriteria(Optional.ofNullable(title), Optional.ofNullable(description),
|
||||
Optional.ofNullable(author), Optional.ofNullable(abst), Optional.ofNullable(type),
|
||||
Optional.ofNullable(categories), Optional.ofNullable(raiting), pageable);
|
||||
Optional.ofNullable(author), Optional.ofNullable(abst), Optional.ofNullable(type), Optional.ofNullable(category),
|
||||
Optional.ofNullable(raiting), pageable);
|
||||
}
|
||||
|
||||
public Page<Dataset> searchByOptionalCriteria(String search, Pageable pageable) {
|
||||
|
@ -23,7 +23,7 @@ public class LoadDummyDatabase {
|
||||
|
||||
return args -> {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Dataset dataset = new Dataset("Title" + i, "Abst" + i, "Description" + i, "Author" + i,null, new String[]{"Category" + i}, Type.API);
|
||||
Dataset dataset = new Dataset("Title" + i, "Abst" + i, "Description" + i, "Author" + i,null, Category.EDUCATION, Type.API);
|
||||
repository.save(dataset);
|
||||
log.info("Preloading" + repository.save(dataset));
|
||||
}
|
||||
|
@ -12,48 +12,60 @@ 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> {
|
||||
|
||||
Dataset getDatasetById(UUID id);
|
||||
List<Dataset> findByTitle(String title);
|
||||
List<Dataset> findByTitleLike(String title);
|
||||
List<Dataset> findByAuthorLike(String author);
|
||||
List<Dataset> findByType(Type type);
|
||||
List<Dataset> findByAuthor(String author);
|
||||
List<Dataset> findByAbstLike(String abst);
|
||||
List<Dataset> findByDescriptionLike(String description);
|
||||
List<Dataset> findByCategories(String[] categories);
|
||||
List<Dataset> findByRaitingGreaterThan(float raiting);
|
||||
List<Dataset> findByVotesGreaterThan(int votes);
|
||||
List<Dataset> findByDateAfter(Date date);
|
||||
List<Dataset> findByDateBefore(Date date);
|
||||
List<Dataset> findByDateBetween(Date date1, Date date2);
|
||||
@SuppressWarnings("null")
|
||||
Page<Dataset> findAll(Pageable pageable);
|
||||
Dataset getDatasetById(UUID id);
|
||||
|
||||
@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)")
|
||||
Page<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,
|
||||
Pageable pageable);
|
||||
List<Dataset> findByTitle(String title);
|
||||
|
||||
List<Dataset> findByTitleLike(String title);
|
||||
|
||||
@Query("SELECT d FROM Dataset d WHERE " +
|
||||
"(LOWER(d.title) LIKE LOWER(:search)) OR " +
|
||||
"(LOWER(d.description) LIKE LOWER(:search)) OR " +
|
||||
"(LOWER(d.author) LIKE LOWER(:search))")
|
||||
Page<Dataset>searchByOptionalCriteria(@Param("search") Optional<String> search,
|
||||
Pageable pageable);
|
||||
|
||||
List<Dataset> findByAuthorLike(String author);
|
||||
|
||||
List<Dataset> findByType(Type type);
|
||||
|
||||
List<Dataset> findByAuthor(String author);
|
||||
|
||||
List<Dataset> findByAbstLike(String abst);
|
||||
|
||||
List<Dataset> findByDescriptionLike(String description);
|
||||
|
||||
List<Dataset> findByRaitingGreaterThan(float raiting);
|
||||
|
||||
List<Dataset> findByVotesGreaterThan(int votes);
|
||||
|
||||
List<Dataset> findByDateAfter(Date date);
|
||||
|
||||
List<Dataset> findByDateBefore(Date date);
|
||||
|
||||
List<Dataset> findByCategorie(Category categorie);
|
||||
|
||||
List<Dataset> findByDateBetween(Date date1, Date date2);
|
||||
|
||||
@SuppressWarnings("null")
|
||||
Page<Dataset> findAll(Pageable pageable);
|
||||
|
||||
@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" +
|
||||
"(:categorie IS NULL OR d.categorie = :categorie) AND" +
|
||||
"(:raiting IS NULL OR d.raiting > :raiting)")
|
||||
Page<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("categorie") Optional<Category> categories,
|
||||
@Param("raiting") Optional<Float> raiting,
|
||||
Pageable pageable);
|
||||
|
||||
@Query("SELECT d FROM Dataset d WHERE " +
|
||||
"(LOWER(d.title) LIKE LOWER(:search)) OR " +
|
||||
"(LOWER(d.description) LIKE LOWER(:search)) OR " +
|
||||
"(LOWER(d.author) LIKE LOWER(:search))")
|
||||
Page<Dataset> searchByOptionalCriteria(@Param("search") Optional<String> search,
|
||||
Pageable pageable);
|
||||
}
|
Loading…
Reference in New Issue
Block a user