Modifications aprèm J4

Springboot
Alix JEUDI--LEMOINE 1 year ago
parent 8826093d91
commit 700112823e

@ -21,4 +21,5 @@ public class PartieModelAssembler extends RepresentationModelAssemblerSupport<Pa
ModelMapper mapper = new ModelMapper();
return mapper.map(entity, PartieDTO.class);
}
}

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

@ -0,0 +1,11 @@
package fr.iut.sciencequest.sae.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
public class MalformedPartyException extends RuntimeException {
public MalformedPartyException(String message) {
super(message);
}
}

@ -7,19 +7,34 @@ import fr.iut.sciencequest.sae.services.interfaces.IPartieService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.List;
@AllArgsConstructor
@Service
public class PartieService implements IPartieService {
private final PartieRepository partieRepository;
/*private final JeuRepository jeuRepository;
private final UtilisateurRepository utilisateurRepository;
private final ThematiqueRepository thematiqueRepository;
private final DifficulteRepository difficulteRepository;*/
public Partie findById(int id) {
return this.partieRepository.findById(id).orElseThrow(() ->
new PartieNotFoundException("Partie", id)
);
}
public Partie save(Partie p) {
public Partie create(Integer idJeu, Integer idUtilisateur, List<Integer> thematiques, Integer idDifficulte) {
/*try {
Jeu jeu = jeuService.findById(idJeu);
if(partie.getJeu().getNom() == null) {
throw new MalformedPartyException("Party's game id is not given or is a false value");
}
return this.partieRepository.save(partie);
} catch (DataIntegrityViolationException e) {
throw new DuplicatedFieldException("ERREUR : il existe déjà une partie : " + partie.getId() + " en base");
}*/
return new Partie();
}
}

@ -2,7 +2,9 @@ package fr.iut.sciencequest.sae.services.interfaces;
import fr.iut.sciencequest.sae.entities.Partie;
import java.util.List;
public interface IPartieService {
Partie findById(int id);
Partie save(Partie p);
Partie create(Integer idJeu, Integer idUtilisateur, List<Integer> thematiques, Integer idDifficulte);
}

Loading…
Cancel
Save