diff --git a/api/src/main/java/com/maptology/api/device/IDeviceService.java b/api/src/main/java/com/maptology/api/device/IDeviceService.java index 5fcc0f9..1fc6eb8 100644 --- a/api/src/main/java/com/maptology/api/device/IDeviceService.java +++ b/api/src/main/java/com/maptology/api/device/IDeviceService.java @@ -59,8 +59,43 @@ public interface IDeviceService { @ApiOperation(value = "Deletes a device", authorizations = {@Authorization("device")}) @ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "The device was deleted successfully."), + @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "The device does not exists"), @ApiResponse(code = HttpServletResponse.SC_FORBIDDEN, message = "Insufficient privileges for executing this method.") }) Response deleteDevice(@ApiParam(value = "The device id", required = true) @PathParam("id") @Valid @Min(0) long id); + /** + * Get the last known location of a device + * + * @param id The id of the device + * @return The last known location + */ + @GET + @Path("device/{id}/location") + @ApiOperation(value = "Returns the last known location of a device", authorizations = {@Authorization("device")}) + @ApiResponses({ + @ApiResponse(code = HttpServletResponse.SC_OK, message = "The request was successfully"), + @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "The device does not exists"), + @ApiResponse(code = HttpServletResponse.SC_FORBIDDEN, message = "Insufficient privileges") + }) + Response getDeviceLocation(@ApiParam(value = "The device id", required = true) @PathParam("id") @Valid @Min(0) long id); + + /** + * Set the last known location of a device + * + * @param id The id of the device + * @param location The location to set + */ + @POST + @Path("device/{id}/location") + @ApiOperation(value = "Updates the last known location of a device", authorizations = {@Authorization("device")}) + @ApiResponses({ + @ApiResponse(code = HttpServletResponse.SC_OK, message = "The request was successfully", response = Location.class), + @ApiResponse(code = HttpServletResponse.SC_NOT_FOUND, message = "The device does not exists"), + @ApiResponse(code = HttpServletResponse.SC_FORBIDDEN, message = "Insufficient privileges"), + @ApiResponse(code = HttpServletResponse.SC_BAD_REQUEST, message = "Invalid request parameter.") + }) + Response setDeviceLocation(@ApiParam(value = "The device id", required = true) @PathParam("id") @Valid @Min(0) long id, + @ApiParam(value = "The location to set", required = true) @Valid Location location); + } diff --git a/api/src/main/java/com/maptology/api/device/Location.java b/api/src/main/java/com/maptology/api/device/Location.java new file mode 100644 index 0000000..89cbeee --- /dev/null +++ b/api/src/main/java/com/maptology/api/device/Location.java @@ -0,0 +1,60 @@ +package com.maptology.api.device; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * * A data transfer object for a device location with associated swagger and + * jaxb annotations that supports xml and json serialization. + * + * @author Ole + */ +@XmlRootElement +@ApiModel(description = "Represents a location.") +public class Location { + + @Min(-180) + @Max(180) + @XmlAttribute(required = true) + @ApiModelProperty(value = "The longitude of a location", required = true) + private double lon; + + @Min(-90) + @Max(90) + @XmlAttribute(required = true) + @ApiModelProperty(value = "The latitude of a location", required = true) + private double lat; + + @XmlAttribute(required = true) + @ApiModelProperty(value = "The timestamp of the location", required = true) + private long timestamp; + + public double getLon() { + return lon; + } + + public void setLon(double lon) { + this.lon = lon; + } + + public double getLat() { + return lat; + } + + public void setLat(double lat) { + this.lat = lat; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +}