forked from tom.biard/ScienceQuest
parent
0b22f02742
commit
a2fe781a96
@ -0,0 +1,24 @@
|
||||
package fr.iut.sciencequest.sae.assemblers;
|
||||
|
||||
import fr.iut.sciencequest.sae.controllers.PartieController;
|
||||
import fr.iut.sciencequest.sae.entities.Partie;
|
||||
import fr.iut.sciencequest.sae.dto.PartieDTO;
|
||||
import jakarta.annotation.Nullable;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PartieModelAssembler extends RepresentationModelAssemblerSupport<Partie, PartieDTO> {
|
||||
public PartieModelAssembler() {
|
||||
super(PartieController.class, PartieDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public PartieDTO toModel(@Nullable Partie entity) {
|
||||
ModelMapper mapper = new ModelMapper();
|
||||
return mapper.map(entity, PartieDTO.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package fr.iut.sciencequest.sae.assemblers;
|
||||
|
||||
import fr.iut.sciencequest.sae.controllers.ScientifiqueController;
|
||||
import fr.iut.sciencequest.sae.dto.ScientifiqueDTO;
|
||||
import fr.iut.sciencequest.sae.entities.scientifique.Scientifique;
|
||||
import jakarta.annotation.Nullable;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ScientifiqueModelAssembler extends RepresentationModelAssemblerSupport<Scientifique, ScientifiqueDTO> {
|
||||
public ScientifiqueModelAssembler() {
|
||||
super(ScientifiqueController.class, ScientifiqueDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public ScientifiqueDTO toModel(@Nullable Scientifique entity) {
|
||||
ModelMapper mapper = new ModelMapper();
|
||||
return mapper.map(entity, ScientifiqueDTO.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package fr.iut.sciencequest.sae.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import fr.iut.sciencequest.sae.entities.Partie;
|
||||
import fr.iut.sciencequest.sae.entities.Reponse;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class JoueurDTO extends RepresentationModel<JoueurDTO> {
|
||||
@NotNull
|
||||
private int id;
|
||||
|
||||
@NotBlank
|
||||
private String pseudo;
|
||||
|
||||
private Partie partie;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package fr.iut.sciencequest.sae.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import fr.iut.sciencequest.sae.entities.Jeu;
|
||||
import fr.iut.sciencequest.sae.entities.joueur.Joueur;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class PartieDTO extends RepresentationModel<PartieDTO> {
|
||||
@NotNull
|
||||
private int id;
|
||||
@NotEmpty
|
||||
private String codeInvitation;
|
||||
@NotEmpty
|
||||
private Iterable<Joueur> joueurs;
|
||||
@NotEmpty
|
||||
private Jeu jeu;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package fr.iut.sciencequest.sae.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import fr.iut.sciencequest.sae.entities.Reponse;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class QuestionDTO extends RepresentationModel<QuestionDTO> {
|
||||
@NotNull
|
||||
private int id;
|
||||
@NotBlank
|
||||
private String question;
|
||||
@NotEmpty
|
||||
private Iterable<Reponse> reponses;
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package fr.iut.sciencequest.sae.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import fr.iut.sciencequest.sae.entities.Difficulte;
|
||||
import fr.iut.sciencequest.sae.entities.Sexe;
|
||||
import fr.iut.sciencequest.sae.entities.Thematique;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.*;
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class ScientifiqueDTO extends RepresentationModel<ScientifiqueDTO> {
|
||||
@NotNull
|
||||
private int id;
|
||||
|
||||
@NotNull
|
||||
private Difficulte difficulte;
|
||||
|
||||
@NotNull
|
||||
private Thematique thematique;
|
||||
|
||||
@URL
|
||||
private String pathToPhoto;
|
||||
|
||||
@NotBlank
|
||||
private String nom;
|
||||
|
||||
@NotBlank
|
||||
private String prenom;
|
||||
|
||||
@NotBlank
|
||||
private String descriptif;
|
||||
|
||||
@NotEmpty
|
||||
private Date dateNaissance;
|
||||
|
||||
@NotBlank
|
||||
private Sexe sexe;
|
||||
|
||||
@Size(min=0, max=1)
|
||||
private double ratioTrouvee;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package fr.iut.sciencequest.sae.entities;
|
||||
|
||||
public interface IToProjection {
|
||||
public <T> T toProjection(Class<T> projectionType);
|
||||
<T> T toProjection(Class<T> projectionType);
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package fr.iut.sciencequest.sae.entities.joueur;
|
||||
|
||||
public interface IIdAndPseudoOnlyProjection {
|
||||
int getId();
|
||||
String getPseudo();
|
||||
}
|
@ -1,26 +1,31 @@
|
||||
package fr.iut.sciencequest.sae.entities;
|
||||
package fr.iut.sciencequest.sae.entities.joueur;
|
||||
|
||||
import fr.iut.sciencequest.sae.entities.BaseEntity;
|
||||
import fr.iut.sciencequest.sae.entities.Partie;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Inheritance ( strategy = InheritanceType.JOINED)
|
||||
@Entity
|
||||
@Table(name="joueur")
|
||||
public abstract class Joueur extends BaseEntity {
|
||||
@Id
|
||||
@NotNull
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
|
||||
@NotBlank
|
||||
@Column(unique = true)
|
||||
private String pseudo;
|
||||
//private Partie partie;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="idpartie")
|
||||
private Partie partie;
|
||||
}
|
@ -1,4 +1,25 @@
|
||||
package fr.iut.sciencequest.sae.services;
|
||||
|
||||
public class PartieService {
|
||||
import fr.iut.sciencequest.sae.entities.Partie;
|
||||
import fr.iut.sciencequest.sae.exceptions.notFound.PartieNotFoundException;
|
||||
import fr.iut.sciencequest.sae.repositories.PartieRepository;
|
||||
import fr.iut.sciencequest.sae.services.interfaces.IPartieService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class PartieService implements IPartieService {
|
||||
private final PartieRepository partieRepository;
|
||||
|
||||
public Partie findById(int id) {
|
||||
return this.partieRepository.findById(id).orElseThrow(() ->
|
||||
new PartieNotFoundException("Partie", id)
|
||||
);
|
||||
}
|
||||
public Partie save(Partie p) {
|
||||
return new Partie();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package fr.iut.sciencequest.sae.services.interfaces;
|
||||
|
||||
public class IPartieService {
|
||||
import fr.iut.sciencequest.sae.entities.Partie;
|
||||
|
||||
public interface IPartieService {
|
||||
Partie findById(int id);
|
||||
Partie save(Partie p);
|
||||
}
|
||||
|
Loading…
Reference in new issue