diff options
author | Roberto Murguia <robertmalvarado@gmail.com> | 2023-04-04 17:14:29 -0500 |
---|---|---|
committer | Roberto Murguia <robertmalvarado@gmail.com> | 2023-04-04 17:45:08 -0500 |
commit | 9423dad9bc56674dd864897c9c0265ca8cea6670 (patch) | |
tree | a8a99cb19856d3e33d91fcfbfb197eb08204eede | |
parent | 836fb2221dedae55c3f8457f35294b3753f095c8 (diff) | |
download | trackermap-server-9423dad9bc56674dd864897c9c0265ca8cea6670.tar.gz trackermap-server-9423dad9bc56674dd864897c9c0265ca8cea6670.tar.bz2 trackermap-server-9423dad9bc56674dd864897c9c0265ca8cea6670.zip |
Add DELETE api endpoint for Positions
-rw-r--r-- | src/main/java/org/traccar/api/resource/PositionResource.java | 17 | ||||
-rw-r--r-- | swagger.json | 48 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/api/resource/PositionResource.java b/src/main/java/org/traccar/api/resource/PositionResource.java index 042dd1e23..37696a620 100644 --- a/src/main/java/org/traccar/api/resource/PositionResource.java +++ b/src/main/java/org/traccar/api/resource/PositionResource.java @@ -31,6 +31,7 @@ import org.traccar.storage.query.Request; import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.GET; +import javax.ws.rs.DELETE; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; @@ -43,6 +44,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; +import java.util.LinkedList; @Path("positions") @Produces(MediaType.APPLICATION_JSON) @@ -86,6 +88,21 @@ public class PositionResource extends BaseResource { } } + @DELETE + public Response remove( + @QueryParam("deviceId") long deviceId, + @QueryParam("from") Date from, @QueryParam("to") Date to) throws StorageException { + permissionsService.checkPermission(Device.class, getUserId(), deviceId); + permissionsService.checkRestriction(getUserId(), UserRestrictions::getReadonly); + + var conditions = new LinkedList<Condition>(); + conditions.add(new Condition.Equals("deviceId", deviceId)); + conditions.add(new Condition.Between("fixTime", "from", from, "to", to)); + storage.removeObject(Position.class, new Request(Condition.merge(conditions))); + + return Response.status(Response.Status.NO_CONTENT).build(); + } + @Path("kml") @GET @Produces("application/vnd.google-earth.kml+xml") diff --git a/swagger.json b/swagger.json index 6c1e21d28..467925ca9 100644 --- a/swagger.json +++ b/swagger.json @@ -873,6 +873,54 @@ } } } + }, + "delete": { + "summary": "Deletes all the Positions of a device in the time span specified", + "description": "", + "tags": [ + "Positions" + ], + "parameters": [ + { + "name": "deviceId", + "in": "query", + "description": "", + "schema": { + "type": "integer" + }, + "required": true + }, + { + "name": "from", + "in": "query", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`", + "schema": { + "type": "string", + "format": "date-time" + }, + "required": true + }, + { + "name": "to", + "in": "query", + "description": "in IS0 8601 format. eg. `1963-11-22T18:30:00Z`", + "schema": { + "type": "string", + "format": "date-time" + }, + "required": true + } + ], + "responses": { + "204": { + "description": "No Content", + "content": {} + }, + "400": { + "description": "Bad Request", + "content": {} + } + } } }, "/server": { |