feat: implemented date filtration and a utils service to prevent code ducplication
This commit is contained in:
@ -1,13 +1,9 @@
|
||||
package enseirb.myinpulse.service;
|
||||
|
||||
import enseirb.myinpulse.model.Entrepreneur;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.model.SectionCell;
|
||||
import enseirb.myinpulse.model.User;
|
||||
import enseirb.myinpulse.service.database.EntrepreneurService;
|
||||
import enseirb.myinpulse.service.database.ProjectService;
|
||||
import enseirb.myinpulse.service.database.SectionCellService;
|
||||
import enseirb.myinpulse.service.database.UserService;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -23,28 +19,19 @@ public class EntrepreneurApiService {
|
||||
|
||||
private final SectionCellService sectionCellService;
|
||||
private final ProjectService projectService;
|
||||
private final UserService userService;
|
||||
private final EntrepreneurService entrepreneurService;
|
||||
private final UtilsService utilsService;
|
||||
|
||||
@Autowired
|
||||
EntrepreneurApiService(
|
||||
SectionCellService sectionCellService,
|
||||
ProjectService projectService,
|
||||
UserService userService,
|
||||
EntrepreneurService entrepreneurService) {
|
||||
UtilsService utilsService) {
|
||||
this.sectionCellService = sectionCellService;
|
||||
this.projectService = projectService;
|
||||
this.userService = userService;
|
||||
this.entrepreneurService = entrepreneurService;
|
||||
this.utilsService = utilsService;
|
||||
}
|
||||
|
||||
// Create utils file ?
|
||||
Boolean isAllowedToCheckProject(String mail, long projectId) {
|
||||
User user = this.userService.getUserByEmail(mail);
|
||||
Entrepreneur entrepreneur = this.entrepreneurService.getEntrepreneurById(user.getIdUser());
|
||||
Project project = this.projectService.getProjectById(projectId);
|
||||
return entrepreneur.getProjectParticipation() == project;
|
||||
}
|
||||
|
||||
|
||||
public void editSectionCell(Long sectionCellId, SectionCell sectionCell, String mail) {
|
||||
SectionCell editSectionCell = sectionCellService.getSectionCellById(sectionCellId);
|
||||
@ -53,7 +40,7 @@ public class EntrepreneurApiService {
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
|
||||
}
|
||||
if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) {
|
||||
if (!utilsService.isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) {
|
||||
logger.warn(
|
||||
"User {} tried to edit section cells {} of the project {} but is not allowed to.",
|
||||
mail,
|
||||
@ -81,7 +68,7 @@ public class EntrepreneurApiService {
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cette cellule de section n'existe pas");
|
||||
}
|
||||
if (!isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) {
|
||||
if (!utilsService.isAllowedToCheckProject(mail, this.sectionCellService.getProjectId(sectionCellId))) {
|
||||
logger.warn(
|
||||
"User {} tried to remove section cells {} of the project {} but is not allowed to.",
|
||||
mail,
|
||||
@ -104,7 +91,7 @@ public class EntrepreneurApiService {
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.BAD_REQUEST, "La cellule de section fournie est vide");
|
||||
}
|
||||
if (!isAllowedToCheckProject(
|
||||
if (!utilsService.isAllowedToCheckProject(
|
||||
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
|
||||
logger.warn(
|
||||
"User {} tried to add a section cell to the project {} but is not allowed to.",
|
||||
|
Reference in New Issue
Block a user