32 lines
1.0 KiB
Java
32 lines
1.0 KiB
Java
package fr.titionfire.ffsaf.rest;
|
|
|
|
import fr.titionfire.ffsaf.rest.client.SirenService;
|
|
import fr.titionfire.ffsaf.rest.data.UniteLegaleRoot;
|
|
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
|
import io.smallrye.mutiny.Uni;
|
|
import jakarta.ws.rs.*;
|
|
import jakarta.ws.rs.core.MediaType;
|
|
import org.eclipse.microprofile.openapi.annotations.Operation;
|
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
|
|
|
@Path("api/asso")
|
|
public class AssoEndpoints {
|
|
|
|
@RestClient
|
|
SirenService sirenService;
|
|
|
|
@GET
|
|
@Path("siren/{siren}")
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
@Operation(hidden = true)
|
|
public Uni<UniteLegaleRoot> getInfoSiren(@PathParam("siren") String siren) {
|
|
return sirenService.get_unite(siren).onFailure().transform(throwable -> {
|
|
if (throwable instanceof WebApplicationException exception) {
|
|
if (exception.getResponse().getStatus() == 400)
|
|
return new DNotFoundException("Siret introuvable");
|
|
}
|
|
return throwable;
|
|
});
|
|
}
|
|
}
|