diff --git a/backend/pom.xml b/backend/pom.xml index 2c4acce..4d24672 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.6 + 3.3.0 com.epsyl @@ -100,4 +100,4 @@ - \ No newline at end of file + diff --git a/backend/src/main/java/com/epsyl/eps/EpsylProspectsServiceApplication.java b/backend/src/main/java/com/epsyl/eps/EpsylProspectsServiceApplication.java index 47d5501..8a18045 100644 --- a/backend/src/main/java/com/epsyl/eps/EpsylProspectsServiceApplication.java +++ b/backend/src/main/java/com/epsyl/eps/EpsylProspectsServiceApplication.java @@ -10,4 +10,17 @@ public static void main(String[] args) { SpringApplication.run(EpsylProspectsServiceApplication.class, args); } + // @Bean + // CommandLineRunner start(UserService userService, UserRepository userRepository) { + // return args -> { + // Role admin = new Role(ERole.ADMIN); + // Role rh = new Role(ERole.RH); + // Role bum = new Role(ERole.BUM); + + // userService.addNewRole(admin); + // userService.addNewRole(rh); + // userService.addNewRole(bum); + // }; + // } + } diff --git a/backend/src/main/java/com/epsyl/eps/configuration_global/ObjectIdDeserrializer.java b/backend/src/main/java/com/epsyl/eps/configuration_global/ObjectIdDeserrializer.java new file mode 100644 index 0000000..13fd721 --- /dev/null +++ b/backend/src/main/java/com/epsyl/eps/configuration_global/ObjectIdDeserrializer.java @@ -0,0 +1,17 @@ +package com.epsyl.eps.configuration_global; + +import java.io.IOException; + +import org.bson.types.ObjectId; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +public class ObjectIdDeserrializer extends JsonDeserializer { + + @Override + public ObjectId deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { + return new ObjectId(jsonParser.getText()); + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/configuration_global/WebConfig.java b/backend/src/main/java/com/epsyl/eps/configuration_global/WebConfig.java new file mode 100644 index 0000000..debfb36 --- /dev/null +++ b/backend/src/main/java/com/epsyl/eps/configuration_global/WebConfig.java @@ -0,0 +1,25 @@ +package com.epsyl.eps.configuration_global; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.lang.NonNull; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig { + + @Bean + public WebMvcConfigurer corsConfigurer() { + return new WebMvcConfigurer() { + @Override + public void addCorsMappings(@NonNull CorsRegistry registry) { + registry.addMapping("/api/v1/**") + .allowedOriginPatterns("http://localhost:8089","http://localhost:4200") + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + .allowedHeaders("*") + .allowCredentials(true); + } + }; + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/controllers/FileStorageController.java b/backend/src/main/java/com/epsyl/eps/controllers/FileStorageController.java index 2a35294..e2f3a7c 100644 --- a/backend/src/main/java/com/epsyl/eps/controllers/FileStorageController.java +++ b/backend/src/main/java/com/epsyl/eps/controllers/FileStorageController.java @@ -17,7 +17,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.slf4j.Logger; @@ -26,7 +25,6 @@ @RestController @RequestMapping("/api/v1/files") -@CrossOrigin(origins = "http://localhost:4200") public class FileStorageController { private static final Logger logger = LoggerFactory.getLogger(FileStorageController.class); @@ -63,6 +61,5 @@ public ResponseEntity downloadFile(@PathVariable String _id) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); } } - } diff --git a/backend/src/main/java/com/epsyl/eps/controllers/ProspectsController.java b/backend/src/main/java/com/epsyl/eps/controllers/ProspectsController.java index c854700..478d113 100644 --- a/backend/src/main/java/com/epsyl/eps/controllers/ProspectsController.java +++ b/backend/src/main/java/com/epsyl/eps/controllers/ProspectsController.java @@ -1,5 +1,6 @@ package com.epsyl.eps.controllers; +import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -7,27 +8,69 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import com.epsyl.eps.dtos.ProspectDTO; +import com.epsyl.eps.entities.FileStorage; import com.epsyl.eps.entities.Prospect; -import com.epsyl.eps.services.ProspectServices; +import com.epsyl.eps.entities.User; +import com.epsyl.eps.repositories.FileStorageRepository; +import com.epsyl.eps.repositories.UserRepository; +import com.epsyl.eps.services.ProspectService; @RestController -@CrossOrigin(origins = "*") -@RequestMapping("api/v1/prospect") +@RequestMapping("/api/v1/prospect") public class ProspectsController { @Autowired - private ProspectServices prospectServices; + private ProspectService prospectService; + + @Autowired + private UserRepository userRepository; + + @Autowired + private FileStorageRepository fileStorageRepository; // GET /api/v1/prospect/all @GetMapping("/all") - public List getAllProspects() { - return prospectServices.allProspects(); + public List getAllProspects() { + List prospects = prospectService.allProspects(); + List prospectDTOs = new ArrayList<>(); + for (Prospect prospect : prospects) { + User bum = null; + User rh = null; + FileStorage cv = null; + FileStorage grille = null; + FileStorage dc = null; + + if (prospect.bum != null) { + bum = userRepository.findBy_id(prospect.bum); + } + + if (prospect.rh != null) { + rh = userRepository.findById(prospect.rh).orElse(null); + } + + if (prospect.cv != null) { + cv = fileStorageRepository.findById(prospect.cv).orElse(null); + } + + if (prospect.grille != null) { + grille = fileStorageRepository.findById(prospect.grille).orElse(null); + } + + if (prospect.dc != null) { + dc = fileStorageRepository.findById(prospect.dc).orElse(null); + } + + ProspectDTO prospectDTO = new ProspectDTO(prospect,bum, rh, cv, grille, dc); + prospectDTOs.add(prospectDTO); + } + return prospectDTOs; } // GET /api/v1/prospect/id @RequestMapping("/{id}") public ResponseEntity getProspectById(@PathVariable String _id) { - Optional prospect = prospectServices.getProspectByID(_id); + Optional prospect = prospectService.getProspectByID(_id); if (prospect.isPresent()) { return ResponseEntity.ok(prospect.get()); } else { @@ -38,55 +81,25 @@ public ResponseEntity getProspectById(@PathVariable String _id) { // GET /api/v1/prospect/trigram @GetMapping("/trigram") public boolean checkTrigram(@RequestParam String trigramme) { - return prospectServices.trigramExist(trigramme); + return prospectService.trigramExist(trigramme); } // POST /api/v1/prospect/save @PostMapping("/save") public Prospect saveProspect(@RequestBody Prospect prospect) { - return prospectServices.saveOrUpdateProspect(prospect); + return prospectService.save(prospect); } - // PUT /api/v1/prospect/edit/id - @PutMapping("/edit/{id}") - public ResponseEntity updateProspect(@PathVariable String _id, @RequestBody Prospect prospectDetails) { - Optional prospectOptional = prospectServices.getProspectByID(_id); - if (prospectOptional.isPresent()) { - Prospect prospect = prospectOptional.get(); - // Update fields here - prospect.setFirstName(prospectDetails.getFirstName()); - prospect.setLastName(prospectDetails.getLastName()); - prospect.setTrigramme(prospectDetails.getTrigramme()); - prospect.setEmail(prospectDetails.getEmail()); - prospect.setPhone(prospectDetails.getPhone()); - prospect.setProfil(prospectDetails.getProfil()); - prospect.setDateContact(prospectDetails.getDateContact()); - prospect.setDateEntretien(prospectDetails.getDateEntretien()); - prospect.setStatutProspect(prospectDetails.getStatutProspect()); - prospect.setBum(prospectDetails.getBum()); - prospect.setRh(prospectDetails.getRh()); - prospect.setSource(prospectDetails.getSource()); - prospect.setPretentionSalariale(prospectDetails.getPretentionSalariale()); - prospect.setNiveauEtude(prospectDetails.getNiveauEtude()); - prospect.setDisponibilite(prospectDetails.getDisponibilite()); - prospect.setMobiliteGeo(prospectDetails.getMobiliteGeo()); - prospect.setCv(prospectDetails.getCv()); - prospect.setGrille(prospectDetails.getGrille()); - prospect.setPr(prospectDetails.getPr()); - prospect.setDc(prospectDetails.getDc()); - prospect.setPushQualif(prospectDetails.getPushQualif()); - // Save updated prospect - Prospect updatedProspect = prospectServices.saveOrUpdateProspect(prospect); - return ResponseEntity.ok(updatedProspect); - } else { - return ResponseEntity.notFound().build(); - } + // PUT /api/v1/prospect/id + @PutMapping("/{id}") + public Prospect updateProspect(@PathVariable String _id, @RequestBody Prospect prospect) { + return prospectService.updateProspect(_id, prospect); } // DELETE /api/v1/prospect/delete/id @DeleteMapping("/delete/{id}") public ResponseEntity deleteProspect(@PathVariable String _id) { - prospectServices.deleteProspectById(_id); + prospectService.deleteProspectById(_id); return ResponseEntity.noContent().build(); } diff --git a/backend/src/main/java/com/epsyl/eps/controllers/TestController.java b/backend/src/main/java/com/epsyl/eps/controllers/TestController.java index 1fa34ee..e4128ef 100644 --- a/backend/src/main/java/com/epsyl/eps/controllers/TestController.java +++ b/backend/src/main/java/com/epsyl/eps/controllers/TestController.java @@ -1,12 +1,10 @@ package com.epsyl.eps.controllers; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.GetMapping; -@CrossOrigin(origins = "*", maxAge = 3600) @RestController @RequestMapping("/api/test") public class TestController { @@ -15,12 +13,6 @@ public String allAccess() { return "Public Content."; } - @GetMapping("/user") - @PreAuthorize("hasRole('USER') or hasRole('RH') or hasRole('BUM') or hasRole('ADMIN') or hasRole('SUPER_ADMIN')") - public String userAccess() { - return "User Content."; - } - @GetMapping("/rh") @PreAuthorize("hasRole('RH')") public String rhAccess() { @@ -37,10 +29,4 @@ public String bumAccess() { public String adminAccess() { return "Admin Content."; } - - @GetMapping("/super_admin") - @PreAuthorize("hasRole('SUPER_ADMIN')") - public String superAdminAccess() { - return "Super Admin Content."; - } -} +} \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/controllers/UsersController.java b/backend/src/main/java/com/epsyl/eps/controllers/UsersController.java index aad520f..a55d02f 100644 --- a/backend/src/main/java/com/epsyl/eps/controllers/UsersController.java +++ b/backend/src/main/java/com/epsyl/eps/controllers/UsersController.java @@ -1,22 +1,26 @@ package com.epsyl.eps.controllers; +import java.util.Optional; + import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import com.epsyl.eps.dtos.LoginRequestDto; import com.epsyl.eps.dtos.RegisterRequestDto; import com.epsyl.eps.dtos.UserResponseDto; +import com.epsyl.eps.entities.User; +import com.epsyl.eps.services.UserService; import com.epsyl.eps.services.authentification.AuthService; import lombok.RequiredArgsConstructor; @RestController -@CrossOrigin(origins = "*") @RequestMapping("/api/v1/user") @RequiredArgsConstructor public class UsersController { private final AuthService authService; + private final UserService userService; // POST api/v1/user/register @PostMapping("/register") @@ -30,41 +34,42 @@ public ResponseEntity login(@RequestBody LoginRequestDto user) return authService.login(user); } - // // GET api/v1/user/id - // @RequestMapping("/{id}") - // public ResponseEntity getUser(@PathVariable String _id) { - // Optional user = userServices.getUserByID(_id); - // if (user.isPresent()) { - // return ResponseEntity.ok(user.get()); - // } else { - // return ResponseEntity.notFound().build(); - // } - // } + // GET api/v1/user/id + @RequestMapping("/{id}") + public ResponseEntity getUser(@PathVariable String id) { + Optional user = userService.getUserByID(id); + if (user.isPresent()) { + return ResponseEntity.ok(user.get()); + } else { + return ResponseEntity.notFound().build(); + } + } - // // GET api/v1/user/all - // @GetMapping("/all") - // public Iterable getUsers() { - // return userServices.listAll(); - // } + // GET api/v1/user/all + @GetMapping("/all") + public Iterable getUsers() { + return userService.listAll(); + } - // // POST api/v1/user/save - // @PostMapping("/save") - // public User saveUser(@RequestBody User user) { - // return userServices.saveOrUpdateUser(user); - // } + // POST api/v1/user/id + @PostMapping("/save") + public User saveUser(@RequestBody User user) { + userService.saveUser(user); + return user; + } - // // PUT api/v1/user/edit/id - // @PutMapping("/edit/{id}") - // public User updateUser(@RequestBody User user, @PathVariable String _id) { - // user.set_id(_id); - // userServices.saveOrUpdateUser(user); - // return user; - // } + // PUT api/v1/user/id + @PutMapping("/{id}") + public User updateUser(@RequestBody User user, @PathVariable String id) { + user.set_id(id); + userService.saveUser(user); + return user; + } - // // DELETE api/v1/user/delete/id - // @DeleteMapping("/delete/{id}") - // public ResponseEntity deleteUser(@PathVariable String userId) { - // userServices.deleteUser(userId); - // return ResponseEntity.noContent().build(); - // } + // DELETE api/v1/user/delete/id + @DeleteMapping("/delete/{id}") + public ResponseEntity deleteUser(@PathVariable String userId) { + userService.deleteUser(userId); + return ResponseEntity.noContent().build(); + } } diff --git a/backend/src/main/java/com/epsyl/eps/dtos/ProspectDTO.java b/backend/src/main/java/com/epsyl/eps/dtos/ProspectDTO.java index a8f3363..51a5e09 100644 --- a/backend/src/main/java/com/epsyl/eps/dtos/ProspectDTO.java +++ b/backend/src/main/java/com/epsyl/eps/dtos/ProspectDTO.java @@ -3,39 +3,67 @@ import java.time.LocalDateTime; import java.util.Date; -import org.springframework.data.annotation.CreatedDate; - +import com.epsyl.eps.entities.FileStorage; +import com.epsyl.eps.entities.Prospect; import com.epsyl.eps.entities.PushQualif; +import com.epsyl.eps.entities.User; -import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data -@Builder +@NoArgsConstructor public class ProspectDTO { - public String _id; - public String firstName; - public String lastName; - public String trigramme; - public String email; - public String phone; - public String profil; - public Date dateContact; - public Date dateEntretien; - public String statutProspect; - public String bum; - public String rh; - public String source; - public Double pretentionSalariale; - public String niveauEtude; - public String disponibilite; - public String mobiliteGeo; - public String cv; - public String grille; - public Integer pr; - public String dc; - public PushQualif pushQualif; - @CreatedDate - public LocalDateTime createdDate; + private String _id; + private String firstName; + private String lastName; + private String trigramme; + private String email; + private String phone; + private String profil; + private Date dateContact; + private Date dateEntretien; + private String statutProspect; + private User bum; + private User rh; + private String source; + private Double pretentionSalariale; + private String niveauEtude; + private String disponibilite; + private String mobiliteGeo; + private Boolean goNogo; + private FileStorage cv; + private FileStorage grille; + private Integer pr; + private FileStorage dc; + private PushQualif pushQualif; + private LocalDateTime createdDate; + + public ProspectDTO(Prospect prospect, User bum, User rh, FileStorage cv, FileStorage grille, FileStorage dc) { + this._id = prospect.get_id(); + this.firstName = prospect.getFirstName(); + this.lastName = prospect.getLastName(); + this.trigramme = prospect.getTrigramme(); + this.email = prospect.getEmail(); + this.phone = prospect.getPhone(); + this.profil = prospect.getProfil(); + this.dateContact = prospect.getDateContact(); + this.dateEntretien = prospect.getDateEntretien(); + this.statutProspect = prospect.getStatutProspect(); + this.bum = bum; + this.rh = rh; + this.source = prospect.getSource(); + this.pretentionSalariale = prospect.getPretentionSalariale(); + this.niveauEtude = prospect.getNiveauEtude(); + this.disponibilite = prospect.getDisponibilite(); + this.mobiliteGeo = prospect.getMobiliteGeo(); + this.goNogo = prospect.getGoNogo(); + this.cv = cv; + this.grille = grille; + this.pr = prospect.getPr(); + this.dc = dc; + this.pushQualif = prospect.getPushQualif(); + this.createdDate = prospect.getCreatedDate(); + } } diff --git a/backend/src/main/java/com/epsyl/eps/dtos/UserResponseDto.java b/backend/src/main/java/com/epsyl/eps/dtos/UserResponseDto.java index 07268dd..6ffbf99 100644 --- a/backend/src/main/java/com/epsyl/eps/dtos/UserResponseDto.java +++ b/backend/src/main/java/com/epsyl/eps/dtos/UserResponseDto.java @@ -1,10 +1,31 @@ package com.epsyl.eps.dtos; +import java.util.Collection; + +import com.epsyl.eps.entities.Role; + import lombok.Builder; import lombok.Data; @Data @Builder public class UserResponseDto { + private String _id; + private String firstName; + private String lastName; + private String email; + private String password; + private Collection roles; private String message; -} + + public UserResponseDto(String _id, String firstName, String lastName, String email, String password, + Collection roles, String message) { + this._id = _id; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.password = password; + this.roles = roles; + this.message = message; + } +} \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/entities/Prospect.java b/backend/src/main/java/com/epsyl/eps/entities/Prospect.java index 74e422d..37e2dee 100644 --- a/backend/src/main/java/com/epsyl/eps/entities/Prospect.java +++ b/backend/src/main/java/com/epsyl/eps/entities/Prospect.java @@ -7,7 +7,9 @@ import org.springframework.data.annotation.Id; import org.springframework.data.mongodb.core.mapping.Document; +import com.epsyl.eps.configuration_global.ObjectIdDeserrializer; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.AllArgsConstructor; import lombok.Builder; @@ -22,6 +24,7 @@ public class Prospect { @Id + @JsonDeserialize(using = ObjectIdDeserrializer.class) public String _id; public String firstName; @@ -42,13 +45,13 @@ public class Prospect { public String statutProspect; - public String bum; + public String bum; // ObjectId - public String rh; + public String rh; // ObjectId public String source; - public double pretentionSalariale; + public Double pretentionSalariale; public String niveauEtude; @@ -56,13 +59,15 @@ public class Prospect { public String mobiliteGeo; - public String cv; + public Boolean goNogo; - public String grille; + public String cv; // ObjectId - public byte pr; + public String grille; // ObjectId - public String dc; + public Integer pr; + + public String dc; // ObjectId @JsonProperty public PushQualif pushQualif; diff --git a/backend/src/main/java/com/epsyl/eps/entities/User.java b/backend/src/main/java/com/epsyl/eps/entities/User.java index 3f2c0bc..3c68103 100644 --- a/backend/src/main/java/com/epsyl/eps/entities/User.java +++ b/backend/src/main/java/com/epsyl/eps/entities/User.java @@ -19,11 +19,12 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; + +@Document(collection = "users") @Data @Builder @AllArgsConstructor @NoArgsConstructor -@Document(collection = "users") public class User implements UserDetails { @Id private String _id; @@ -84,4 +85,5 @@ public boolean isCredentialsNonExpired() { public boolean isEnabled() { return true; } + } diff --git a/backend/src/main/java/com/epsyl/eps/enums/ERole.java b/backend/src/main/java/com/epsyl/eps/enums/ERole.java index 1455327..2bd5ba3 100644 --- a/backend/src/main/java/com/epsyl/eps/enums/ERole.java +++ b/backend/src/main/java/com/epsyl/eps/enums/ERole.java @@ -1,9 +1,7 @@ package com.epsyl.eps.enums; public enum ERole { - SUPER_ADMIN, ADMIN, RH, - BUM, - USER + BUM } diff --git a/backend/src/main/java/com/epsyl/eps/repositories/FileStorageRepository.java b/backend/src/main/java/com/epsyl/eps/repositories/FileStorageRepository.java index 7669acd..7841ca2 100644 --- a/backend/src/main/java/com/epsyl/eps/repositories/FileStorageRepository.java +++ b/backend/src/main/java/com/epsyl/eps/repositories/FileStorageRepository.java @@ -6,6 +6,4 @@ import com.epsyl.eps.entities.FileStorage; @Repository -public interface FileStorageRepository extends MongoRepository { - -} +public interface FileStorageRepository extends MongoRepository { } diff --git a/backend/src/main/java/com/epsyl/eps/repositories/ProspectRepository.java b/backend/src/main/java/com/epsyl/eps/repositories/ProspectRepository.java index 2070ce1..92b56c5 100644 --- a/backend/src/main/java/com/epsyl/eps/repositories/ProspectRepository.java +++ b/backend/src/main/java/com/epsyl/eps/repositories/ProspectRepository.java @@ -7,6 +7,7 @@ @Repository public interface ProspectRepository extends MongoRepository { + /* * Vérifier si le trigramme existe */ diff --git a/backend/src/main/java/com/epsyl/eps/repositories/RoleRepository.java b/backend/src/main/java/com/epsyl/eps/repositories/RoleRepository.java index 7614395..844338a 100644 --- a/backend/src/main/java/com/epsyl/eps/repositories/RoleRepository.java +++ b/backend/src/main/java/com/epsyl/eps/repositories/RoleRepository.java @@ -6,6 +6,7 @@ import com.epsyl.eps.entities.Role; + public interface RoleRepository extends MongoRepository { Optional findByName(String name); } diff --git a/backend/src/main/java/com/epsyl/eps/repositories/UserRepository.java b/backend/src/main/java/com/epsyl/eps/repositories/UserRepository.java index 86e90e7..9ae9f42 100644 --- a/backend/src/main/java/com/epsyl/eps/repositories/UserRepository.java +++ b/backend/src/main/java/com/epsyl/eps/repositories/UserRepository.java @@ -6,10 +6,13 @@ import com.epsyl.eps.entities.User; import java.util.Optional; + @Repository public interface UserRepository extends MongoRepository { Optional findByEmail(String email); - Boolean existsByEmail(String email); + boolean existsByEmail(String email); + + User findBy_id(String _id); } \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/services/FileStorageService.java b/backend/src/main/java/com/epsyl/eps/services/FileStorageService.java index 427d3da..3f0a61b 100644 --- a/backend/src/main/java/com/epsyl/eps/services/FileStorageService.java +++ b/backend/src/main/java/com/epsyl/eps/services/FileStorageService.java @@ -23,7 +23,7 @@ public String storeFile(MultipartFile file) throws IOException { fileStorage = fileStorageRepository.save(fileStorage); - return fileStorage.get_id(); + return fileStorage._id; } public FileStorage getFile(String id) { diff --git a/backend/src/main/java/com/epsyl/eps/services/ProspectService.java b/backend/src/main/java/com/epsyl/eps/services/ProspectService.java new file mode 100644 index 0000000..3ef36e9 --- /dev/null +++ b/backend/src/main/java/com/epsyl/eps/services/ProspectService.java @@ -0,0 +1,90 @@ +package com.epsyl.eps.services; + +import java.util.List; +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.stereotype.Service; + +import com.epsyl.eps.entities.Prospect; +import com.epsyl.eps.repositories.ProspectRepository; + +@Service +public class ProspectService { + + @Autowired + private ProspectRepository prospectRepository; + + @Autowired + private MongoTemplate mongoTemplate; + + public Prospect getProspectWithUserDetail(String prospectId) { + Aggregation aggregation = Aggregation.newAggregation( + Aggregation.match(Criteria.where("_id").is(prospectId)), + Aggregation.lookup("users", "bum", "_id", "bumDetails"), + Aggregation.lookup("users", "rh", "_id", "rhDetails") + ); + AggregationResults results = mongoTemplate.aggregate(aggregation, "prospects", Prospect.class); + return results.getUniqueMappedResult(); + } + + // All prospects + public List allProspects() { + return prospectRepository.findAll(); + } + + // One prospect + public Optional getProspectByID(String _id) { + return prospectRepository.findById(_id); + } + + public Prospect save(Prospect prospect) { + return prospectRepository.save(prospect); + } + + public Prospect updateProspect(String id, Prospect updatedProspect) { + // Récupérer le prospect existant depuis la base de données + Prospect existingProspect = prospectRepository.findById(id).orElseThrow(() -> new RuntimeException("Prospect not found")); + + existingProspect.setFirstName(updatedProspect.getFirstName()); + existingProspect.setLastName(updatedProspect.getLastName()); + existingProspect.setTrigramme(updatedProspect.getTrigramme()); + existingProspect.setEmail(updatedProspect.getEmail()); + existingProspect.setPhone(updatedProspect.getPhone()); + existingProspect.setProfil(updatedProspect.getProfil()); + existingProspect.setDateContact(updatedProspect.getDateContact()); + existingProspect.setDateEntretien(updatedProspect.getDateEntretien()); + existingProspect.setStatutProspect(updatedProspect.getStatutProspect()); + existingProspect.setBum(updatedProspect.getBum()); + existingProspect.setRh(updatedProspect.getRh()); + existingProspect.setSource(updatedProspect.getSource()); + existingProspect.setPretentionSalariale(updatedProspect.getPretentionSalariale()); + existingProspect.setNiveauEtude(updatedProspect.getNiveauEtude()); + existingProspect.setDisponibilite(updatedProspect.getDisponibilite()); + existingProspect.setMobiliteGeo(updatedProspect.getMobiliteGeo()); + existingProspect.setGoNogo(updatedProspect.getGoNogo()); + existingProspect.setCv(updatedProspect.getCv()); + existingProspect.setGrille(updatedProspect.getGrille()); + existingProspect.setPr(updatedProspect.getPr()); + existingProspect.setDc(updatedProspect.getDc()); + existingProspect.setPushQualif(updatedProspect.getPushQualif()); + existingProspect.setCreatedDate(updatedProspect.getCreatedDate()); + + return existingProspect; + } + + public Optional deleteProspectById(String _id) { + return prospectRepository.findById(_id).flatMap(prospect -> { + prospectRepository.deleteById(prospect.get_id()); + return Optional.of(prospect); + }); + } + + public boolean trigramExist(String trigramme) { + return prospectRepository.existsByTrigramme(trigramme); + } +} diff --git a/backend/src/main/java/com/epsyl/eps/services/ProspectServices.java b/backend/src/main/java/com/epsyl/eps/services/ProspectServices.java deleted file mode 100644 index b066e91..0000000 --- a/backend/src/main/java/com/epsyl/eps/services/ProspectServices.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.epsyl.eps.services; - -import java.util.List; -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.epsyl.eps.entities.Prospect; -import com.epsyl.eps.repositories.ProspectRepository; - -@Service -public class ProspectServices { - - @Autowired - private ProspectRepository prospectRepository; - - public List allProspects() { - return prospectRepository.findAll(); - } - - public Optional getProspectByID(String _id) { - return prospectRepository.findById(_id); - } - - public Prospect saveOrUpdateProspect(Prospect prospect) { - return prospectRepository.save(prospect); - } - - public Optional deleteProspectById(String _id) { - return prospectRepository.findById(_id).flatMap(prospect -> { - prospectRepository.deleteById(prospect.get_id()); - return Optional.of(prospect); - }); - } - - public boolean trigramExist(String trigramme) { - return prospectRepository.existsByTrigramme(trigramme); - } -} diff --git a/backend/src/main/java/com/epsyl/eps/services/UserService.java b/backend/src/main/java/com/epsyl/eps/services/UserService.java new file mode 100644 index 0000000..3c01f7f --- /dev/null +++ b/backend/src/main/java/com/epsyl/eps/services/UserService.java @@ -0,0 +1,19 @@ +package com.epsyl.eps.services; + +import java.util.List; +import java.util.Optional; + +import com.epsyl.eps.entities.Role; +import com.epsyl.eps.entities.User; + +public interface UserService { + Role addNewRole(Role role); + + void addRoleToUser(User user, List roles); + + // CRUD operations + Iterable listAll(); + Optional getUserByID(String id); + User saveUser(User user); + Optional deleteUser(String _id); +} \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/services/UserServiceImpl.java b/backend/src/main/java/com/epsyl/eps/services/UserServiceImpl.java index 5442298..4faf352 100644 --- a/backend/src/main/java/com/epsyl/eps/services/UserServiceImpl.java +++ b/backend/src/main/java/com/epsyl/eps/services/UserServiceImpl.java @@ -1,6 +1,7 @@ package com.epsyl.eps.services; import java.util.List; +import java.util.Optional; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -18,7 +19,8 @@ @Service @Transactional @RequiredArgsConstructor -public class UserServiceImpl implements UserServices, UserDetailsService { +public class UserServiceImpl implements UserService, UserDetailsService { + private final UserRepository userRepository; private final RoleRepository roleRepository; @@ -35,26 +37,31 @@ public Role addNewRole(Role role) { @Override public void addRoleToUser(User user, List roles) { - // User userFromDB = userRepository.findByEmail(user.getEmail()).orElse(null); + // User userFromDB = userRepository.findByEmail(user.getEmail()).orElse(null); - // roles.stream() - // .map(Role::getName) - // .map(roleRepository::findByName) - // .forEach(userFromDB.getRoles()::add); + // roles.stream() + // .map(Role::getName) + // .map(roleRepository::findByName) + // .forEach(userFromDB.getRoles()::add); } - // public Optional getUserByID(String userId) { - // return this.userRepository.findById(userId); - // } + public Optional getUserByID(String userId) { + return this.userRepository.findById(userId); + } - // public Iterable listAll() { - // return this.userRepository.findAll(); - // } + public Iterable listAll() { + return this.userRepository.findAll(); + } - // public Optional deleteUser(String _id) { - // return this.userRepository.findById(_id).flatMap(user -> { - // userRepository.deleteById(user.get_id()); - // return Optional.of(user); - // }); - // } + public Optional deleteUser(String _id) { + return this.userRepository.findById(_id).flatMap(user -> { + userRepository.deleteById(user.get_id()); + return Optional.of(user); + }); + } + + @Override + public User saveUser(User user) { + return this.userRepository.save(user); + } } diff --git a/backend/src/main/java/com/epsyl/eps/services/UserServices.java b/backend/src/main/java/com/epsyl/eps/services/UserServices.java deleted file mode 100644 index 44c0793..0000000 --- a/backend/src/main/java/com/epsyl/eps/services/UserServices.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.epsyl.eps.services; - -import java.util.List; - -import com.epsyl.eps.entities.Role; -import com.epsyl.eps.entities.User; - -public interface UserServices { - Role addNewRole(Role role); - - void addRoleToUser(User user, List roles); -} \ No newline at end of file diff --git a/backend/src/main/java/com/epsyl/eps/services/authentification/AuthService.java b/backend/src/main/java/com/epsyl/eps/services/authentification/AuthService.java index 814492b..aeb7722 100644 --- a/backend/src/main/java/com/epsyl/eps/services/authentification/AuthService.java +++ b/backend/src/main/java/com/epsyl/eps/services/authentification/AuthService.java @@ -88,6 +88,11 @@ public ResponseEntity login(LoginRequestDto request) { return ResponseEntity.ok() .headers(responseHeaders) .body(UserResponseDto.builder() + ._id(user.get_id()) + .firstName(user.getFirstName()) + .lastName(user.getLastName()) + .email(user.getEmail()) + .roles(user.getRoles()) .message("Utilisateur authentifié avec succès") .build()); } diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 300b5ae..ebcb55f 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -18,7 +18,5 @@ spring.servlet.multipart.file-size-threshold=10MB # spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http # App properties -epsyl.eps.jwtCookieName=Epsyl-alcen -epsyl.eps.jwtSecret= ***===Epsyl-alcen===*** -epsyl.eps.jwtExpirationMs=86400000 +spring.security.oauth2.resourceserver.jwt.public-key-location=JeSuisLaPuteDEpsylAlcenPourFaireToutEtNImporteQuoi