| 1 | package fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.controllers; | |
| 2 | ||
| 3 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.dtos.DateSondeeDto; | |
| 4 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.exception.DateSondageAlreadyExistsException; | |
| 5 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.exception.SondageCloturedException; | |
| 6 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.Choix; | |
| 7 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.models.DateSondee; | |
| 8 | import fr.univ.lorraine.ufr.mim.m2.gi.mysurvey.services.DateSondeeService; | |
| 9 | import io.swagger.v3.oas.annotations.Operation; | |
| 10 | import jakarta.persistence.NoResultException; | |
| 11 | import org.apache.commons.lang3.EnumUtils; | |
| 12 | import org.modelmapper.ModelMapper; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.http.HttpStatus; | |
| 15 | import org.springframework.web.bind.annotation.*; | |
| 16 | import org.springframework.web.server.ResponseStatusException; | |
| 17 | ||
| 18 | @RestController | |
| 19 | @RequestMapping(value = "/api/participer") | |
| 20 | public class ParticipationController { | |
| 21 | ||
| 22 | @Autowired | |
| 23 | private DateSondeeService dateSondeeService; | |
| 24 | ||
| 25 | @Autowired | |
| 26 | private ModelMapper mapper; | |
| 27 | ||
| 28 | /** | |
| 29 | * Ajout d'un participant (A utiliser sans dateSondeeId) | |
| 30 | * @param id de la DateSondage | |
| 31 | * @param dto DateSondeeDto de la participation | |
| 32 | * @return DateSondee créée | |
| 33 | */ | |
| 34 | @PostMapping(value = "/{id}") | |
| 35 | @ResponseStatus(HttpStatus.CREATED) | |
| 36 | @Operation(summary = "Créer un vote d'un participant sur une date", description = "Retourne l'objet DateSondee créé correspondant à la participation créée.") | |
| 37 | public DateSondeeDto create(@PathVariable("id") Long id, @RequestBody DateSondeeDto dto) { | |
| 38 |
1
1. create : negated conditional → KILLED |
if(dto.getParticipant() == null) |
| 39 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Précisez un participant."); | |
| 40 |
1
1. create : negated conditional → KILLED |
if(!EnumUtils.isValidEnum(Choix.class, dto.getChoix())) |
| 41 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Précisez un choix valide."); | |
| 42 | try { | |
| 43 | DateSondee model = mapper.map(dto, DateSondee.class); | |
| 44 | var result = dateSondeeService.create(id, dto.getParticipant(), model); | |
| 45 |
1
1. create : replaced return value with null for fr/univ/lorraine/ufr/mim/m2/gi/mysurvey/controllers/ParticipationController::create → KILLED |
return mapper.map(result, DateSondeeDto.class); |
| 46 | } catch (DateSondageAlreadyExistsException | SondageCloturedException e) { | |
| 47 | throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage()); | |
| 48 | } catch (NoResultException e){ | |
| 49 | throw new ResponseStatusException(HttpStatus.NOT_FOUND,e.getMessage()); | |
| 50 | } catch (Exception e) { | |
| 51 | throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Erreur lors de la création de la participation."); | |
| 52 | } | |
| 53 | } | |
| 54 | } | |
Mutations | ||
| 38 |
1.1 |
|
| 40 |
1.1 |
|
| 45 |
1.1 |