This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 885
/
PetStoreResource.java
94 lines (86 loc) · 3.51 KB
/
PetStoreResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* Copyright 2016 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.swagger.sample.resource;
import io.swagger.annotations.*;
import io.swagger.sample.data.StoreData;
import io.swagger.sample.model.Order;
import io.swagger.sample.exception.NotFoundException;
import io.swagger.sample.data.PetData;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.*;
@Path("/store")
@Api(value="/store" , description = "Operations about store")
@Produces({"application/json", "application/xml"})
public class PetStoreResource {
static StoreData storeData = new StoreData();
static PetData petData = new PetData();
@GET
@Path("/inventory")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ApiOperation(value = "Returns pet inventories by status",
notes = "Returns a map of status codes to quantities",
response = Integer.class,
responseContainer = "map",
authorizations = @Authorization(value = "api_key")
)
public java.util.Map<String, Integer> getInventory() {
return petData.getInventoryByStatus();
}
@GET
@Path("/order/{orderId}")
@ApiOperation(value = "Find purchase order by ID",
notes = "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions",
response = Order.class)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Order not found") })
public Response getOrderById(
@ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,10]", required = true)
@PathParam("orderId") Long orderId)
throws NotFoundException {
Order order = storeData.findOrderById(orderId);
if (null != order) {
return Response.ok().entity(order).build();
} else {
throw new NotFoundException(404, "Order not found");
}
}
@POST
@Path("/order")
@ApiOperation(value = "Place an order for a pet")
@ApiResponses({ @ApiResponse(code = 400, message = "Invalid Order") })
public Order placeOrder(
@ApiParam(value = "order placed for purchasing the pet",
required = true) Order order) {
storeData.placeOrder(order);
return storeData.placeOrder(order);
}
@DELETE
@Path("/order/{orderId}")
@ApiOperation(value = "Delete purchase order by ID",
notes = "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid ID supplied"),
@ApiResponse(code = 404, message = "Order not found") })
public Response deleteOrder(
@ApiParam(value = "ID of the order that needs to be deleted", allowableValues = "range[1,infinity]", required = true)
@PathParam("orderId") Long orderId) {
if (storeData.deleteOrder(orderId)) {
return Response.ok().entity("").build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity("Order not found").build();
}
}
}