48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
package dev.dinauer.metrics.service;
|
|
|
|
import dev.dinauer.metrics.service.client.auth.AuthenticationService;
|
|
import dev.dinauer.metrics.service.model.BucketUnit;
|
|
import dev.dinauer.metrics.service.model.Collection;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.ws.rs.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
|
|
@Path("/{resource}/{metric}")
|
|
public class Resource
|
|
{
|
|
@Inject
|
|
AuthenticationService authenticationService;
|
|
|
|
@Inject
|
|
Service service;
|
|
|
|
@POST
|
|
public void insert(@PathParam("resource") String resource, @PathParam("metric") String metric, Map<String, Double> values)
|
|
{
|
|
if (authenticationService.canWrite())
|
|
{
|
|
service.index(resource, metric, values);
|
|
}
|
|
else
|
|
{
|
|
throw new ForbiddenException();
|
|
}
|
|
}
|
|
|
|
@GET
|
|
public List<Collection> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit)
|
|
{
|
|
if (authenticationService.canRead())
|
|
{
|
|
return service.get(resource, metric, bucketUnit.orElse(BucketUnit.RAW));
|
|
}
|
|
else
|
|
{
|
|
throw new ForbiddenException();
|
|
}
|
|
}
|
|
}
|