backend-api #6
@@ -4,4 +4,22 @@ public class ProjectDecision {
 | 
			
		||||
    public long projectId;
 | 
			
		||||
    public long adminId;
 | 
			
		||||
    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,
 | 
			
		||||
    ACTIVE,
 | 
			
		||||
    ENDED,
 | 
			
		||||
    ABORTED
 | 
			
		||||
    ABORTED,
 | 
			
		||||
    REJECTED,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,9 +7,13 @@ import enseirb.myinpulse.model.ProjectDecisionValue;
 | 
			
		||||
import org.springframework.data.jpa.repository.JpaRepository;
 | 
			
		||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
 | 
			
		||||
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
 | 
			
		||||
@RepositoryRestResource
 | 
			
		||||
public interface ProjectRepository extends JpaRepository<Project, Long> {
 | 
			
		||||
    Iterable<Project> findByProjectAdministrator(Administrator administrator);
 | 
			
		||||
 | 
			
		||||
    Iterable<Project> findByProjectStatus(ProjectDecisionValue status);
 | 
			
		||||
 | 
			
		||||
    Optional<Project> findByProjectName(String projectName);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package enseirb.myinpulse.service;
 | 
			
		||||
 | 
			
		||||
import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
 | 
			
		||||
import static enseirb.myinpulse.model.ProjectDecisionValue.REJECTED;
 | 
			
		||||
 | 
			
		||||
import enseirb.myinpulse.model.*;
 | 
			
		||||
import enseirb.myinpulse.service.database.AdministratorService;
 | 
			
		||||
@@ -29,7 +30,7 @@ public class AdminApiService {
 | 
			
		||||
        this.administratorService = administratorService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: check if test are sufficient
 | 
			
		||||
    // TODO: check if tests are sufficients - peer verification required
 | 
			
		||||
    public Iterable<Project> getProjectsOfAdmin(String email) {
 | 
			
		||||
        return projectService.getProjectsByAdminId(
 | 
			
		||||
                administratorService.getAdministratorById(
 | 
			
		||||
@@ -41,29 +42,35 @@ public class AdminApiService {
 | 
			
		||||
        throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: test
 | 
			
		||||
    // TODO: check if tests are sufficient - peer verification required
 | 
			
		||||
    public Iterable<Project> getPendingProjects() {
 | 
			
		||||
        return this.projectService.getPendingProjects();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: test
 | 
			
		||||
    // TODO: check if tests are sufficient - peer verification required
 | 
			
		||||
    public void validateProject(ProjectDecision decision) {
 | 
			
		||||
        if (decision.isAccepted == 1) {
 | 
			
		||||
            projectService.updateProject(
 | 
			
		||||
                    decision.projectId,
 | 
			
		||||
                    null,
 | 
			
		||||
                    null,
 | 
			
		||||
                    null,
 | 
			
		||||
                    ACTIVE,
 | 
			
		||||
                    this.administratorService.getAdministratorById(decision.projectId));
 | 
			
		||||
        }
 | 
			
		||||
        projectService.updateProject(
 | 
			
		||||
                decision.projectId,
 | 
			
		||||
                null,
 | 
			
		||||
                null,
 | 
			
		||||
                null,
 | 
			
		||||
                (decision.isAccepted == 1) ? ACTIVE : REJECTED,
 | 
			
		||||
                this.administratorService.getAdministratorById(decision.adminId));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: solve todo + test
 | 
			
		||||
    // TODO: check if tests are sufficient - peer verification required
 | 
			
		||||
    public void addNewProject(Project project) {
 | 
			
		||||
        projectService.addNewProject(
 | 
			
		||||
                project); // TODO: how can the front know the ID ? => it does not, thus needing to
 | 
			
		||||
        // have null in the project id field
 | 
			
		||||
        project.setIdProject(null);
 | 
			
		||||
        // We remove it from the request to be sure that it will be auto generated
 | 
			
		||||
        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
 | 
			
		||||
 
 | 
			
		||||
@@ -108,4 +108,17 @@ public class ProjectService {
 | 
			
		||||
    public void deleteProjectById(Long 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