feat: club end main

This commit is contained in:
2024-07-14 13:24:02 +02:00
parent e1a8c90f3e
commit 6a21bd4735
12 changed files with 364 additions and 249 deletions

View File

@@ -28,8 +28,6 @@ public class ClubModel {
String country;
String shieldURL;
//@Enumerated(EnumType.STRING)
@ElementCollection
@CollectionTable(name = "club_contact_mapping",
@@ -37,15 +35,19 @@ public class ClubModel {
@MapKeyColumn(name = "contact_type")
Map<Contact, String> contact;
@Lob
@Column(length=4096)
String training_location;
@Lob
@Column(length=4096)
String training_day_time;
String contact_intern;
String RNA;
String SIRET;
Long SIRET;
String no_affiliation;

View File

@@ -18,13 +18,12 @@ public class ClubEntity {
private String name;
private String clubId;
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 Long SIRET;
private String no_affiliation;
private boolean international;
@@ -38,7 +37,6 @@ public class ClubEntity {
.name(model.getName())
.clubId(model.getClubId())
.country(model.getCountry())
.shieldURL(model.getShieldURL())
.contact(model.getContact())
.training_location(model.getTraining_location())
.training_day_time(model.getTraining_day_time())

View File

@@ -1,9 +1,14 @@
package fr.titionfire.ffsaf.domain.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import fr.titionfire.ffsaf.data.model.ClubModel;
import fr.titionfire.ffsaf.data.repository.ClubRepository;
import fr.titionfire.ffsaf.net2.ServerCustom;
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
import fr.titionfire.ffsaf.net2.request.SReqClub;
import fr.titionfire.ffsaf.rest.from.FullClubForm;
import fr.titionfire.ffsaf.utils.Contact;
import fr.titionfire.ffsaf.utils.PageResult;
import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
@@ -19,8 +24,11 @@ import jakarta.ws.rs.BadRequestException;
import org.hibernate.reactive.mutiny.Mutiny;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
@WithSession
@ApplicationScoped
public class ClubService {
@@ -28,13 +36,18 @@ public class ClubService {
@Inject
ClubRepository repository;
@Inject
ServerCustom serverCustom;
public SimpleClubModel findByIdOptionalClub(long id) throws Throwable {
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleClubModel::fromModel)));
return VertxContextSupport.subscribeAndAwait(
() -> Panache.withTransaction(() -> repository.findById(id).map(SimpleClubModel::fromModel)));
}
public Collection<SimpleClubModel> findAllClub() throws Throwable {
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(
() -> repository.findAll().list().map(clubModels -> clubModels.stream().map(SimpleClubModel::fromModel).toList())));
() -> repository.findAll().list()
.map(clubModels -> clubModels.stream().map(SimpleClubModel::fromModel).toList())));
}
public Uni<List<ClubModel>> getAll() {
@@ -88,15 +101,32 @@ public class ClubService {
}
public Uni<String> update(long id, FullClubForm input) {
/*return repository.findById(id)
.onItem().transformToUni(m -> {
return repository.findById(id).call(m -> Mutiny.fetch(m.getContact()))
.onItem().transformToUni(Unchecked.function(m -> {
TypeReference<HashMap<Contact, String>> typeRef = new TypeReference<>() {
};
m.setName(input.getName());
m.setCountry(input.getCountry());
m.setNo_affiliation(input.getNo_affiliation());
m.setShieldURL(input.getShieldURL());
if (!input.isInternational()) {
m.setTraining_location(input.getTraining_location());
m.setTraining_day_time(input.getTraining_day_time());
m.setContact_intern(input.getContact_intern());
m.setRNA(input.getRna());
m.setSIRET(input.getSiret());
try {
m.setContact(MAPPER.readValue(input.getContact(), typeRef));
} catch (JsonProcessingException e) {
throw new BadRequestException();
}
}
return Panache.withTransaction(() -> repository.persist(m));
});*/
return Uni.createFrom().nullItem();
}))
.invoke(membreModel -> SReqClub.sendIfNeed(serverCustom.clients,
SimpleClubModel.fromModel(membreModel)))
.map(__ -> "OK");
}
public Uni<Long> add(FullClubForm input) {

View File

@@ -23,7 +23,7 @@ public class SimpleClubModel {
if (model == null)
return null;
return new SimpleClubModel(model.getId(), model.getName(), model.getCountry(), model.getShieldURL(),
model.getNo_affiliation());
return new SimpleClubModel(model.getId(), model.getName(), model.getCountry(),
"/api/club/" + model.getClubId() + "/logo", model.getNo_affiliation());
}
}

View File

@@ -21,13 +21,12 @@ public class SimpleClub {
private String clubId;
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 Long SIRET;
private String no_affiliation;
private boolean international;
private HashMap<String, String> contactMap = null;
@@ -41,7 +40,6 @@ public class SimpleClub {
.clubId(model.getClubId())
.name(model.getName())
.country(model.getCountry())
.shieldURL(model.getShieldURL())
.contact(model.getContact())
.training_location(model.getTraining_location())
.training_day_time(model.getTraining_day_time())

View File

@@ -3,8 +3,10 @@ package fr.titionfire.ffsaf.rest.from;
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.core.MediaType;
import lombok.Getter;
import lombok.ToString;
import org.jboss.resteasy.reactive.PartType;
@ToString
@Getter
public class FullClubForm {
@FormParam("id")
@@ -13,6 +15,30 @@ public class FullClubForm {
@FormParam("name")
private String name = null;
@FormParam("country")
private String country = null;
@FormParam("contact")
private String contact = null;
@FormParam("training_location")
private String training_location = null;
@FormParam("training_day_time")
private String training_day_time = null;
@FormParam("contact_intern")
private String contact_intern = null;
@FormParam("rna")
private String rna = null;
@FormParam("siret")
private Long siret = null;
@FormParam("international")
private boolean international = false;
@FormParam("status")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
private byte[] status = new byte[0];

View File

@@ -54,7 +54,7 @@ public class Utils {
File dirFile = new File(media, dir);
if (!dirFile.exists())
if (dirFile.mkdirs())
if (!dirFile.mkdirs())
throw new IOException("Fail to create directory " + dir);
FilenameFilter filter = (directory, filename) -> filename.startsWith(String.valueOf(id));