feat: Add Category enum for dataset classification & Add api endpoint
This commit is contained in:
		@@ -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.Page;
 | 
				
			||||||
import org.springframework.data.domain.PageRequest;
 | 
					import org.springframework.data.domain.PageRequest;
 | 
				
			||||||
import org.springframework.web.bind.annotation.*;
 | 
					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.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;
 | 
				
			||||||
@@ -82,10 +84,11 @@ public class DatasetController {
 | 
				
			|||||||
            @RequestParam(value = "page", required = false, defaultValue = "0") int page,
 | 
					            @RequestParam(value = "page", required = false, defaultValue = "0") int page,
 | 
				
			||||||
            @RequestParam(value = "size", required = false, defaultValue = "20") int size,
 | 
					            @RequestParam(value = "size", required = false, defaultValue = "20") int size,
 | 
				
			||||||
            @RequestParam(value = "sort", required = false, defaultValue = "upvotes") String sort,
 | 
					            @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,
 | 
					        Pageable pageable = PageRequest.of(page, size,
 | 
				
			||||||
                Sort.by(direction.equals("asc") ? Sort.Direction.ASC : Sort.Direction.DESC, sort));
 | 
					                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")
 | 
					    @GetMapping("/search")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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 int upvotes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private URL url;
 | 
					    private URL url;
 | 
				
			||||||
 | 
					    @Enumerated(EnumType.STRING)
 | 
				
			||||||
 | 
					    private Category categorie;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private String[] categories;
 | 
					    public Dataset(String title, String abst, String description, String author, URL url, Category categories, Type type) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public Dataset(String title, String abst, String description, String author, URL url, String[] categories, Type type) {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.raiting = 0;
 | 
					        this.raiting = 0;
 | 
				
			||||||
        this.votes = 0;
 | 
					        this.votes = 0;
 | 
				
			||||||
@@ -51,7 +51,7 @@ public class Dataset {
 | 
				
			|||||||
        setDescription(description);        
 | 
					        setDescription(description);        
 | 
				
			||||||
        setAuthor(author);
 | 
					        setAuthor(author);
 | 
				
			||||||
        setDate(LocalDate.now());        
 | 
					        setDate(LocalDate.now());        
 | 
				
			||||||
        setCategories(categories);        
 | 
					        setCategorie(categories);        
 | 
				
			||||||
        setType(type);
 | 
					        setType(type);
 | 
				
			||||||
        setUrl(url);
 | 
					        setUrl(url);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -68,8 +68,8 @@ public class Dataset {
 | 
				
			|||||||
        return author;
 | 
					        return author;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String[] getCategories() {
 | 
					    public Category getCategorie() {
 | 
				
			||||||
        return categories;
 | 
					        return categorie;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public LocalDate getDate() {
 | 
					    public LocalDate getDate() {
 | 
				
			||||||
@@ -116,8 +116,8 @@ public class Dataset {
 | 
				
			|||||||
        this.author = author;
 | 
					        this.author = author;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void setCategories(String[] categories) {
 | 
					    public void setCategorie(Category categories) {
 | 
				
			||||||
        this.categories = categories;
 | 
					        this.categorie = categories;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public void setDate(LocalDate localDate) {
 | 
					    public void setDate(LocalDate localDate) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -85,11 +85,10 @@ public class DatasetService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Page<Dataset> getDatasetsByOptionalCriteria(String title, String description, String author, String abst,
 | 
					    public Page<Dataset> getDatasetsByOptionalCriteria(String title, String description, String author, String abst,
 | 
				
			||||||
            Type type, Float raiting, Pageable pageable) {
 | 
					            Type type, Float raiting, Category category, Pageable pageable) {
 | 
				
			||||||
        String[] categories = null;
 | 
					 | 
				
			||||||
        return datasetRepository.findByOptionalCriteria(Optional.ofNullable(title), Optional.ofNullable(description),
 | 
					        return datasetRepository.findByOptionalCriteria(Optional.ofNullable(title), Optional.ofNullable(description),
 | 
				
			||||||
                Optional.ofNullable(author), Optional.ofNullable(abst), Optional.ofNullable(type),
 | 
					                Optional.ofNullable(author), Optional.ofNullable(abst), Optional.ofNullable(type), Optional.ofNullable(category),
 | 
				
			||||||
                Optional.ofNullable(categories), Optional.ofNullable(raiting), pageable);
 | 
					                Optional.ofNullable(raiting), pageable);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Page<Dataset> searchByOptionalCriteria(String search, Pageable pageable) {
 | 
					    public Page<Dataset> searchByOptionalCriteria(String search, Pageable pageable) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ public class LoadDummyDatabase {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return args -> {
 | 
					        return args -> {
 | 
				
			||||||
        for (int i = 0; i < 100; i++) {
 | 
					        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);
 | 
					            repository.save(dataset);
 | 
				
			||||||
            log.info("Preloading" + 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;
 | 
					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);
 | 
					        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);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Query("SELECT d FROM Dataset d WHERE " +
 | 
					        List<Dataset> findByTitle(String title);
 | 
				
			||||||
    "(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> findByTitleLike(String title);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
     @Query("SELECT d FROM Dataset d WHERE " +
 | 
					        List<Dataset> findByAuthorLike(String author);
 | 
				
			||||||
    "(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> 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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user