feat: added a new database service
All checks were successful
Format / formatting (push) Successful in 7s
CI / build (push) Successful in 13s

This commit is contained in:
Pierre Tellier 2025-02-26 10:32:44 +01:00
parent 27e70ee109
commit e66fa33577

View File

@ -1,29 +1,32 @@
package enseirb.myinpulse.service.database.old_controllers_to_convert_to_services;
package enseirb.myinpulse.service.database;
import enseirb.myinpulse.model.Project;
import enseirb.myinpulse.repository.ProjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDate;
import java.util.Optional;
@RestController
public class ProjectController {
@Service
public class ProjectService {
@Autowired ProjectRepository projectRepository;
private final ProjectRepository projectRepository;
@GetMapping("/Project")
@ResponseBody
public Iterable<Project> allProjects() {
@Autowired
ProjectService(ProjectRepository projectRepository) {
this.projectRepository = projectRepository;
}
public Iterable<Project> getAllProjects() {
return this.projectRepository.findAll();
}
@GetMapping("/Project/{id}")
public Project getProjectById(@PathVariable Long id) {
// TODO: change error
public Project getProjectById(Long id) {
Optional<Project> project = this.projectRepository.findById(id);
if (project.isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
@ -31,14 +34,13 @@ public class ProjectController {
return project.get();
}
@PostMapping("/Project")
public Project addProject(@RequestBody Project project) {
// TODO: validation
public Project addNewProject(Project project) {
return this.projectRepository.save(project);
}
@PostMapping("/Project/{id}")
public Project updateProject(
@PathVariable Long id,
Long id,
String projectName,
byte[] logo,
LocalDate creationDate,