Merge branch '11-add-api-for-getting-home-page-data' into 22-integrate-api-and-frontend
This commit is contained in:
commit
c98602520b
@ -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")
|
||||||
@ -99,4 +102,4 @@ public class DatasetController {
|
|||||||
return datasetService.searchByOptionalCriteria(search, pageable);
|
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
|
||||||
|
}
|
@ -3,6 +3,7 @@ package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EnumType;
|
import jakarta.persistence.EnumType;
|
||||||
@ -29,7 +30,7 @@ public class Dataset {
|
|||||||
|
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
private LocalDate date;
|
private Date date;
|
||||||
|
|
||||||
private float raiting;
|
private float raiting;
|
||||||
|
|
||||||
@ -38,10 +39,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 +52,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,12 +69,12 @@ public class Dataset {
|
|||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getCategories() {
|
public Category getCategorie() {
|
||||||
return categories;
|
return categorie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getDate() {
|
public LocalDate getDate() {
|
||||||
return date;
|
return date.toLocalDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
@ -116,12 +117,12 @@ 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) {
|
||||||
this.date = localDate;
|
this.date = Date.valueOf(localDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
|
@ -85,16 +85,14 @@ 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) {
|
||||||
if (search.equals("%")) {
|
if (search.equals("%")) {
|
||||||
System.out.println("searching for all datasets");
|
|
||||||
return datasetRepository.findAll(pageable);
|
return datasetRepository.findAll(pageable);
|
||||||
}
|
}
|
||||||
return datasetRepository.searchByOptionalCriteria(Optional.ofNullable(search), pageable);
|
return datasetRepository.searchByOptionalCriteria(Optional.ofNullable(search), pageable);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
||||||
|
|
||||||
import java.net.URL;
|
|
||||||
import java.sql.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -23,7 +21,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 " +
|
List<Dataset> findByType(Type type);
|
||||||
"(LOWER(d.author) LIKE LOWER(:search))")
|
|
||||||
Page<Dataset>searchByOptionalCriteria(@Param("search") Optional<String> search,
|
List<Dataset> findByAuthor(String author);
|
||||||
Pageable pageable);
|
|
||||||
|
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