forked from tom.biard/ScienceQuest
parent
0b9c48be47
commit
8347cd163e
@ -0,0 +1,42 @@
|
|||||||
|
package fr.iut.sciencequest.sae.assemblers;
|
||||||
|
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.sae.controllers.ScientifiqueController;
|
||||||
|
import org.springframework.hateoas.CollectionModel;
|
||||||
|
import fr.iut.sciencequest.sae.dto.indice.IndiceSimpleWithScientifiquesIdDTO;
|
||||||
|
import fr.iut.sciencequest.sae.entities.Indice;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||||
|
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class IndiceModelAssembler extends RepresentationModelAssemblerSupport<Indice, IndiceSimpleWithScientifiquesIdDTO> {
|
||||||
|
public IndiceModelAssembler() {
|
||||||
|
super(Indice.class, IndiceSimpleWithScientifiquesIdDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public IndiceSimpleWithScientifiquesIdDTO toModel(@Nullable Indice entity) {
|
||||||
|
ModelMapper mapper = new ModelMapper();
|
||||||
|
return mapper.map(entity, IndiceSimpleWithScientifiquesIdDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public CollectionModel<IndiceSimpleWithScientifiquesIdDTO> toCollectionModel(@Nullable Iterable<? extends Indice> entities) {
|
||||||
|
assert entities != null;
|
||||||
|
CollectionModel<IndiceSimpleWithScientifiquesIdDTO> collectionModel = super.toCollectionModel(entities);
|
||||||
|
// Le lien n'est pas ajouté automatiquement si l'on utilise pas la pagination /!\
|
||||||
|
if(collectionModel.iterator().hasNext())
|
||||||
|
collectionModel.add(linkTo(methodOn(ScientifiqueController.class).getScientistHints(collectionModel.iterator().next().getScientifique().getId())).withSelfRel());
|
||||||
|
|
||||||
|
return collectionModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package fr.iut.sciencequest.sae.assemblers;
|
||||||
|
|
||||||
|
import fr.iut.sciencequest.sae.dto.thematique.ThematiqueDTO;
|
||||||
|
import fr.iut.sciencequest.sae.entities.Thematique;
|
||||||
|
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 ThematiqueModelAssembler extends RepresentationModelAssemblerSupport<Thematique, ThematiqueDTO> {
|
||||||
|
public ThematiqueModelAssembler() {
|
||||||
|
super(Thematique.class, ThematiqueDTO.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public ThematiqueDTO toModel(@Nullable Thematique entity) {
|
||||||
|
ModelMapper mapper = new ModelMapper();
|
||||||
|
return mapper.map(entity, ThematiqueDTO.class);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.difficulte;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.*;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class DifficulteSimpleDTO extends RepresentationModel<DifficulteSimpleDTO> {
|
||||||
|
@NotNull
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String libelle;
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.indice;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.*;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class IndiceLibelleOnlyDTO extends RepresentationModel<IndiceLibelleOnlyDTO> {
|
||||||
|
@NotBlank
|
||||||
|
private String libelle;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.indice;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import fr.iut.sciencequest.sae.dto.scientifique.ScientifiqueIdOnlyDTO;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
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 IndiceSimpleWithScientifiquesIdDTO extends RepresentationModel<IndiceSimpleWithScientifiquesIdDTO> {
|
||||||
|
@NotNull
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String libelle;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private ScientifiqueIdOnlyDTO scientifique;
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.indice;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import fr.iut.sciencequest.sae.dto.scientifique.ScientifiqueIdOnlyDTO;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.*;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
public class IndiceWithoutIdAndScientifiqueIdOnlyForPatchDTO extends RepresentationModel<IndiceWithoutIdAndScientifiqueIdOnlyForPatchDTO> {
|
||||||
|
|
||||||
|
private String libelle;
|
||||||
|
|
||||||
|
@Valid
|
||||||
|
private ScientifiqueIdOnlyDTO scientifique;
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.scientifique;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.*;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ScientifiqueIdOnlyDTO extends RepresentationModel<ScientifiqueIdOnlyDTO> {
|
||||||
|
@NotNull
|
||||||
|
private Integer id;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.thematique;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.*;
|
||||||
|
import org.springframework.hateoas.RepresentationModel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
public class ThematiqueSimpleDTO extends RepresentationModel<ThematiqueSimpleDTO> {
|
||||||
|
@NotNull
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String libelle;
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package fr.iut.sciencequest.sae.dto.utilisateur;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
import fr.iut.sciencequest.sae.dto.partie.PartieDTO;
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
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 UtilisateurWithPasswordDTO extends RepresentationModel<UtilisateurWithPasswordDTO> {
|
||||||
|
@NotNull
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Email
|
||||||
|
@NotNull
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String motDePasse;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String pseudo;
|
||||||
|
|
||||||
|
private PartieDTO partie;
|
||||||
|
}
|
@ -1,12 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities;
|
|
||||||
|
|
||||||
import org.springframework.data.projection.ProjectionFactory;
|
|
||||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
|
||||||
|
|
||||||
public abstract class BaseEntity implements IToProjection {
|
|
||||||
public <T> T toProjection(Class<T> projectionType){
|
|
||||||
ProjectionFactory pf = new SpelAwareProxyProjectionFactory();
|
|
||||||
return pf.createProjection(projectionType, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +1,37 @@
|
|||||||
package fr.iut.sciencequest.sae.entities;
|
package fr.iut.sciencequest.sae.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.modelmapper.internal.bytebuddy.implementation.bind.annotation.Super;
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="difficulte")
|
@Table(name="difficulte")
|
||||||
public class Difficulte extends BaseEntity {
|
@JsonIdentityInfo(
|
||||||
|
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
property = "id")
|
||||||
|
public class Difficulte {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(unique = true)
|
@Column(unique = true)
|
||||||
private String libelle;
|
private String libelle;
|
||||||
|
|
||||||
|
@JsonManagedReference
|
||||||
|
@OneToMany(mappedBy = "difficulte")
|
||||||
|
@Fetch(FetchMode.JOIN)
|
||||||
|
private List<Scientifique> scientifiques;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities;
|
|
||||||
|
|
||||||
public interface IToProjection {
|
|
||||||
<T> T toProjection(Class<T> projectionType);
|
|
||||||
}
|
|
@ -0,0 +1,26 @@
|
|||||||
|
package fr.iut.sciencequest.sae.entities;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name="indice")
|
||||||
|
public class Indice {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String libelle;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name="idscientifique", nullable = false)
|
||||||
|
private Scientifique scientifique;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
|||||||
|
package fr.iut.sciencequest.sae.entities;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
//@Relation(collectionRelation = "scientifiques", itemRelation = "scientifique")
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "scientifique")
|
||||||
|
@JsonIdentityInfo(
|
||||||
|
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
property = "id")
|
||||||
|
public class Scientifique {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@JsonBackReference
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name="iddifficulte", nullable = false)
|
||||||
|
private Difficulte difficulte;
|
||||||
|
|
||||||
|
@JsonBackReference
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name="idthematique", nullable = false)
|
||||||
|
private Thematique thematique;
|
||||||
|
|
||||||
|
@Column(name = "photo")
|
||||||
|
private String pathToPhoto;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String nom;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String prenom;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String descriptif;
|
||||||
|
|
||||||
|
@Column(name = "datenaissance", nullable = false)
|
||||||
|
private Date dateNaissance;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Sexe sexe;
|
||||||
|
|
||||||
|
@Column(name = "ratiotrouvee")
|
||||||
|
private BigDecimal ratioTrouve = BigDecimal.ZERO;
|
||||||
|
}
|
@ -1,25 +1,38 @@
|
|||||||
package fr.iut.sciencequest.sae.entities;
|
package fr.iut.sciencequest.sae.entities;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name="thematique")
|
@Table(name="thematique")
|
||||||
public class Thematique extends BaseEntity {
|
@JsonIdentityInfo(
|
||||||
|
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
property = "id")
|
||||||
|
public class Thematique {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(unique = true)
|
@Column(unique = true)
|
||||||
private String libelle;
|
private String libelle;
|
||||||
|
|
||||||
|
@JsonManagedReference
|
||||||
|
@OneToMany(mappedBy = "thematique")
|
||||||
|
@Fetch(FetchMode.JOIN)
|
||||||
|
private List<Scientifique> scientifiques;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities.indice;
|
|
||||||
|
|
||||||
import fr.iut.sciencequest.sae.entities.scientifique.IScientifiqueIdOnlyProjection;
|
|
||||||
|
|
||||||
public interface IIndiceidAndLibelleAndScientifiqueIdOnlyProjection {
|
|
||||||
int getId();
|
|
||||||
String getLibelle();
|
|
||||||
|
|
||||||
IScientifiqueIdOnlyProjection getScientifique();
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities.indice;
|
|
||||||
|
|
||||||
public interface IValidateOnlyLibelle {}
|
|
@ -1,37 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities.indice;
|
|
||||||
|
|
||||||
import fr.iut.sciencequest.sae.entities.BaseEntity;
|
|
||||||
import fr.iut.sciencequest.sae.entities.scientifique.Scientifique;
|
|
||||||
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;
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Entity
|
|
||||||
@Table(name="indice")
|
|
||||||
public class Indice extends BaseEntity {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
@NotBlank(groups = {IValidateOnlyLibelle.class})
|
|
||||||
private String libelle;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@NotNull
|
|
||||||
@JoinColumn(name="idscientifique", nullable = false)
|
|
||||||
private Scientifique scientifique;
|
|
||||||
|
|
||||||
public Indice(int id, String libelle) { // Used for projection
|
|
||||||
this.id = id;
|
|
||||||
this.libelle = libelle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities.joueur;
|
|
||||||
|
|
||||||
public interface IIdAndPseudoOnlyProjection {
|
|
||||||
int getId();
|
|
||||||
String getPseudo();
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities.scientifique;
|
|
||||||
|
|
||||||
public interface IScientifiqueIdOnlyProjection {
|
|
||||||
int getId();
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
package fr.iut.sciencequest.sae.entities.scientifique;
|
|
||||||
|
|
||||||
import fr.iut.sciencequest.sae.entities.BaseEntity;
|
|
||||||
import fr.iut.sciencequest.sae.entities.Difficulte;
|
|
||||||
import fr.iut.sciencequest.sae.entities.Sexe;
|
|
||||||
import fr.iut.sciencequest.sae.entities.Thematique;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.hibernate.validator.constraints.URL;
|
|
||||||
import org.springframework.hateoas.server.core.Relation;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Relation(collectionRelation = "scientifiques", itemRelation = "scientifique")
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = false)
|
|
||||||
@Entity
|
|
||||||
@Table(name = "scientifique")
|
|
||||||
public class Scientifique extends BaseEntity {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name="iddifficulte")
|
|
||||||
private Difficulte difficulte;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name="idthematique")
|
|
||||||
private Thematique thematique;
|
|
||||||
|
|
||||||
@Column(name = "photo")
|
|
||||||
private String pathToPhoto;
|
|
||||||
|
|
||||||
private String nom;
|
|
||||||
|
|
||||||
private String prenom;
|
|
||||||
|
|
||||||
private String descriptif;
|
|
||||||
|
|
||||||
@Column(name = "datenaissance")
|
|
||||||
private Date dateNaissance;
|
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private Sexe sexe;
|
|
||||||
|
|
||||||
@Column(name = "ratiotrouvee")
|
|
||||||
private BigDecimal ratioTrouve = BigDecimal.ZERO;
|
|
||||||
}
|
|
@ -0,0 +1,34 @@
|
|||||||
|
package fr.iut.sciencequest.sae.exceptions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.FieldError;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
import org.springframework.web.context.request.WebRequest;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
public class ValidationHandler extends ResponseEntityExceptionHandler {
|
||||||
|
|
||||||
|
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
protected ResponseEntity<Object> hand(MethodArgumentNotValidException ex) {
|
||||||
|
|
||||||
|
Map<String, String> errors = new HashMap<>();
|
||||||
|
ex.getBindingResult().getAllErrors().forEach((error) ->{
|
||||||
|
|
||||||
|
String fieldName = ((FieldError) error).getField();
|
||||||
|
String message = error.getDefaultMessage();
|
||||||
|
errors.put(fieldName, message);
|
||||||
|
});
|
||||||
|
return new ResponseEntity<Object>(errors, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package fr.iut.sciencequest.sae.exceptions.notFound;
|
||||||
|
|
||||||
|
public class DifficulteNotFoundException extends EntityNotFoundException{
|
||||||
|
public DifficulteNotFoundException(int id) {
|
||||||
|
super("Difficulté", id);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,19 @@
|
|||||||
package fr.iut.sciencequest.sae.repositories;
|
package fr.iut.sciencequest.sae.repositories;
|
||||||
|
|
||||||
import fr.iut.sciencequest.sae.entities.scientifique.Scientifique;
|
import fr.iut.sciencequest.sae.entities.Difficulte;
|
||||||
|
import fr.iut.sciencequest.sae.entities.Scientifique;
|
||||||
|
import fr.iut.sciencequest.sae.entities.Thematique;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ScientifiqueRepository extends PagingAndSortingRepository<Scientifique, Integer>, CrudRepository<Scientifique, Integer> {
|
public interface ScientifiqueRepository extends JpaRepository<Scientifique, Integer> {
|
||||||
|
Page<Scientifique> findAllByDifficulteEquals(Difficulte difficulte, Pageable pageable);
|
||||||
|
Page<Scientifique> findAllByThematiqueEquals(Thematique thematique, Pageable pageable);
|
||||||
|
Page<Scientifique> findAllByThematiqueEqualsAndDifficulteEquals(Thematique thematique, Difficulte difficulte, Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package fr.iut.sciencequest.sae.services.interfaces;
|
package fr.iut.sciencequest.sae.services.interfaces;
|
||||||
|
|
||||||
import fr.iut.sciencequest.sae.entities.indice.IIndiceidAndLibelleAndScientifiqueIdOnlyProjection;
|
import fr.iut.sciencequest.sae.entities.Indice;
|
||||||
import fr.iut.sciencequest.sae.entities.indice.Indice;
|
|
||||||
|
|
||||||
public interface IIndiceService {
|
public interface IIndiceService {
|
||||||
Iterable<IIndiceidAndLibelleAndScientifiqueIdOnlyProjection> findByScientifiqueId(int id);
|
Iterable<Indice> findByScientifiqueId(int id);
|
||||||
Indice update(Indice indice);
|
Indice update(Indice indice);
|
||||||
Indice create(Indice indice);
|
Indice create(Indice indice);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue