feat: add licence log
This commit is contained in:
parent
0563c7c8de
commit
0a56f8c180
@ -14,7 +14,7 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema;
|
||||
|
||||
@Entity
|
||||
@Table(name = "licence")
|
||||
public class LicenceModel {
|
||||
public class LicenceModel implements LoggableModel {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Schema(description = "L'identifiant de la licence.")
|
||||
@ -39,4 +39,14 @@ public class LicenceModel {
|
||||
@Schema(description = "Licence payer", example = "true")
|
||||
@Column(nullable = false, columnDefinition = "boolean default false")
|
||||
boolean pay = false;
|
||||
|
||||
@Override
|
||||
public String getObjectName() {
|
||||
return "licence " + id.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogModel.ObjectType getObjectType() {
|
||||
return LogModel.ObjectType.Licence;
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,9 @@ public class AffiliationService {
|
||||
@Inject
|
||||
ReactiveMailer reactiveMailer;
|
||||
|
||||
@Inject
|
||||
LoggerService ls;
|
||||
|
||||
@ConfigProperty(name = "upload_dir")
|
||||
String media;
|
||||
|
||||
@ -263,7 +266,9 @@ public class AffiliationService {
|
||||
.call(l1 -> l1 != null && l1.stream().anyMatch(l -> l.getSaison() == saison) ?
|
||||
Uni.createFrom().nullItem() :
|
||||
Panache.withTransaction(() -> licenceRepository.persist(
|
||||
new LicenceModel(null, m, club.getId(), saison, null, true, false)))));
|
||||
new LicenceModel(null, m, club.getId(), saison, null, true, false)))
|
||||
.call(licenceModel -> ls.logA(LogModel.ActionType.ADD, m.getObjectName(),
|
||||
licenceModel))));
|
||||
}
|
||||
|
||||
public Uni<?> accept(AffiliationRequestSaveForm form) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
import fr.titionfire.ffsaf.data.model.LogModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.LicenceRepository;
|
||||
@ -38,6 +39,9 @@ public class LicenceService {
|
||||
@Inject
|
||||
KeycloakService keycloakService;
|
||||
|
||||
@Inject
|
||||
LoggerService ls;
|
||||
|
||||
public Uni<List<LicenceModel>> getLicence(long id, Consumer<MembreModel> checkPerm) {
|
||||
return combRepository.findById(id).invoke(checkPerm)
|
||||
.chain(combRepository -> Mutiny.fetch(combRepository.getLicences()));
|
||||
@ -58,6 +62,8 @@ public class LicenceService {
|
||||
for (Long id : ids) {
|
||||
uni = uni.chain(__ -> repository.find("membre.id = ?1 AND saison = ?2", id, Utils.getSaison()).firstResult()
|
||||
.chain(model -> {
|
||||
if (!model.isValidate())
|
||||
ls.logUpdate("validation de la licence", model);
|
||||
model.setValidate(true);
|
||||
return Panache.withTransaction(() -> repository.persist(model)
|
||||
.call(m -> Mutiny.fetch(m.getMembre())
|
||||
@ -66,7 +72,7 @@ public class LicenceService {
|
||||
}))
|
||||
.map(__ -> "OK");
|
||||
}
|
||||
return uni;
|
||||
return uni.call(__ -> ls.append());
|
||||
}
|
||||
|
||||
public Uni<LicenceModel> setLicence(long id, LicenceForm form) {
|
||||
@ -80,21 +86,27 @@ public class LicenceService {
|
||||
model.setValidate(form.isValidate());
|
||||
model.setPay(form.isPay());
|
||||
return Panache.withTransaction(() -> repository.persist(model)
|
||||
.call(m -> m.isValidate() ? Uni.createFrom().item(membreModel)
|
||||
.call(genLicenceNumberAndAccountIfNeed())
|
||||
: Uni.createFrom().nullItem()
|
||||
));
|
||||
.call(m -> m.isValidate() ? Uni.createFrom().item(membreModel)
|
||||
.call(genLicenceNumberAndAccountIfNeed())
|
||||
: Uni.createFrom().nullItem()
|
||||
))
|
||||
.call(licenceModel -> ls.logA(LogModel.ActionType.ADD, membreModel.getObjectName(),
|
||||
licenceModel));
|
||||
});
|
||||
} else {
|
||||
return repository.findById(form.getId()).chain(model -> {
|
||||
ls.logChange("Certificate", model.getCertificate(), form.getCertificate(), model);
|
||||
ls.logChange("Validate", model.isValidate(), form.isValidate(), model);
|
||||
ls.logChange("Pay", model.isPay(), form.isPay(), model);
|
||||
model.setCertificate(form.getCertificate());
|
||||
model.setValidate(form.isValidate());
|
||||
model.setPay(form.isPay());
|
||||
return Panache.withTransaction(() -> repository.persist(model)
|
||||
.call(m -> m.isValidate() ? Mutiny.fetch(m.getMembre())
|
||||
.call(genLicenceNumberAndAccountIfNeed())
|
||||
: Uni.createFrom().nullItem()
|
||||
));
|
||||
.call(m -> m.isValidate() ? Mutiny.fetch(m.getMembre())
|
||||
.call(genLicenceNumberAndAccountIfNeed())
|
||||
: Uni.createFrom().nullItem()
|
||||
))
|
||||
.call(__ -> ls.append());
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -111,7 +123,9 @@ public class LicenceService {
|
||||
}
|
||||
|
||||
public Uni<?> deleteLicence(long id) {
|
||||
return Panache.withTransaction(() -> repository.deleteById(id));
|
||||
return repository.findById(id)
|
||||
.call(model -> ls.logADelete(model))
|
||||
.chain(model -> repository.delete(model));
|
||||
}
|
||||
|
||||
public Uni<LicenceModel> askLicence(long id, LicenceForm form, Consumer<MembreModel> checkPerm) {
|
||||
@ -129,11 +143,15 @@ public class LicenceService {
|
||||
model.setCertificate(form.getCertificate());
|
||||
model.setValidate(false);
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
}));
|
||||
}))
|
||||
.call(licenceModel -> ls.logA(LogModel.ActionType.ADD, membreModel.getObjectName(),
|
||||
licenceModel));
|
||||
} else {
|
||||
return repository.findById(form.getId()).chain(model -> {
|
||||
ls.logChange("Certificate", model.getCertificate(), form.getCertificate(), model);
|
||||
model.setCertificate(form.getCertificate());
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
return Panache.withTransaction(() -> repository.persist(model))
|
||||
.call(__ -> ls.append());
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -148,6 +166,7 @@ public class LicenceService {
|
||||
if (licenceModel.isPay())
|
||||
throw new DBadRequestException("Impossible de supprimer une licence déjà payée");
|
||||
}))
|
||||
.call(model -> ls.logADelete(model))
|
||||
.chain(__ -> Panache.withTransaction(() -> repository.deleteById(id)));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user