feature: add ability to vote on datasets
This commit is contained in:
parent
8820f1d5ef
commit
5df6a65f1b
@ -12,6 +12,8 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/datasets")
|
||||
@ -61,6 +63,16 @@ public class DatasetController {
|
||||
return null; // new ResponseEntity<>(null, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/id/{id}/vote")
|
||||
public String postMethodName(@PathVariable("id") UUID id,
|
||||
@RequestParam("stars") int stars) {
|
||||
if (stars > 0 && stars < 6) {
|
||||
datasetService.voteDataset(id, stars);
|
||||
return null;
|
||||
}
|
||||
return "Invalid vote";
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Page<Dataset> getDatasetsByDateAfter(@RequestParam(value = "author", required = false) String author,
|
||||
@RequestParam(value = "title", required = false) String title,
|
||||
|
@ -33,6 +33,12 @@ public class DatasetService {
|
||||
datasetRepository.getDatasetById(id).setTitle(title);
|
||||
}
|
||||
|
||||
public void voteDataset(UUID id, int vote) {
|
||||
Dataset dataset = datasetRepository.getDatasetById(id);
|
||||
dataset.vote(vote);
|
||||
datasetRepository.save(dataset);
|
||||
}
|
||||
|
||||
public void deleteDataset(UUID id) {
|
||||
Dataset dataset = datasetRepository.getDatasetById(id);
|
||||
datasetRepository.delete(dataset);
|
||||
|
Loading…
Reference in New Issue
Block a user