change endpoints
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
package hackathon.FrisbYEE.rest;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import hackathon.FrisbYEE.jpa.metier.Athlete;
|
||||
import hackathon.FrisbYEE.jpa.service.AthleteDAO;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
@CrossOrigin(origins = "http://localhost:3000")
|
||||
public class UserSyncResource {
|
||||
@Autowired
|
||||
private AthleteDAO athleteDAO;
|
||||
|
||||
@PostMapping("/sync")
|
||||
@Transactional
|
||||
public ResponseEntity<Void> sync() {
|
||||
Jwt jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
String keycloakId = jwt.getSubject();
|
||||
String firstName = jwt.getClaimAsString("given_name");
|
||||
String lastName = jwt.getClaimAsString("family_name");
|
||||
if (!athleteDAO.existsByKeycloakId(keycloakId)) {
|
||||
Athlete athlete = new Athlete();
|
||||
athlete.setKeycloakId(keycloakId);
|
||||
athlete.setName(lastName);
|
||||
athlete.setPrenom(firstName);
|
||||
athlete.setRole(hackathon.FrisbYEE.jpa.metier.Role.athlete);
|
||||
athleteDAO.save(athlete);
|
||||
}
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user