|
|
@ -1,35 +1,21 @@
|
|
|
|
package fr.iut.sciencequest.sae.controllers;
|
|
|
|
package fr.iut.sciencequest.sae.controllers;
|
|
|
|
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.assemblers.PartieModelAssembler;
|
|
|
|
import fr.iut.sciencequest.sae.assemblers.PartieModelAssembler;
|
|
|
|
import fr.iut.sciencequest.sae.assemblers.QuestionModelAssembler;
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.dto.PartieDTO;
|
|
|
|
import fr.iut.sciencequest.sae.dto.PartieDTO;
|
|
|
|
import fr.iut.sciencequest.sae.entities.Partie;
|
|
|
|
import fr.iut.sciencequest.sae.entities.Partie;
|
|
|
|
import fr.iut.sciencequest.sae.entities.Question;
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.exceptions.DuplicatedFieldException;
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.exceptions.notFound.PartieNotFoundException;
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.repositories.PartieRepository;
|
|
|
|
|
|
|
|
import fr.iut.sciencequest.sae.services.PartieService;
|
|
|
|
import fr.iut.sciencequest.sae.services.PartieService;
|
|
|
|
import fr.iut.sciencequest.sae.services.QuestionService;
|
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
|
|
|
|
|
import org.springframework.data.web.PagedResourcesAssembler;
|
|
|
|
|
|
|
|
import org.springframework.hateoas.EntityModel;
|
|
|
|
|
|
|
|
import org.springframework.hateoas.Link;
|
|
|
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@AllArgsConstructor
|
|
|
|
@AllArgsConstructor
|
|
|
|
@RequestMapping("/api/v1/partie")
|
|
|
|
@RequestMapping("/api/v1/partie")
|
|
|
|
public class PartieController extends Controller {
|
|
|
|
public class PartieController extends Controller {
|
|
|
|
private final PartieModelAssembler partieModelAssembler;
|
|
|
|
private final PartieModelAssembler partieModelAssembler;
|
|
|
|
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
|
|
|
|
|
|
|
private final PagedResourcesAssembler<Partie> pagedResourcesAssembler;
|
|
|
|
|
|
|
|
private final PartieService partieService;
|
|
|
|
private final PartieService partieService;
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/{id}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@RequestMapping(value = "/{id}",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ -38,16 +24,10 @@ public class PartieController extends Controller {
|
|
|
|
return partieModelAssembler.toModel(partie);
|
|
|
|
return partieModelAssembler.toModel(partie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
|
|
public Partie createPartie(@RequestBody Partie partie) {
|
|
|
|
public Partie createPartie(@RequestBody Integer idJeu, Integer idUtilisateur, List<Integer> thematiques, Integer idDifficulte) {
|
|
|
|
try {
|
|
|
|
return this.partieService.create(idJeu, idUtilisateur, thematiques, idDifficulte);
|
|
|
|
return this.partieRepository.save(partie);
|
|
|
|
|
|
|
|
} catch (DataIntegrityViolationException e) {
|
|
|
|
|
|
|
|
throw new DuplicatedFieldException("ERREUR : il existe déjà une partie : " + partie.getId() + " en base");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|