86 lines
3.2 KiB
Java
86 lines
3.2 KiB
Java
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;
|
|
import enseirb.myinpulse.service.database.ProjectService;
|
|
import enseirb.myinpulse.service.database.UserService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.server.ResponseStatusException;
|
|
|
|
@Service
|
|
public class AdminApiService {
|
|
|
|
private final ProjectService projectService;
|
|
private final UserService userService;
|
|
private final AdministratorService administratorService;
|
|
|
|
@Autowired
|
|
AdminApiService(
|
|
ProjectService projectService,
|
|
UserService userService,
|
|
AdministratorService administratorService) {
|
|
this.projectService = projectService;
|
|
this.userService = userService;
|
|
this.administratorService = administratorService;
|
|
}
|
|
|
|
// TODO: check if tests are sufficients - peer verification required
|
|
public Iterable<Project> getProjectsOfAdmin(String email) {
|
|
return projectService.getProjectsByAdminId(
|
|
administratorService.getAdministratorById(
|
|
this.userService.getUserByEmail(email).getIdUser()));
|
|
}
|
|
|
|
// TODO
|
|
public Iterable<Appointment> getUpcomingAppointments(String email) {
|
|
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
|
}
|
|
|
|
// TODO: check if tests are sufficient - peer verification required
|
|
public Iterable<Project> getPendingProjects() {
|
|
return this.projectService.getPendingProjects();
|
|
}
|
|
|
|
// TODO: check if tests are sufficient - peer verification required
|
|
public void validateProject(ProjectDecision decision) {
|
|
projectService.updateProject(
|
|
decision.projectId,
|
|
null,
|
|
null,
|
|
null,
|
|
(decision.isAccepted == 1) ? ACTIVE : REJECTED,
|
|
this.administratorService.getAdministratorById(decision.adminId));
|
|
}
|
|
|
|
// TODO: check if tests are sufficient - peer verification required
|
|
public void addNewProject(Project project) {
|
|
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
|
|
public void createAppointmentReport(String appointmentId, Report report, String email) {
|
|
throw new ResponseStatusException(HttpStatus.NOT_IMPLEMENTED, "Not implemented yet");
|
|
}
|
|
|
|
// TODO: test
|
|
public void deleteProject(long projectId) {
|
|
this.projectService.deleteProjectById(projectId);
|
|
}
|
|
}
|