From 1e0c24f452bd0a803c6bf5b1a99a18a073a56ab7 Mon Sep 17 00:00:00 2001 From: Maarten Mulders Date: Tue, 31 Dec 2024 23:21:26 +0100 Subject: [PATCH] feat: Correctly implement JAX-RS endpoint --- .../api/measurements/MeasurementResource.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java index 6113fc2..ad57a26 100644 --- a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java +++ b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java @@ -2,9 +2,8 @@ import it.mulders.traqqr.api.measurements.dto.MeasurementDto; import it.mulders.traqqr.domain.measurements.MeasurementRepository; -import it.mulders.traqqr.domain.vehicles.Authorisation; import it.mulders.traqqr.domain.vehicles.VehicleRepository; -import jakarta.enterprise.context.RequestScoped; +import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.POST; @@ -16,22 +15,27 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response.Status; -@RequestScoped +@ApplicationScoped @Path("/v1/vehicle/{code}/measurement") -@Consumes("application/json") -@Produces("application/json") public class MeasurementResource { - private final MeasurementRepository measurementRepository; - private final VehicleRepository vehicleRepository; - private final MeasurementMapper measurementMapper; - @Inject - public MeasurementResource(MeasurementRepository measurementRepository, VehicleRepository vehicleRepository, MeasurementMapper measurementMapper) { + private MeasurementRepository measurementRepository; + @Inject + private VehicleRepository vehicleRepository; + @Inject + private MeasurementMapper measurementMapper; + + public MeasurementResource() { + } + + protected MeasurementResource(MeasurementRepository measurementRepository, VehicleRepository vehicleRepository, MeasurementMapper measurementMapper) { this.measurementRepository = measurementRepository; this.vehicleRepository = vehicleRepository; this.measurementMapper = measurementMapper; } + @Consumes("application/json") + @Produces("application/json") @POST public Response registerMeasurement(@PathParam("code") String code, MeasurementDto measurementDto, @Context HttpHeaders headers) { var vehicle = vehicleRepository.findByCode(code);