add list user and part of user page
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.Contact;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
@@ -25,4 +26,25 @@ public class ClubModel {
|
||||
String country;
|
||||
|
||||
String shieldURL;
|
||||
|
||||
//@Enumerated(EnumType.STRING)
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "club_contact_mapping",
|
||||
joinColumns = {@JoinColumn(name = "club_id", referencedColumnName = "id")})
|
||||
@MapKeyColumn(name = "contact_type")
|
||||
Map<Contact, String> contact;
|
||||
|
||||
String training_location;
|
||||
|
||||
String training_day_time;
|
||||
|
||||
String contact_intern;
|
||||
|
||||
String RNA;
|
||||
|
||||
String SIRET;
|
||||
|
||||
String no_affiliation;
|
||||
|
||||
boolean international;
|
||||
}
|
||||
|
||||
@@ -2,29 +2,31 @@ package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
|
||||
@Entity
|
||||
@Table(name = "comb")
|
||||
public class CombModel {
|
||||
@Table(name = "membre")
|
||||
public class MembreModel {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Long id;
|
||||
|
||||
String lname = "";
|
||||
String fname = "";
|
||||
String lname;
|
||||
String fname;
|
||||
|
||||
Categorie categorie;
|
||||
|
||||
@@ -34,7 +36,17 @@ public class CombModel {
|
||||
|
||||
Genre genre;
|
||||
|
||||
int licence = 0;
|
||||
int licence;
|
||||
|
||||
String country = "fr";
|
||||
String country;
|
||||
|
||||
Date birth_date;
|
||||
|
||||
String email;
|
||||
|
||||
RoleAsso role;
|
||||
|
||||
GradeArbitrage grade_arbitrage;
|
||||
|
||||
String url_photo;
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package fr.titionfire.ffsaf.data.repository;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CombModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CombRepository implements PanacheRepositoryBase<CombModel, Long> {
|
||||
public class CombRepository implements PanacheRepositoryBase<MembreModel, Long> {
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.utils.Contact;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class ClubEntity {
|
||||
@@ -13,12 +18,39 @@ public class ClubEntity {
|
||||
private String name;
|
||||
private String country;
|
||||
private String shieldURL;
|
||||
private Map<Contact, String> contact;
|
||||
private String training_location;
|
||||
private String training_day_time;
|
||||
private String contact_intern;
|
||||
private String RNA;
|
||||
private String SIRET;
|
||||
private String no_affiliation;
|
||||
private boolean international;
|
||||
|
||||
public static ClubEntity fromModel (ClubModel model) {
|
||||
return new ClubEntity(model.getId(), model.getName(), model.getCountry(), model.getShieldURL());
|
||||
if (model == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ClubEntity.builder()
|
||||
.id(model.getId())
|
||||
.name(model.getName())
|
||||
.country(model.getCountry())
|
||||
.shieldURL(model.getShieldURL())
|
||||
.contact(model.getContact())
|
||||
.training_location(model.getTraining_location())
|
||||
.training_day_time(model.getTraining_day_time())
|
||||
.contact_intern(model.getContact_intern())
|
||||
.RNA(model.getRNA())
|
||||
.SIRET(model.getSIRET())
|
||||
.no_affiliation(model.getNo_affiliation())
|
||||
.international(model.isInternational())
|
||||
.build();
|
||||
}
|
||||
|
||||
public ClubModel toModel () {
|
||||
return new ClubModel(this.id, this.name, this.country, this.shieldURL);
|
||||
return new ClubModel(this.id, this.name, this.country, this.shieldURL, this.contact, this.training_location,
|
||||
this.training_day_time, this.contact_intern, this.RNA, this.SIRET, this.no_affiliation,
|
||||
this.international);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CombModel;
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class CombEntity {
|
||||
private long id;
|
||||
private String lname = "";
|
||||
private String fname = "";
|
||||
private Categorie categorie;
|
||||
private ClubEntity club;
|
||||
private Genre genre;
|
||||
private int licence;
|
||||
private String country;
|
||||
|
||||
public static CombEntity fromModel(CombModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new CombEntity(model.getId(), model.getLname(), model.getFname(), model.getCategorie(),
|
||||
(model.getClub() == null) ? null : ClubEntity.fromModel(model.getClub()),
|
||||
model.getGenre(), model.getLicence(), model.getCountry());
|
||||
}
|
||||
|
||||
public static String getFullName(CombModel model) {
|
||||
return model.getFname() + " " + model.getLname();
|
||||
}
|
||||
public String getFullName() {
|
||||
return this.fname + " " + this.lname;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package fr.titionfire.ffsaf.domain.entity;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class MembreEntity {
|
||||
private long id;
|
||||
private String lname = "";
|
||||
private String fname = "";
|
||||
private Categorie categorie;
|
||||
private ClubEntity club;
|
||||
private Genre genre;
|
||||
private int licence;
|
||||
private String country;
|
||||
private Date birth_date;
|
||||
private String email;
|
||||
private RoleAsso role;
|
||||
private GradeArbitrage grade_arbitrage;
|
||||
private String url_photo;
|
||||
|
||||
|
||||
public static MembreEntity fromModel(MembreModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new MembreEntityBuilder()
|
||||
.id(model.getId())
|
||||
.lname(model.getLname())
|
||||
.fname(model.getFname())
|
||||
.categorie(model.getCategorie())
|
||||
.club(ClubEntity.fromModel(model.getClub()))
|
||||
.genre(model.getGenre())
|
||||
.licence(model.getLicence())
|
||||
.country(model.getCountry())
|
||||
.birth_date(model.getBirth_date())
|
||||
.email(model.getEmail())
|
||||
.role(model.getRole())
|
||||
.grade_arbitrage(model.getGrade_arbitrage())
|
||||
.url_photo(model.getUrl_photo())
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String getFullName(MembreModel model) {
|
||||
return model.getFname() + " " + model.getLname();
|
||||
}
|
||||
public String getFullName() {
|
||||
return this.fname + " " + this.lname;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,13 +2,16 @@ package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.data.repository.ClubRepository;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.vertx.VertxContextSupport;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
@@ -17,11 +20,16 @@ public class ClubService {
|
||||
@Inject
|
||||
ClubRepository repository;
|
||||
|
||||
public ClubModel findByIdOptionalClub (long id) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findById(id)));
|
||||
public SimpleClubModel findByIdOptionalClub(long id) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleClubModel::fromModel)));
|
||||
}
|
||||
|
||||
public Collection<ClubModel> findAllClub () throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findAll().list()));
|
||||
public Collection<SimpleClubModel> findAllClub() throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(
|
||||
() -> repository.findAll().list().map(clubModels -> clubModels.stream().map(SimpleClubModel::fromModel).toList())));
|
||||
}
|
||||
|
||||
public Uni<List<ClubModel>> getAll() {
|
||||
return repository.listAll();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CombModel;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.vertx.VertxContextSupport;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
public class CombService {
|
||||
|
||||
@Inject
|
||||
CombRepository repository;
|
||||
|
||||
public CombModel find(int licence, String np) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||
repository.find("licence = ?1 AND (lname = ?2 OR fname = ?2)", licence, np).firstResult()));
|
||||
}
|
||||
|
||||
public CombModel findByIdOptionalComb (long id) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findById(id)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.repository.ClubRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCombModel;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
import fr.titionfire.ffsaf.utils.Pair;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.panache.common.Sort;
|
||||
import io.quarkus.vertx.VertxContextSupport;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
public class MembreService {
|
||||
|
||||
@Inject
|
||||
CombRepository repository;
|
||||
@Inject
|
||||
ClubRepository clubRepository;
|
||||
|
||||
public SimpleCombModel find(int licence, String np) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||
repository.find("licence = ?1 AND (lname = ?2 OR fname = ?2)", licence, np).firstResult().map(SimpleCombModel::fromModel)));
|
||||
}
|
||||
|
||||
public SimpleCombModel findByIdOptionalComb(long id) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleCombModel::fromModel)));
|
||||
}
|
||||
|
||||
public Uni<List<MembreModel>> getAll() {
|
||||
return repository.listAll(Sort.ascending("fname", "lname"));
|
||||
}
|
||||
|
||||
public Uni<MembreModel> getById(long id) {
|
||||
return repository.findById(id);
|
||||
}
|
||||
|
||||
public Uni<String> update(long id, FullMemberForm membre) {
|
||||
return repository.findById(id)
|
||||
.chain(membreModel -> clubRepository.findById(membre.getClub()).map(club -> new Pair<>(membreModel, club)))
|
||||
.onItem().transformToUni(pair -> {
|
||||
MembreModel m = pair.getKey();
|
||||
m.setFname(membre.getFname());
|
||||
m.setLname(membre.getLname());
|
||||
m.setClub(pair.getValue());
|
||||
m.setCountry(membre.getCountry());
|
||||
m.setBirth_date(membre.getBirth_date());
|
||||
m.setGenre(membre.getGenre());
|
||||
m.setCategorie(membre.getCategorie());
|
||||
m.setRole(membre.getRole());
|
||||
m.setGrade_arbitrage(membre.getGrade_arbitrage());
|
||||
m.setEmail(membre.getEmail());
|
||||
return Panache.withTransaction(() -> repository.persist(m));
|
||||
}).map(__ -> "OK");
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package fr.titionfire.ffsaf.net2;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import fr.titionfire.ffsaf.domain.service.ClubService;
|
||||
import fr.titionfire.ffsaf.domain.service.CombService;
|
||||
import fr.titionfire.ffsaf.domain.service.MembreService;
|
||||
import fr.titionfire.ffsaf.net2.packet.IAction;
|
||||
import fr.titionfire.ffsaf.net2.packet.RegisterAction;
|
||||
import fr.titionfire.ffsaf.utils.Pair;
|
||||
@@ -54,7 +54,7 @@ public class ServerCustom extends Thread {
|
||||
protected Scheduler quartz;
|
||||
|
||||
@Inject
|
||||
public CombService combService;
|
||||
public MembreService membreService;
|
||||
|
||||
@Inject
|
||||
public ClubService clubService;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package fr.titionfire.ffsaf.net2.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleClubModel {
|
||||
Long id;
|
||||
String name;
|
||||
String country;
|
||||
String shieldURL;
|
||||
|
||||
public static SimpleClubModel fromModel(ClubModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleClubModel(model.getId(), model.getName(), model.getCountry(), model.getShieldURL());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package fr.titionfire.ffsaf.net2.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleCombModel {
|
||||
Long id;
|
||||
String lname = "";
|
||||
String fname = "";
|
||||
Categorie categorie;
|
||||
SimpleClubModel club;
|
||||
Genre genre;
|
||||
int licence = 0;
|
||||
String country = "fr";
|
||||
|
||||
public static SimpleCombModel fromModel(MembreModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleCombModel(model.getId(), model.getLname(), model.getFname(), model.getCategorie(),
|
||||
(model.getClub() == null) ? null : SimpleClubModel.fromModel(model.getClub()),
|
||||
model.getGenre(), model.getLicence(), model.getCountry());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.titionfire.ffsaf.net2.packet;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.ClubModel;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -12,7 +12,7 @@ public class RClub {
|
||||
|
||||
final CIA<Long> findByIdOptionalClub = new CIA<>(Long.class, (client_Thread, message) -> {
|
||||
try {
|
||||
ClubModel clubModel = ServerCustom.getInstance().clubService.findByIdOptionalClub(message.data());
|
||||
SimpleClubModel clubModel = ServerCustom.getInstance().clubService.findByIdOptionalClub(message.data());
|
||||
client_Thread.sendRepTo(clubModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
@@ -22,7 +22,7 @@ public class RClub {
|
||||
|
||||
final IAction findAllClub = (client_Thread, message) -> {
|
||||
try {
|
||||
Collection<ClubModel> clubModels = ServerCustom.getInstance().clubService.findAllClub();
|
||||
Collection<SimpleClubModel> clubModels = ServerCustom.getInstance().clubService.findAllClub();
|
||||
client_Thread.sendRepTo(clubModels, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.titionfire.ffsaf.net2.packet;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CombModel;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCombModel;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class RComb {
|
||||
|
||||
final IAction findComb = (client_Thread, message) -> {
|
||||
try {
|
||||
CombModel combModel = ServerCustom.getInstance().combService.find(message.data().get("licence").asInt(), message.data().get("np").asText());
|
||||
SimpleCombModel combModel = ServerCustom.getInstance().membreService.find(message.data().get("licence").asInt(), message.data().get("np").asText());
|
||||
client_Thread.sendRepTo(combModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
@@ -23,7 +23,7 @@ public class RComb {
|
||||
|
||||
final CIA<Long> findByIdOptionalComb = new CIA<>(Long.class, (client_Thread, message) -> {
|
||||
try {
|
||||
CombModel combModel = ServerCustom.getInstance().combService.findByIdOptionalComb(message.data());
|
||||
SimpleCombModel combModel = ServerCustom.getInstance().membreService.findByIdOptionalComb(message.data());
|
||||
client_Thread.sendRepTo(combModel, message);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
|
||||
28
src/main/java/fr/titionfire/ffsaf/rest/ClubEndpoints.java
Normal file
28
src/main/java/fr/titionfire/ffsaf/rest/ClubEndpoints.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.ClubService;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Path("/club")
|
||||
public class ClubEndpoints {
|
||||
|
||||
@Inject
|
||||
ClubService clubService;
|
||||
|
||||
@GET
|
||||
@Path("/no_detail")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleClubModel>> getAll() {
|
||||
return clubService.getAll().map(clubModels -> clubModels.stream().map(SimpleClubModel::fromModel).toList());
|
||||
}
|
||||
}
|
||||
124
src/main/java/fr/titionfire/ffsaf/rest/CombEndpoints.java
Normal file
124
src/main/java/fr/titionfire/ffsaf/rest/CombEndpoints.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.MembreService;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleMembre;
|
||||
import fr.titionfire.ffsaf.rest.from.FullMemberForm;
|
||||
import fr.titionfire.ffsaf.utils.Pair;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.tika.mime.MimeTypeException;
|
||||
import org.apache.tika.mime.MimeTypes;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URI;
|
||||
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;
|
||||
|
||||
@Path("/member")
|
||||
public class CombEndpoints {
|
||||
|
||||
@Inject
|
||||
MembreService membreService;
|
||||
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
@GET
|
||||
@Path("/all")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleMembre>> getAll() {
|
||||
return membreService.getAll().map(membreModels -> membreModels.stream().map(SimpleMembre::fromModel).toList());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<SimpleMembre> getById(@PathParam("id") long id) {
|
||||
return membreService.getById(id).map(SimpleMembre::fromModel);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{id}")
|
||||
@RolesAllowed("federation_admin")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
public Uni<String> setAdminMembre(@PathParam("id") long id, FullMemberForm input) {
|
||||
Future<String> future = CompletableFuture.supplyAsync(() -> {
|
||||
try (InputStream is = new BufferedInputStream(new ByteArrayInputStream(input.getPhoto_data()))) {
|
||||
String mimeType = URLConnection.guessContentTypeFromStream(is);
|
||||
String extension = MimeTypes.getDefaultMimeTypes().forName(mimeType).getExtension();
|
||||
FileUtils.writeByteArrayToFile(new File(media, "ppMembre/" + input.getId() + extension), input.getPhoto_data());
|
||||
return "OK";
|
||||
} catch (IOException | MimeTypeException e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
});
|
||||
|
||||
if (input.getPhoto_data().length > 0) {
|
||||
return membreService.update(id, input)
|
||||
.invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to update data: " + out);
|
||||
}))
|
||||
.chain(() -> Uni.createFrom().future(future))
|
||||
.invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to get MimeType " + out);
|
||||
}));
|
||||
} else {
|
||||
return membreService.update(id, input)
|
||||
.invoke(Unchecked.consumer(out -> {
|
||||
if (!out.equals("OK")) throw new InternalError("Fail to update data: " + out);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/photo")
|
||||
public Uni<Response> getPhoto(@PathParam("id") long id) throws URISyntaxException {
|
||||
Future<Pair<File, byte[]>> future = CompletableFuture.supplyAsync(() -> {
|
||||
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));
|
||||
File[] files = new File(media, "ppMembre").listFiles(filter);
|
||||
if (files != null && files.length > 0) {
|
||||
File file = files[0];
|
||||
try {
|
||||
byte[] data = Files.readAllBytes(file.toPath());
|
||||
return new Pair<>(file, data);
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
URI uri = new URI("https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-chat/ava2.webp");
|
||||
|
||||
return Uni.createFrom().future(future)
|
||||
.map(filePair -> {
|
||||
if (filePair == null)
|
||||
return Response.temporaryRedirect(uri).build();
|
||||
|
||||
String mimeType = URLConnection.guessContentTypeFromName(filePair.getKey().getName());
|
||||
|
||||
Response.ResponseBuilder resp = Response.ok(filePair.getValue());
|
||||
resp.type(MediaType.APPLICATION_OCTET_STREAM);
|
||||
resp.header(HttpHeaders.CONTENT_LENGTH, filePair.getValue().length);
|
||||
resp.header(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
resp.header(HttpHeaders.CONTENT_DISPOSITION, "inline; ");
|
||||
|
||||
return resp.build();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleMembre {
|
||||
private long id;
|
||||
private String lname = "";
|
||||
private String fname = "";
|
||||
private Categorie categorie;
|
||||
private SimpleClubModel club;
|
||||
private Genre genre;
|
||||
private int licence;
|
||||
private String country;
|
||||
private Date birth_date;
|
||||
private String email;
|
||||
private RoleAsso role;
|
||||
private GradeArbitrage grade_arbitrage;
|
||||
private String url_photo;
|
||||
|
||||
public static SimpleMembre fromModel(MembreModel model) {
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new SimpleMembreBuilder()
|
||||
.id(model.getId())
|
||||
.lname(model.getLname())
|
||||
.fname(model.getFname())
|
||||
.categorie(model.getCategorie())
|
||||
.club(SimpleClubModel.fromModel(model.getClub()))
|
||||
.genre(model.getGenre())
|
||||
.licence(model.getLicence())
|
||||
.country(model.getCountry())
|
||||
.birth_date(model.getBirth_date())
|
||||
.email(model.getEmail())
|
||||
.role(model.getRole())
|
||||
.grade_arbitrage(model.getGrade_arbitrage())
|
||||
.url_photo(model.getUrl_photo())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package fr.titionfire.ffsaf.rest.from;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.Categorie;
|
||||
import fr.titionfire.ffsaf.utils.Genre;
|
||||
import fr.titionfire.ffsaf.utils.GradeArbitrage;
|
||||
import fr.titionfire.ffsaf.utils.RoleAsso;
|
||||
import jakarta.ws.rs.FormParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import lombok.Getter;
|
||||
import org.jboss.resteasy.reactive.PartType;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Getter
|
||||
public class FullMemberForm {
|
||||
@FormParam("id")
|
||||
private String id = null;
|
||||
|
||||
@FormParam("lname")
|
||||
private String lname = null;
|
||||
|
||||
@FormParam("fname")
|
||||
private String fname = null;
|
||||
|
||||
@FormParam("categorie")
|
||||
private Categorie categorie = null;
|
||||
|
||||
@FormParam("club")
|
||||
private Long club = null;
|
||||
|
||||
@FormParam("genre")
|
||||
private Genre genre;
|
||||
|
||||
@FormParam("licence")
|
||||
private int licence;
|
||||
|
||||
@FormParam("country")
|
||||
private String country;
|
||||
|
||||
@FormParam("birth_date")
|
||||
private Date birth_date;
|
||||
|
||||
@FormParam("email")
|
||||
private String email;
|
||||
|
||||
@FormParam("role")
|
||||
private RoleAsso role;
|
||||
|
||||
@FormParam("grade_arbitrage")
|
||||
private GradeArbitrage grade_arbitrage;
|
||||
|
||||
@FormParam("photo_data")
|
||||
@PartType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
private byte[] photo_data = new byte[0];
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FullMemberForm{" +
|
||||
"id='" + id + '\'' +
|
||||
", lname='" + lname + '\'' +
|
||||
", fname='" + fname + '\'' +
|
||||
", categorie=" + categorie +
|
||||
", club=" + club +
|
||||
", genre=" + genre +
|
||||
", licence=" + licence +
|
||||
", country='" + country + '\'' +
|
||||
", birth_date=" + birth_date +
|
||||
", email='" + email + '\'' +
|
||||
", role=" + role +
|
||||
", grade_arbitrage=" + grade_arbitrage +
|
||||
", url_photo=" + photo_data.length +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
20
src/main/java/fr/titionfire/ffsaf/utils/Contact.java
Normal file
20
src/main/java/fr/titionfire/ffsaf/utils/Contact.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
public enum Contact {
|
||||
COURRIEL("Courriel"),
|
||||
TELEPHONE("Téléphone"),
|
||||
SITE("Site web"),
|
||||
FACEBOOK("Facebook"),
|
||||
INSTAGRAM("Instagram");
|
||||
|
||||
public final String name;
|
||||
|
||||
Contact(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
18
src/main/java/fr/titionfire/ffsaf/utils/GradeArbitrage.java
Normal file
18
src/main/java/fr/titionfire/ffsaf/utils/GradeArbitrage.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
public enum GradeArbitrage {
|
||||
NA("N/A"),
|
||||
ASSESSEUR("Assesseur"),
|
||||
ARBITRE("Arbitre");
|
||||
|
||||
public final String name;
|
||||
|
||||
GradeArbitrage(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
20
src/main/java/fr/titionfire/ffsaf/utils/RoleAsso.java
Normal file
20
src/main/java/fr/titionfire/ffsaf/utils/RoleAsso.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
|
||||
public enum RoleAsso {
|
||||
MEMBRE("Membre"),
|
||||
PRESIDENT("Président"),
|
||||
TRESORIER("Trésorier"),
|
||||
SECRETAIRE("Secrétaire");
|
||||
|
||||
public final String name;
|
||||
|
||||
RoleAsso(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user