From add1194484bc24ff335818e1a878942cc22f7ff3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 21 Jun 2020 16:35:46 -0700 Subject: Add single object GET API --- src/main/java/org/traccar/api/BaseObjectResource.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar/api') diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java index 7de6a3877..c4206f385 100644 --- a/src/main/java/org/traccar/api/BaseObjectResource.java +++ b/src/main/java/org/traccar/api/BaseObjectResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2020 Anton Tananaev (anton@traccar.org) * Copyright 2017 - 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ import java.sql.SQLException; import java.util.Set; import javax.ws.rs.DELETE; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; @@ -54,7 +55,7 @@ public abstract class BaseObjectResource extends BaseResour } protected final Set getSimpleManagerItems(BaseObjectManager manager, boolean all, long userId) { - Set result = null; + Set result; if (all) { if (Context.getPermissionsManager().getUserAdmin(getUserId())) { result = manager.getAllItems(); @@ -72,6 +73,19 @@ public abstract class BaseObjectResource extends BaseResour return result; } + @Path("{id}") + @GET + public Response add(@PathParam("id") long id) throws SQLException { + Context.getPermissionsManager().checkPermission(baseClass, getUserId(), id); + BaseObjectManager manager = Context.getManager(baseClass); + T entity = manager.getById(id); + if (entity != null) { + return Response.ok(entity).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).build(); + } + } + @POST public Response add(T entity) throws SQLException { Context.getPermissionsManager().checkReadonly(getUserId()); -- cgit v1.2.3