backend-api #6
@@ -4,4 +4,22 @@ public class ProjectDecision {
 | 
				
			|||||||
    public long projectId;
 | 
					    public long projectId;
 | 
				
			||||||
    public long adminId;
 | 
					    public long adminId;
 | 
				
			||||||
    public long isAccepted;
 | 
					    public long isAccepted;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public ProjectDecision(long projectId, long adminId, long isAccepted) {
 | 
				
			||||||
 | 
					        this.projectId = projectId;
 | 
				
			||||||
 | 
					        this.adminId = adminId;
 | 
				
			||||||
 | 
					        this.isAccepted = isAccepted;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String toString() {
 | 
				
			||||||
 | 
					        return "ProjectDecision{"
 | 
				
			||||||
 | 
					                + "projectId="
 | 
				
			||||||
 | 
					                + projectId
 | 
				
			||||||
 | 
					                + ", adminId="
 | 
				
			||||||
 | 
					                + adminId
 | 
				
			||||||
 | 
					                + ", isAccepted="
 | 
				
			||||||
 | 
					                + isAccepted
 | 
				
			||||||
 | 
					                + '}';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,5 +4,6 @@ public enum ProjectDecisionValue {
 | 
				
			|||||||
    PENDING,
 | 
					    PENDING,
 | 
				
			||||||
    ACTIVE,
 | 
					    ACTIVE,
 | 
				
			||||||
    ENDED,
 | 
					    ENDED,
 | 
				
			||||||
    ABORTED
 | 
					    ABORTED,
 | 
				
			||||||
 | 
					    REJECTED,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,9 +7,13 @@ import enseirb.myinpulse.model.ProjectDecisionValue;
 | 
				
			|||||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
					import org.springframework.data.jpa.repository.JpaRepository;
 | 
				
			||||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
 | 
					import org.springframework.data.rest.core.annotation.RepositoryRestResource;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Optional;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@RepositoryRestResource
 | 
					@RepositoryRestResource
 | 
				
			||||||
public interface ProjectRepository extends JpaRepository<Project, Long> {
 | 
					public interface ProjectRepository extends JpaRepository<Project, Long> {
 | 
				
			||||||
    Iterable<Project> findByProjectAdministrator(Administrator administrator);
 | 
					    Iterable<Project> findByProjectAdministrator(Administrator administrator);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Iterable<Project> findByProjectStatus(ProjectDecisionValue status);
 | 
					    Iterable<Project> findByProjectStatus(ProjectDecisionValue status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Optional<Project> findByProjectName(String projectName);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
package enseirb.myinpulse.service;
 | 
					package enseirb.myinpulse.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
 | 
					import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
 | 
				
			||||||
 | 
					import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import enseirb.myinpulse.model.*;
 | 
					import enseirb.myinpulse.model.*;
 | 
				
			||||||
import enseirb.myinpulse.service.database.AdministratorService;
 | 
					import enseirb.myinpulse.service.database.AdministratorService;
 | 
				
			||||||
@@ -29,7 +30,7 @@ public class AdminApiService {
 | 
				
			|||||||
        this.administratorService = administratorService;
 | 
					        this.administratorService = administratorService;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: check if test are sufficient
 | 
					    // TODO: check if tests are sufficients - peer verification required
 | 
				
			||||||
    public Iterable<Project> getProjectsOfAdmin(String email) {
 | 
					    public Iterable<Project> getProjectsOfAdmin(String email) {
 | 
				
			||||||
        return projectService.getProjectsByAdminId(
 | 
					        return projectService.getProjectsByAdminId(
 | 
				
			||||||
                administratorService.getAdministratorById(
 | 
					                administratorService.getAdministratorById(
 | 
				
			||||||
@@ -41,29 +42,35 @@ public class AdminApiService {
 | 
				
			|||||||
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
 | 
					        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: test
 | 
					    // TODO: check if tests are sufficient - peer verification required
 | 
				
			||||||
    public Iterable<Project> getPendingProjects() {
 | 
					    public Iterable<Project> getPendingProjects() {
 | 
				
			||||||
        return this.projectService.getPendingProjects();
 | 
					        return this.projectService.getPendingProjects();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: test
 | 
					    // TODO: check if tests are sufficient - peer verification required
 | 
				
			||||||
    public void validateProject(ProjectDecision decision) {
 | 
					    public void validateProject(ProjectDecision decision) {
 | 
				
			||||||
        if (decision.isAccepted == 1) {
 | 
					        projectService.updateProject(
 | 
				
			||||||
            projectService.updateProject(
 | 
					                decision.projectId,
 | 
				
			||||||
                    decision.projectId,
 | 
					                null,
 | 
				
			||||||
                    null,
 | 
					                null,
 | 
				
			||||||
                    null,
 | 
					                null,
 | 
				
			||||||
                    null,
 | 
					                (decision.isAccepted == 1) ? ACTIVE : REJECTED,
 | 
				
			||||||
                    ACTIVE,
 | 
					                this.administratorService.getAdministratorById(decision.adminId));
 | 
				
			||||||
                    this.administratorService.getAdministratorById(decision.projectId));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO: solve todo + test
 | 
					    // TODO: check if tests are sufficient - peer verification required
 | 
				
			||||||
    public void addNewProject(Project project) {
 | 
					    public void addNewProject(Project project) {
 | 
				
			||||||
        projectService.addNewProject(
 | 
					        project.setIdProject(null);
 | 
				
			||||||
                project); // TODO: how can the front know the ID ? => it does not, thus needing to
 | 
					        // We remove it from the request to be sure that it will be auto generated
 | 
				
			||||||
        // have null in the project id field
 | 
					        try {
 | 
				
			||||||
 | 
					            this.projectService.getProjectByName(project.getProjectName(), true);
 | 
				
			||||||
 | 
					            throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
 | 
				
			||||||
 | 
					        } catch (ResponseStatusException e) {
 | 
				
			||||||
 | 
					            if (e.getStatusCode() == HttpStatus.CONFLICT) {
 | 
				
			||||||
 | 
					                throw new ResponseStatusException(HttpStatus.CONFLICT, "Project already exists");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            projectService.addNewProject(project);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO
 | 
					    // TODO
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,4 +108,17 @@ public class ProjectService {
 | 
				
			|||||||
    public void deleteProjectById(Long id) {
 | 
					    public void deleteProjectById(Long id) {
 | 
				
			||||||
        this.projectRepository.deleteById(id);
 | 
					        this.projectRepository.deleteById(id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Project getProjectByName(String name, boolean noerror) {
 | 
				
			||||||
 | 
					        Optional<Project> project = this.projectRepository.findByProjectName(name);
 | 
				
			||||||
 | 
					        if (project.isEmpty()) {
 | 
				
			||||||
 | 
					            if (noerror) logger.error("No project found with name {}", name);
 | 
				
			||||||
 | 
					            throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Ce projet n'existe pas");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return project.get();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public Project getProjectByName(String name) {
 | 
				
			||||||
 | 
					        return getProjectByName(name, false);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user