feature: add minimal API

This commit is contained in:
Erik Foris 2024-06-17 18:13:25 +02:00
parent b901b018d6
commit 10e339f32b
3 changed files with 152 additions and 0 deletions

View File

@ -0,0 +1,84 @@
package de.uni_passau.fim.PADAS.group3.DataDash.controler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
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.DatasetService;
import java.util.List;
import java.util.UUID;
import de.uni_passau.fim.PADAS.group3.DataDash.model.Type;
import javax.swing.text.html.HTML;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/api/datasets")
public class DatasetController {
@Autowired
private DatasetService datasetService;
@GetMapping
public List<Dataset> getAllDatasets() {
return datasetService.getAllDatasets();
}
@GetMapping("/id/{id}")
public Dataset getDatasetById(@PathVariable("id") UUID id) {
return datasetService.getDatasetById(id);
}
@PostMapping
public Dataset createDataset(@RequestBody Dataset dataset) {
datasetService.addDataset(dataset);
//TODO: figure out what the fuck i need to do here
return null;
}
//@PutMapping("/{id}")
//public Dataset updateDataset(@PathVariable("id") Long id, @RequestBody Dataset dataset) {
// return datasetService.updateDataset(id, dataset);
//}
//
@DeleteMapping("/id/{id}")
public void deleteDataset(@PathVariable("id") UUID 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);
}
}

View File

@ -0,0 +1,65 @@
package de.uni_passau.fim.PADAS.group3.DataDash.model;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DatasetService {
private dataRepository datasetRepository;
@Autowired
public DatasetService(dataRepository datasetRepository) {
this.datasetRepository = datasetRepository;
}
public List<Dataset> getAllDatasets() {
return datasetRepository.findAll();
}
public Dataset getDatasetById(UUID id) {
return datasetRepository.getDatasetById(id);
}
public void addDataset(Dataset dataset) {
datasetRepository.save(dataset);
}
public void updateDatasetTitle(UUID id, String title) {
datasetRepository.getDatasetById(id).setTitle(title);
}
public void deleteDataset(UUID id) {
Dataset dataset = datasetRepository.getDatasetById(id);
datasetRepository.delete(dataset);
}
public List<Dataset> getDatasetsByTitle(String title) {
return datasetRepository.findByTitle(title);
}
public List<Dataset> getDatasetsByTitleLike(String title) {
return datasetRepository.findByTitleLike(title);
}
public List<Dataset> findByDescriptionLike(String description) {
return datasetRepository.findByDescriptionLike(description);
}
public List<Dataset> getDatasetsByAuthorLike(String author) {
return datasetRepository.findByAuthorLike(author);
}
public List<Dataset> getDatasetsByType(Type type) {
return datasetRepository.findByType(type);
}
public List<Dataset> getDatasetsByAbstLike(String abst) {
return datasetRepository.findByAbstLike(abst);
}
public List<Dataset> getDatasetsByRaitingGreaterThan(float raiting) {
return datasetRepository.findByRaitingGreaterThan(raiting);
}
}

View File

@ -3,10 +3,12 @@ package de.uni_passau.fim.PADAS.group3.DataDash.model;
import java.util.List;
import java.util.UUID;
import java.sql.Date;
import org.springframework.data.jpa.repository.JpaRepository;
public interface dataRepository extends JpaRepository<Dataset, UUID>{
Dataset getDatasetById(UUID id);
List<Dataset> findByTitle(String title);
List<Dataset> findByTitleLike(String title);
List<Dataset> findByAuthorLike(String author);
@ -20,5 +22,6 @@ public interface dataRepository extends JpaRepository<Dataset, UUID>{
List<Dataset> findByDateAfter(Date date);
List<Dataset> findByDateBefore(Date date);
List<Dataset> findByDateBetween(Date date1, Date date2);
List<Dataset> findAll();
}