Refactor DatasetController and DatasetService, improve search query and add optional criteria
This commit is contained in:
parent
d616d193f1
commit
df6143da19
@ -11,7 +11,6 @@ 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.UUID;
|
||||
|
||||
@ -51,36 +50,6 @@ public class DatasetController {
|
||||
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")
|
||||
public Dataset upvote(@PathVariable("id") UUID id) {
|
||||
datasetService.upvoteDataset(id);
|
||||
@ -93,26 +62,30 @@ public class DatasetController {
|
||||
return null; // new ResponseEntity<>(null, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/find")
|
||||
@GetMapping
|
||||
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 = "page", required = false) int page,
|
||||
@RequestParam(value = "size", required = false) int size) {
|
||||
Pageable pageable = PageRequest.of(page, size);
|
||||
return datasetService.getDatasetsByOptionalCriteria(title, description, author, abst, type, raiting, pageable);
|
||||
@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
|
||||
@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));
|
||||
@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);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,11 @@ package de.uni_passau.fim.PADAS.group3.DataDash.model;
|
||||
|
||||
import java.net.URL;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.cglib.core.Local;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
@ -28,7 +32,7 @@ public class Dataset {
|
||||
|
||||
private String author;
|
||||
|
||||
private Date date;
|
||||
private LocalDate date;
|
||||
|
||||
private float raiting;
|
||||
|
||||
@ -40,7 +44,7 @@ public class Dataset {
|
||||
|
||||
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.votes = 0;
|
||||
@ -49,7 +53,7 @@ public class Dataset {
|
||||
setAbst(abst);
|
||||
setDescription(description);
|
||||
setAuthor(author);
|
||||
setDate(date);
|
||||
setDate(LocalDate.now());
|
||||
setCategories(categories);
|
||||
setType(type);
|
||||
setUrl(url);
|
||||
@ -71,7 +75,7 @@ public class Dataset {
|
||||
return categories;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
@ -119,8 +123,8 @@ public class Dataset {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
public void setDate(LocalDate localDate) {
|
||||
this.date = localDate;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
|
@ -28,6 +28,7 @@ public interface dataRepository extends JpaRepository<Dataset, UUID>{
|
||||
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 " +
|
||||
|
Loading…
Reference in New Issue
Block a user