feat: switched from String to ProjectDecisionValues
This commit is contained in:
parent
ef964c4d35
commit
e011a5534e
@ -26,8 +26,7 @@ public class Project {
|
||||
private byte[] logo;
|
||||
private LocalDate creationDate;
|
||||
|
||||
@Column(length = 255)
|
||||
private String projectStatus;
|
||||
@Column private ProjectDecisionValue projectStatus;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "idAdministrator")
|
||||
@ -42,11 +41,12 @@ public class Project {
|
||||
String projectName,
|
||||
byte[] logo,
|
||||
LocalDate creationDate,
|
||||
String projectStatus,
|
||||
ProjectDecisionValue projectStatus,
|
||||
Administrator projectAdministrator) {
|
||||
this.projectName = projectName;
|
||||
this.logo = logo;
|
||||
this.creationDate = creationDate;
|
||||
// this.projectStatus = (long) projectStatus.ordinal();
|
||||
this.projectStatus = projectStatus;
|
||||
this.projectAdministrator = projectAdministrator;
|
||||
}
|
||||
@ -83,11 +83,11 @@ public class Project {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public String getProjectStatus() {
|
||||
public ProjectDecisionValue getProjectStatus() {
|
||||
return projectStatus;
|
||||
}
|
||||
|
||||
public void setProjectStatus(String projectStatus) {
|
||||
public void setProjectStatus(ProjectDecisionValue projectStatus) {
|
||||
this.projectStatus = projectStatus;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
package enseirb.myinpulse.model;
|
||||
|
||||
public enum ProjectDecisionValue {
|
||||
PENDING,
|
||||
ACTIVE,
|
||||
ENDED,
|
||||
ABORTED
|
||||
}
|
@ -10,5 +10,5 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
public interface ProjectRepository extends JpaRepository<Project, Long> {
|
||||
Iterable<Project> findByProjectAdministrator(Administrator administrator);
|
||||
|
||||
Iterable<Project> findByProjectStatus(String status);
|
||||
Iterable<Project> findByProjectStatus(Long status);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package enseirb.myinpulse.service;
|
||||
|
||||
import static enseirb.myinpulse.model.ProjectDecisionValue.ACTIVE;
|
||||
|
||||
import enseirb.myinpulse.model.*;
|
||||
import enseirb.myinpulse.service.database.AdministratorService;
|
||||
import enseirb.myinpulse.service.database.ProjectService;
|
||||
@ -27,7 +29,7 @@ public class AdminApiService {
|
||||
this.administratorService = administratorService;
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
// TODO: check if test are sufficient
|
||||
public Iterable<Project> getProjectsOfAdmin(String email) {
|
||||
return projectService.getProjectsByAdminId(
|
||||
administratorService.getAdministratorById(
|
||||
@ -46,14 +48,16 @@ public class AdminApiService {
|
||||
|
||||
// TODO: test
|
||||
public void validateProject(ProjectDecision decision) {
|
||||
if (decision.isAccepted == 1) {
|
||||
projectService.updateProject(
|
||||
decision.projectId,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"ACTIVE",
|
||||
ACTIVE,
|
||||
this.administratorService.getAdministratorById(decision.projectId));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: solve todo + test
|
||||
public void addNewProject(Project project) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package enseirb.myinpulse.service;
|
||||
|
||||
import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING;
|
||||
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.model.SectionCell;
|
||||
import enseirb.myinpulse.service.database.ProjectService;
|
||||
@ -114,7 +116,7 @@ public class EntrepreneurApiService {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Le projet fourni est vide");
|
||||
}
|
||||
logger.info("User {} created a new project with id {}", mail, project.getIdProject());
|
||||
project.setProjectStatus("PENDING");
|
||||
project.setProjectStatus(PENDING);
|
||||
projectService.addNewProject(project);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package enseirb.myinpulse.service.database;
|
||||
|
||||
import static enseirb.myinpulse.model.ProjectDecisionValue.PENDING;
|
||||
|
||||
import enseirb.myinpulse.model.Administrator;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.model.ProjectDecisionValue;
|
||||
import enseirb.myinpulse.repository.ProjectRepository;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -54,7 +57,7 @@ public class ProjectService {
|
||||
String projectName,
|
||||
byte[] logo,
|
||||
LocalDate creationDate,
|
||||
String projectStatus,
|
||||
ProjectDecisionValue projectStatus,
|
||||
Administrator administrator) {
|
||||
Optional<Project> project = this.projectRepository.findById(id);
|
||||
|
||||
@ -76,11 +79,14 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
if (projectStatus != null) {
|
||||
// TODO: check if this is really useful
|
||||
/*
|
||||
if (!validateStatus(projectStatus)) {
|
||||
logger.error("updateProjectStatus: Invalid status {}", projectStatus);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_ACCEPTABLE, "Ce status n'est pas accepté");
|
||||
}
|
||||
*/
|
||||
project.get().setProjectStatus(projectStatus);
|
||||
}
|
||||
|
||||
@ -96,7 +102,7 @@ public class ProjectService {
|
||||
}
|
||||
|
||||
public Iterable<Project> getPendingProjects() {
|
||||
return this.projectRepository.findByProjectStatus("PENDING");
|
||||
return this.projectRepository.findByProjectStatus((long) PENDING.ordinal());
|
||||
}
|
||||
|
||||
public void deleteProjectById(Long id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user