feat: created a better account creation flow
All checks were successful
Format / formatting (push) Successful in 6s
Build / build (push) Successful in 5m20s
CI / build (push) Successful in 11s

This commit is contained in:
Pierre Tellier
2025-04-09 17:39:43 +02:00
parent 385c5cd8d0
commit 66be0baca6
14 changed files with 377 additions and 88 deletions

View File

@ -24,6 +24,7 @@ public class AdminApiService {
private final ProjectService projectService;
private final UserService userService;
private final AdministratorService administratorService;
private final EntrepreneurService entrepreneurService;
private final UtilsService utilsService;
private final AppointmentService appointmentService;
private final ReportService reportService;
@ -35,6 +36,7 @@ public class AdminApiService {
UserService userService,
AdministratorService administratorService,
UtilsService utilsService,
EntrepreneurService entrepreneurService,
AppointmentService appointmentService,
ReportService reportService,
SectionCellService sectionCellService) {
@ -45,6 +47,7 @@ public class AdminApiService {
this.appointmentService = appointmentService;
this.reportService = reportService;
this.sectionCellService = sectionCellService;
this.entrepreneurService = entrepreneurService;
}
// TODO: check if tests are sufficient - peer verification required
@ -75,6 +78,12 @@ public class AdminApiService {
}
if (user instanceof Entrepreneur) {
Project project = ((Entrepreneur) user).getProjectParticipation();
if (project == null) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND,
"The user has no project, thus no appointments. No users should have no project");
}
project.getListSectionCell()
.forEach(
sectionCell -> {
@ -104,7 +113,7 @@ public class AdminApiService {
}
// TODO: check if tests are sufficient - peer verification required
public void addNewProject(Project project) {
public Project addNewProject(Project project) {
project.setIdProject(null);
// We remove the ID from the request to be sure that it will be auto generated
try {
@ -136,6 +145,7 @@ public class AdminApiService {
sectionCell -> {
sectionCell.setProjectSectionCell(newProject);
});
return newProject;
}
public void createAppointmentReport(long appointmentId, Report report, String mail) {
@ -164,4 +174,36 @@ public class AdminApiService {
public void deleteProject(long projectId) {
this.projectService.deleteProjectById(projectId);
}
public void setAdmin(long userId, String token) {
Entrepreneur e = this.entrepreneurService.getEntrepreneurById(userId);
Administrator a =
new Administrator(
e.getUserSurname(),
e.getUserName(),
e.getPrimaryMail(),
e.getSecondaryMail(),
e.getPhoneNumber());
this.entrepreneurService.deleteEntrepreneur(e);
this.administratorService.addAdministrator(a);
try {
KeycloakApi.setRoleToUser(a.getUserName(), "MyINPulse-admin", token);
} catch (Exception err) {
logger.error(err);
}
}
public void validateEntrepreneurAccount(long userId, String token) {
Entrepreneur e = this.entrepreneurService.getEntrepreneurById(userId);
try {
KeycloakApi.setRoleToUser(e.getUserName(), "MyINPulse-entrepreneur", token);
} catch (Exception err) {
logger.error(err);
}
this.entrepreneurService.validateEntrepreneurById(userId);
}
public Iterable<User> getPendingUsers() {
return this.userService.getPendingAccounts();
}
}