Merge branch '19-add-ability-to-page-requests' into '11-add-api-for-getting-home-page-data'
Resolve "Add ability to page requests" See merge request padas/24ss-5430-web-and-data-eng/gruppe-3/datadash!16
This commit is contained in:
commit
800e3d955c
@ -1,17 +1,22 @@
|
|||||||
package de.uni_passau.fim.PADAS.group3.DataDash.controler;
|
package de.uni_passau.fim.PADAS.group3.DataDash.controler;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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 org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
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;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/datasets")
|
@RequestMapping("/api/v1/datasets")
|
||||||
|
@EnableSpringDataWebSupport
|
||||||
public class DatasetController {
|
public class DatasetController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DatasetService datasetService;
|
private DatasetService datasetService;
|
||||||
@ -45,36 +50,6 @@ public class DatasetController {
|
|||||||
datasetService.deleteDataset(id);
|
datasetService.deleteDataset(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/title/{title}")
|
|
||||||
public List<Dataset> getByTitle(@PathVariable("title") String title) {
|
|
||||||
return datasetService.getDatasetsByTitleLike(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/description/{description}")
|
|
||||||
public List<Dataset> getbyDescription(@PathVariable("description") String description) {
|
|
||||||
return datasetService.findByDescriptionLike(description);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/author/{author}")
|
|
||||||
public List<Dataset> getByAuthor(@PathVariable("author") String author) {
|
|
||||||
return datasetService.getDatasetsByAuthorLike(author);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/abst/{abst}")
|
|
||||||
public List<Dataset> getByAbstract(@PathVariable("abst") String abst) {
|
|
||||||
return datasetService.getDatasetsByAbstLike(abst);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/type/{type}")
|
|
||||||
public List<Dataset> getByType(@PathVariable("type") Type type) {
|
|
||||||
return datasetService.getDatasetsByType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/rating/{rating}")
|
|
||||||
public List<Dataset> getByType(@PathVariable("rating") float rating) {
|
|
||||||
return datasetService.getDatasetsByRaitingGreaterThan(rating);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/id/{id}/upvote")
|
@PostMapping("/id/{id}/upvote")
|
||||||
public Dataset upvote(@PathVariable("id") UUID id) {
|
public Dataset upvote(@PathVariable("id") UUID id) {
|
||||||
datasetService.upvoteDataset(id);
|
datasetService.upvoteDataset(id);
|
||||||
@ -88,13 +63,30 @@ public class DatasetController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public List<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 = "title", required = false) String title,
|
||||||
@RequestParam(value = "description", required = false) String description,
|
@RequestParam(value = "description", required = false) String description,
|
||||||
@RequestParam(value = "abst", required = false) String abst,
|
@RequestParam(value = "abst", required = false) String abst,
|
||||||
@RequestParam(value = "type", required = false) Type type,
|
@RequestParam(value = "type", required = false) Type type,
|
||||||
@RequestParam(value = "min-raiting", required = false) Float raiting) {
|
@RequestParam(value = "min-raiting", required = false) Float raiting,
|
||||||
return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, raiting);
|
@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) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/search")
|
||||||
|
public Page<Dataset> search(@RequestParam(value = "search", required = false, defaultValue = "%") String search,
|
||||||
|
@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) {
|
||||||
|
Pageable pageable = PageRequest.of(page, size,
|
||||||
|
Sort.by(direction.equals("asc") ? Sort.Direction.ASC : Sort.Direction.DESC, sort));
|
||||||
|
return datasetService.searchByOptionalCriteria(search, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,12 @@
|
|||||||
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.sql.Date;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.cglib.core.Local;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EnumType;
|
import jakarta.persistence.EnumType;
|
||||||
import jakarta.persistence.Enumerated;
|
import jakarta.persistence.Enumerated;
|
||||||
@ -27,7 +32,7 @@ public class Dataset {
|
|||||||
|
|
||||||
private String author;
|
private String author;
|
||||||
|
|
||||||
private Date date;
|
private LocalDate date;
|
||||||
|
|
||||||
private float raiting;
|
private float raiting;
|
||||||
|
|
||||||
@ -35,9 +40,11 @@ public class Dataset {
|
|||||||
|
|
||||||
private int upvotes;
|
private int upvotes;
|
||||||
|
|
||||||
|
private URL url;
|
||||||
|
|
||||||
private String[] categories;
|
private String[] categories;
|
||||||
|
|
||||||
public Dataset(String title, String abst, String description, String author, Date date, String[] categories, Type type) {
|
public Dataset(String title, String abst, String description, String author, String[] categories, Type type) {
|
||||||
|
|
||||||
this.raiting = 0;
|
this.raiting = 0;
|
||||||
this.votes = 0;
|
this.votes = 0;
|
||||||
@ -46,9 +53,10 @@ public class Dataset {
|
|||||||
setAbst(abst);
|
setAbst(abst);
|
||||||
setDescription(description);
|
setDescription(description);
|
||||||
setAuthor(author);
|
setAuthor(author);
|
||||||
setDate(date);
|
setDate(LocalDate.now());
|
||||||
setCategories(categories);
|
setCategories(categories);
|
||||||
setType(type);
|
setType(type);
|
||||||
|
setUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dataset() {
|
public Dataset() {
|
||||||
@ -67,7 +75,7 @@ public class Dataset {
|
|||||||
return categories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDate() {
|
public LocalDate getDate() {
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +107,10 @@ public class Dataset {
|
|||||||
return upvotes;
|
return upvotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URL getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAbst(String abst) {
|
public void setAbst(String abst) {
|
||||||
this.abst = abst.substring(0, Math.min(abst.length(), 100));
|
this.abst = abst.substring(0, Math.min(abst.length(), 100));
|
||||||
}
|
}
|
||||||
@ -111,13 +123,17 @@ public class Dataset {
|
|||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDate(Date date) {
|
public void setDate(LocalDate localDate) {
|
||||||
this.date = date;
|
this.date = localDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUrl(URL url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title.substring(0, Math.min(title.length(), 50));
|
this.title = title.substring(0, Math.min(title.length(), 50));
|
||||||
|
@ -4,7 +4,11 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.apache.juli.logging.Log;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class DatasetService {
|
public class DatasetService {
|
||||||
@ -75,11 +79,19 @@ public class DatasetService {
|
|||||||
datasetRepository.save(dataset);
|
datasetRepository.save(dataset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<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) {
|
Type type, Float raiting, Pageable pageable) {
|
||||||
String[] categories = null;
|
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(categories), Optional.ofNullable(raiting));
|
Optional.ofNullable(categories), Optional.ofNullable(raiting), pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<Dataset> searchByOptionalCriteria(String search, Pageable pageable) {
|
||||||
|
if (search.equals("%")) {
|
||||||
|
System.out.println("searching for all datasets");
|
||||||
|
return datasetRepository.findAll(pageable);
|
||||||
|
}
|
||||||
|
return datasetRepository.searchByOptionalCriteria(Optional.ofNullable(search), pageable);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,10 +5,13 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
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);
|
||||||
@ -25,7 +28,8 @@ public interface dataRepository extends JpaRepository<Dataset, UUID>{
|
|||||||
List<Dataset> findByDateAfter(Date date);
|
List<Dataset> findByDateAfter(Date date);
|
||||||
List<Dataset> findByDateBefore(Date date);
|
List<Dataset> findByDateBefore(Date date);
|
||||||
List<Dataset> findByDateBetween(Date date1, Date date2);
|
List<Dataset> findByDateBetween(Date date1, Date date2);
|
||||||
List<Dataset> findAll();
|
@SuppressWarnings("null")
|
||||||
|
Page<Dataset> findAll(Pageable pageable);
|
||||||
|
|
||||||
@Query("SELECT d FROM Dataset d WHERE " +
|
@Query("SELECT d FROM Dataset d WHERE " +
|
||||||
"(COALESCE(:title, '') = '' OR d.title LIKE :title) AND " +
|
"(COALESCE(:title, '') = '' OR d.title LIKE :title) AND " +
|
||||||
@ -35,12 +39,21 @@ public interface dataRepository extends JpaRepository<Dataset, UUID>{
|
|||||||
"(:type IS NULL OR d.type = :type) AND"+
|
"(:type IS NULL OR d.type = :type) AND"+
|
||||||
"(:categories IS NULL OR d.categories = :categories) AND" +
|
"(:categories IS NULL OR d.categories = :categories) AND" +
|
||||||
"(:raiting IS NULL OR d.raiting > :raiting)")
|
"(:raiting IS NULL OR d.raiting > :raiting)")
|
||||||
List<Dataset> findByOptionalCriteria(@Param("title") Optional<String> title,
|
Page<Dataset>findByOptionalCriteria(@Param("title") Optional<String> title,
|
||||||
@Param("description") Optional<String> description,
|
@Param("description") Optional<String> description,
|
||||||
@Param("author") Optional<String> author,
|
@Param("author") Optional<String> author,
|
||||||
@Param("abst") Optional<String> abst,
|
@Param("abst") Optional<String> abst,
|
||||||
@Param("type") Optional<Type> type,
|
@Param("type") Optional<Type> type,
|
||||||
@Param("categories") Optional<String[]> categories,
|
@Param("categories") Optional<String[]> categories,
|
||||||
@Param("raiting") Optional<Float> raiting);
|
@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