Added Keycloak related endpoints and other ones
This commit is contained in:
@@ -165,7 +165,6 @@ public class ActiviteResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Activite mapToEntity(ActiviteDTO dto) {
|
private Activite mapToEntity(ActiviteDTO dto) {
|
||||||
Activite activite = new Activite();
|
Activite activite = new Activite();
|
||||||
//ID géré par Postgre ?
|
//ID géré par Postgre ?
|
||||||
|
|||||||
@@ -81,6 +81,13 @@ public class AthleteResource {
|
|||||||
return ResponseEntity.ok(mapToDTO(athlete));
|
return ResponseEntity.ok(mapToDTO(athlete));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/keycloak/{keycloak_id}")
|
||||||
|
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||||
|
public ResponseEntity<AthleteDTO> getByKeycloakId(@PathVariable String keycloak_id) {
|
||||||
|
Athlete athlete = athleteDAO.findByKeycloakId(keycloak_id).get();
|
||||||
|
return ResponseEntity.ok(mapToDTO(athlete));
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "Met à jour l'athlète ayant l'identifiant correspondant")
|
@Operation(summary = "Met à jour l'athlète ayant l'identifiant correspondant")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
@ApiResponse(responseCode = "200", description = "Mise à jour effectuée", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AthleteDTO.class)))
|
||||||
|
|||||||
@@ -39,14 +39,22 @@ public class CoachResource {
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{keycloak_id}")
|
@GetMapping("/keycloak/{keycloak_id}")
|
||||||
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||||
public CoachDTO getById(@PathVariable String keycloak_id) {
|
public CoachDTO getByKeycloakId(@PathVariable String keycloak_id) {
|
||||||
Coach coach = coachDAO.findByKeycloakId(keycloak_id)
|
Coach coach = coachDAO.findByKeycloakId(keycloak_id)
|
||||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||||
return mapToDTO(coach);
|
return mapToDTO(coach);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||||
|
public CoachDTO getById(@PathVariable Integer id) {
|
||||||
|
Coach coach = coachDAO.findById(id)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||||
|
return mapToDTO(coach);
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@PreAuthorize("hasRole('Admin')")
|
@PreAuthorize("hasRole('Admin')")
|
||||||
public ResponseEntity<CoachDTO> update(@PathVariable Integer id, @RequestBody CoachDTO dto) {
|
public ResponseEntity<CoachDTO> update(@PathVariable Integer id, @RequestBody CoachDTO dto) {
|
||||||
@@ -59,6 +67,15 @@ public class CoachResource {
|
|||||||
return ResponseEntity.ok(updatedDto);
|
return ResponseEntity.ok(updatedDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/session")
|
||||||
|
@PreAuthorize("hasRole('Admin') or hasRole('Coach')")
|
||||||
|
public ResponseEntity<List<?>> getSessionsForCoach(@PathVariable Integer id) {
|
||||||
|
Coach coach = coachDAO.findById(id)
|
||||||
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Coach not found"));
|
||||||
|
List<?> sessions = coach.getSessions();
|
||||||
|
return ResponseEntity.ok(sessions);
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
@PreAuthorize("hasRole('Admin')")
|
@PreAuthorize("hasRole('Admin')")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ public class UserResource {
|
|||||||
return ResponseEntity.ok(mapToDTO(user));
|
return ResponseEntity.ok(mapToDTO(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/keycloak/{keycloak_id}")
|
||||||
|
@PreAuthorize("hasRole('admin') or hasRole('coach') or hasRole('athlete')")
|
||||||
|
public ResponseEntity<UserDTO> getByKeycloakId(@PathVariable String keycloak_id) {
|
||||||
|
User user = userDAO.findByKeycloakId(keycloak_id).get();
|
||||||
|
return ResponseEntity.ok(mapToDTO(user));
|
||||||
|
}
|
||||||
|
|
||||||
private UserDTO mapToDTO(User user) {
|
private UserDTO mapToDTO(User user) {
|
||||||
UserDTO dto = new UserDTO();
|
UserDTO dto = new UserDTO();
|
||||||
dto.setId(user.getId());
|
dto.setId(user.getId());
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
import keycloak from "./keycloak";
|
import keycloak from "./keycloak";
|
||||||
|
import { get } from "http";
|
||||||
|
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
@@ -17,7 +18,6 @@ api.interceptors.request.use((config) => {
|
|||||||
if (keycloak?.token) {
|
if (keycloak?.token) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
config.headers.Authorization = `Bearer ${keycloak.token}`;
|
config.headers.Authorization = `Bearer ${keycloak.token}`;
|
||||||
console.log(config.headers.Authorization);
|
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@@ -36,11 +36,13 @@ export function clearAuthToken() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const athleteService = {
|
export const athleteService = {
|
||||||
create: (data: any) => api.post("/athletes/create", data),
|
// controller is mounted at /athlete
|
||||||
getAll: () => api.get("/athletes/all"),
|
create: (data: any) => api.post("/athlete/create", data),
|
||||||
getByKeycloakId: (id: number | string) => api.get(`/athletes/${id}`),
|
getAll: () => api.get("/athlete/all"),
|
||||||
update: (id: number | string, data: any) => api.put(`/athletes/${id}`, data),
|
getById: (id: number | string) => api.get(`/athlete/${id}`),
|
||||||
delete: (id: number | string) => api.delete(`/athletes/${id}`),
|
getByKeycloakId: (keycloakId: string) => api.get(`/athlete/keycloak/${encodeURIComponent(keycloakId)}`),
|
||||||
|
update: (id: number | string, data: any) => api.put(`/athlete/${id}`, data),
|
||||||
|
delete: (id: number | string) => api.delete(`/athlete/${id}`),
|
||||||
|
|
||||||
// session-related endpoints exposed by AthleteResource
|
// session-related endpoints exposed by AthleteResource
|
||||||
getSessionsForAthlete: (athleteId: number | string) => api.get(`/athletes/athlete/${athleteId}/session`),
|
getSessionsForAthlete: (athleteId: number | string) => api.get(`/athletes/athlete/${athleteId}/session`),
|
||||||
@@ -57,6 +59,7 @@ export const activiteService = {
|
|||||||
getById: (id: number | string) => api.get(`/activite/${id}`),
|
getById: (id: number | string) => api.get(`/activite/${id}`),
|
||||||
getAll: () => api.get(`/activite/all`),
|
getAll: () => api.get(`/activite/all`),
|
||||||
getByTheme: (theme: string) => api.get(`/activite/theme/${encodeURIComponent(theme)}`),
|
getByTheme: (theme: string) => api.get(`/activite/theme/${encodeURIComponent(theme)}`),
|
||||||
|
getDataActivite: (id: number | string) => api.get(`/activite/${id}`),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sessionService = {
|
export const sessionService = {
|
||||||
@@ -83,15 +86,16 @@ export const coachService = {
|
|||||||
getByKeycloakId: (id: number | string) => api.get(`/coach/${id}`),
|
getByKeycloakId: (id: number | string) => api.get(`/coach/${id}`),
|
||||||
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
update: (id: number | string, data: any) => api.put(`/coach/update/${id}`, data),
|
||||||
delete: (id: number | string) => api.delete(`/coach/delete/${id}`),
|
delete: (id: number | string) => api.delete(`/coach/delete/${id}`),
|
||||||
|
getSessionsForCoach: (coachId: number | string) => api.get(`/coach/${coachId}/session`),
|
||||||
// plural convenience
|
// plural convenience
|
||||||
createPlural: (data: any) => api.post(`/coaches`, data),
|
createPlural: (data: any) => api.post(`/coaches`, data),
|
||||||
getAllPlural: () => api.get(`/coaches`),
|
getAllPlural: () => api.get(`/coaches`),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const userService = {
|
export const userService = {
|
||||||
getByKeycloakId: (id: number | string) => api.get(`/users/${id}`),
|
getByKeycloakId: (keycloak_id: string) => api.get(`/users/${keycloak_id}`),
|
||||||
getAll: () => api.get(`/users`),
|
getAll: () => api.get(`/users/all`),
|
||||||
|
sync: () => api.post(`/users/sync`),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
export default api;
|
||||||
Reference in New Issue
Block a user