feat: mePage
This commit is contained in:
@@ -8,6 +8,8 @@ import fr.titionfire.ffsaf.data.repository.LicenceRepository;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCombModel;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqComb;
|
||||
import fr.titionfire.ffsaf.rest.data.MeData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleLicence;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
import fr.titionfire.ffsaf.rest.from.ClubMemberForm;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
@@ -27,6 +29,7 @@ import jakarta.ws.rs.BadRequestException;
|
||||
import jakarta.ws.rs.ForbiddenException;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -265,4 +268,14 @@ public class MembreService {
|
||||
StringSimilarity.similarity(m.getLname(), lname) <= 3)
|
||||
.map(SimpleMembre::fromModel).toList());
|
||||
}
|
||||
|
||||
public Uni<MeData> getMembre(String subject) {
|
||||
MeData meData = new MeData();
|
||||
return repository.find("userId = ?1", subject).firstResult()
|
||||
.invoke(meData::setMembre)
|
||||
.chain(membreModel -> Mutiny.fetch(membreModel.getLicences()))
|
||||
.map(licences -> licences.stream().map(SimpleLicence::fromModel).toList())
|
||||
.invoke(meData::setLicences)
|
||||
.map(__ -> meData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.domain.service.MembreService;
|
||||
import fr.titionfire.ffsaf.rest.data.MeData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
import fr.titionfire.ffsaf.rest.from.ClubMemberForm;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
@@ -18,17 +19,11 @@ import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jodd.net.MimeTypes;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Authenticated
|
||||
@@ -198,6 +193,14 @@ public class CombEndpoints {
|
||||
return membreService.delete(id, idToken);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("me")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<MeData> getMe() {
|
||||
return membreService.getMembre(idToken.getSubject());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/photo")
|
||||
@RolesAllowed({"federation_admin", "club_president", "club_secretaire", "club_respo_intra"})
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
@Path("api/countries")
|
||||
public class CountriesEndpoints {
|
||||
|
||||
@GET
|
||||
@Path("/{lang}/{code}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<HashMap<String, String>> getCountries(@PathParam("lang") String lang, @PathParam("code") String code) {
|
||||
Locale locale = new Locale(lang, code);
|
||||
return Uni.createFrom().item(new HashMap<String, String>())
|
||||
.invoke(map -> {
|
||||
String[] locales = Locale.getISOCountries();
|
||||
for (String countryCode : locales) {
|
||||
if (countryCode.equals("AN"))
|
||||
continue;
|
||||
Locale obj = new Locale("", countryCode);
|
||||
map.put(countryCode, obj.getDisplayName(locale));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
45
src/main/java/fr/titionfire/ffsaf/rest/data/MeData.java
Normal file
45
src/main/java/fr/titionfire/ffsaf/rest/data/MeData.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class MeData {
|
||||
private long id;
|
||||
private String lname = "";
|
||||
private String fname = "";
|
||||
private String categorie;
|
||||
private String club;
|
||||
private String genre;
|
||||
private int licence;
|
||||
private String country;
|
||||
private Date birth_date;
|
||||
private String email;
|
||||
private String role;
|
||||
private String grade_arbitrage;
|
||||
private List<SimpleLicence> licences;
|
||||
|
||||
public void setMembre(MembreModel membreModel) {
|
||||
this.id = membreModel.getId();
|
||||
this.lname = membreModel.getLname();
|
||||
this.fname = membreModel.getFname();
|
||||
this.categorie = membreModel.getCategorie().getName();
|
||||
this.club = membreModel.getClub().getName();
|
||||
this.genre = membreModel.getGenre().str;
|
||||
this.licence = membreModel.getLicence();
|
||||
this.country = membreModel.getCountry();
|
||||
this.birth_date = membreModel.getBirth_date();
|
||||
this.email = membreModel.getEmail();
|
||||
this.role = membreModel.getRole().str;
|
||||
this.grade_arbitrage = membreModel.getGrade_arbitrage().str;
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,20 @@ public enum Categorie {
|
||||
case VETERAN2 -> BUNDLE.getString("Cat.VETERAN2");
|
||||
};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return switch (this){
|
||||
case SUPER_MINI -> "Super Mini";
|
||||
case MINI_POUSSIN -> "Mini Poussin";
|
||||
case POUSSIN -> "Poussin";
|
||||
case BENJAMIN -> "Benjamin";
|
||||
case MINIME -> "Minime";
|
||||
case CADET -> "Cadet";
|
||||
case JUNIOR -> "Junior";
|
||||
case SENIOR1 -> "Senior 1";
|
||||
case SENIOR2 -> "Senior 2";
|
||||
case VETERAN1 -> "Vétéran 1";
|
||||
case VETERAN2 -> "Vétéran 2";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
public enum Genre {
|
||||
H, F, NA
|
||||
H("Homme"),
|
||||
F("Femme"),
|
||||
NA("Non définie");
|
||||
|
||||
public final String str;
|
||||
|
||||
Genre(String name) {
|
||||
this.str = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ public enum GradeArbitrage {
|
||||
ASSESSEUR("Assesseur"),
|
||||
ARBITRE("Arbitre");
|
||||
|
||||
public final String name;
|
||||
public final String str;
|
||||
|
||||
GradeArbitrage(String name) {
|
||||
this.name = name;
|
||||
this.str = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,16 @@ public enum RoleAsso {
|
||||
VTRESORIER("Vise-Trésorier", 2),
|
||||
MEMBREBUREAU("Membre bureau", 1);
|
||||
|
||||
public final String name;
|
||||
public final String str;
|
||||
public final int level;
|
||||
|
||||
RoleAsso(String name, int level) {
|
||||
this.name = name;
|
||||
this.str = name;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user