Skip to content

Commit

Permalink
Mise à jour
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolphe_Lassalle committed Jun 10, 2024
1 parent dc7a4f8 commit 7cafb05
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 216 deletions.
4 changes: 2 additions & 2 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.6</version>
<version>3.3.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.epsyl</groupId>
Expand Down Expand Up @@ -100,4 +100,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// };
// }

}
Original file line number Diff line number Diff line change
@@ -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<ObjectId> {

@Override
public ObjectId deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
return new ObjectId(jsonParser.getText());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -63,6 +61,5 @@ public ResponseEntity<byte[]> downloadFile(@PathVariable String _id) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
}


}
Original file line number Diff line number Diff line change
@@ -1,33 +1,76 @@
package com.epsyl.eps.controllers;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
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<Prospect> getAllProspects() {
return prospectServices.allProspects();
public List<ProspectDTO> getAllProspects() {
List<Prospect> prospects = prospectService.allProspects();
List<ProspectDTO> 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<Prospect> getProspectById(@PathVariable String _id) {
Optional<Prospect> prospect = prospectServices.getProspectByID(_id);
Optional<Prospect> prospect = prospectService.getProspectByID(_id);
if (prospect.isPresent()) {
return ResponseEntity.ok(prospect.get());
} else {
Expand All @@ -38,55 +81,25 @@ public ResponseEntity<Prospect> 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<Prospect> updateProspect(@PathVariable String _id, @RequestBody Prospect prospectDetails) {
Optional<Prospect> 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<Void> deleteProspect(@PathVariable String _id) {
prospectServices.deleteProspectById(_id);
prospectService.deleteProspectById(_id);
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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() {
Expand All @@ -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.";
}
}
}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -30,41 +34,42 @@ public ResponseEntity<UserResponseDto> login(@RequestBody LoginRequestDto user)
return authService.login(user);
}

// // GET api/v1/user/id
// @RequestMapping("/{id}")
// public ResponseEntity<User> getUser(@PathVariable String _id) {
// Optional<User> 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<User> getUser(@PathVariable String id) {
Optional<User> 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<User> getUsers() {
// return userServices.listAll();
// }
// GET api/v1/user/all
@GetMapping("/all")
public Iterable<User> 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<Void> deleteUser(@PathVariable String userId) {
// userServices.deleteUser(userId);
// return ResponseEntity.noContent().build();
// }
// DELETE api/v1/user/delete/id
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteUser(@PathVariable String userId) {
userService.deleteUser(userId);
return ResponseEntity.noContent().build();
}
}
Loading

0 comments on commit 7cafb05

Please sign in to comment.