Merge branch '11-add-api-for-getting-home-page-data' into '22-integrate-api-and-frontend'
feature: add ability to vote on datasets See merge request padas/24ss-5430-web-and-data-eng/gruppe-3/datadash!20
This commit is contained in:
		@@ -12,6 +12,8 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport;
 | 
				
			|||||||
import org.springframework.data.domain.Sort;
 | 
					import org.springframework.data.domain.Sort;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.PostMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.RequestBody;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@RestController
 | 
					@RestController
 | 
				
			||||||
@RequestMapping("/api/v1/datasets")
 | 
					@RequestMapping("/api/v1/datasets")
 | 
				
			||||||
@@ -61,6 +63,16 @@ public class DatasetController {
 | 
				
			|||||||
        return null; // new ResponseEntity<>(null, HttpStatus.OK);
 | 
					        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
 | 
					    @GetMapping
 | 
				
			||||||
    public Page<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,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,12 @@ public class DatasetService {
 | 
				
			|||||||
        datasetRepository.getDatasetById(id).setTitle(title);
 | 
					        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) {
 | 
					    public void deleteDataset(UUID id) {
 | 
				
			||||||
        Dataset dataset = datasetRepository.getDatasetById(id);
 | 
					        Dataset dataset = datasetRepository.getDatasetById(id);
 | 
				
			||||||
        datasetRepository.delete(dataset);
 | 
					        datasetRepository.delete(dataset);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user