change endpoints

This commit is contained in:
tuanvu
2026-01-09 10:46:12 +01:00
parent dc814d4a7b
commit 46396d035b
4 changed files with 32 additions and 90 deletions

View File

@@ -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();
}
}