Added endpoint to add an existing activity to session
This commit is contained in:
@@ -116,17 +116,23 @@ public class SessionResource {
|
||||
|
||||
//Commented because not finished
|
||||
|
||||
/*@GetMapping("/activities/add")
|
||||
@GetMapping("/{id_session}/activities/add/{id_act}")
|
||||
@PreAuthorize("hasRole('coach') or hasRole('admin')")
|
||||
public ResponseEntity<?> addActivity(@RequestBody ActiviteDTO dto) {
|
||||
try {
|
||||
Activite activite = maptoEntity(dto);
|
||||
activiteDAO.save(activite);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(maptoDTO(activite));
|
||||
} catch (Exception ex) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ex.getMessage());
|
||||
public ResponseEntity<?> addActivity(@PathVariable Integer id_sess, @PathVariable Integer id_act) {
|
||||
Session s = sessionDAO.findById(id_sess).get();
|
||||
if(s.equals(null)){
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Session not found");
|
||||
}
|
||||
}*/
|
||||
Activite a = activiteDAO.findById(id_act).get();
|
||||
if(a.equals(null)){
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Activite not found");
|
||||
}
|
||||
List<Activite> l = s.getActivites();
|
||||
l.add(a);
|
||||
s.setActivites(l);
|
||||
sessionDAO.save(s);
|
||||
return ResponseEntity.status(200).body(maptoDTO(s));
|
||||
}
|
||||
|
||||
private SessionDTO maptoDTO(Session s) {
|
||||
SessionDTO dto = new SessionDTO();
|
||||
|
||||
Reference in New Issue
Block a user