backend-api #6
@@ -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,
 | 
			
		||||
		Reference in New Issue
	
	Block a user