|
40 | 40 | import convex.restapi.RESTServer;
|
41 | 41 | import convex.restapi.model.CreateAccountRequest;
|
42 | 42 | import convex.restapi.model.CreateAccountResponse;
|
43 |
| -import convex.restapi.model.QueryAccountRequest; |
| 43 | +import convex.restapi.model.QueryAccountResponse; |
44 | 44 | import io.javalin.Javalin;
|
45 | 45 | import io.javalin.http.BadRequestResponse;
|
46 | 46 | import io.javalin.http.Context;
|
47 | 47 | import io.javalin.http.InternalServerErrorResponse;
|
48 | 48 | import io.javalin.http.ServiceUnavailableResponse;
|
49 |
| -import io.javalin.openapi.*; |
| 49 | +import io.javalin.openapi.HttpMethod; |
| 50 | +import io.javalin.openapi.OpenApi; |
| 51 | +import io.javalin.openapi.OpenApiContent; |
| 52 | +import io.javalin.openapi.OpenApiExampleProperty; |
| 53 | +import io.javalin.openapi.OpenApiParam; |
| 54 | +import io.javalin.openapi.OpenApiRequestBody; |
| 55 | +import io.javalin.openapi.OpenApiResponse; |
50 | 56 |
|
51 | 57 | public class ChainAPI extends ABaseAPI {
|
52 | 58 |
|
@@ -154,40 +160,32 @@ public void createAccount(Context ctx) {
|
154 | 160 | ctx.result("{\"address\": " + a.longValue() + "}");
|
155 | 161 | }
|
156 | 162 |
|
157 |
| - @OpenApi(path = ROUTE + "account/{account}", |
158 |
| - methods = HttpMethod.POST, |
| 163 | + @OpenApi(path = ROUTE + "accounts/{address}", |
| 164 | + methods = HttpMethod.GET, |
159 | 165 | operationId = "queryAccount",
|
160 | 166 | tags = { "Account"},
|
161 | 167 | summary = "Get Convex account information",
|
162 |
| - requestBody = @OpenApiRequestBody( |
163 |
| - description = "Query Account request, must provide a valid address", |
164 |
| - content = {@OpenApiContent( |
165 |
| - from = QueryAccountRequest.class, |
166 |
| - type = "application/json", |
167 |
| - exampleObjects = { |
168 |
| - @OpenApiExampleProperty(name = "address", value = "#14") })} |
169 |
| - ), |
| 168 | + pathParams = { |
| 169 | + @OpenApiParam(name = "address", description = "Address of Account", required = true, type = String.class, example="14") |
| 170 | + }, |
170 | 171 | responses = {
|
171 | 172 | @OpenApiResponse(status = "200",
|
172 | 173 | description = "Account queried sucecssfully",
|
173 | 174 | content = {
|
174 | 175 | @OpenApiContent(
|
| 176 | + from=QueryAccountResponse.class, |
175 | 177 | type = "application/json") }),
|
176 |
| - @OpenApiResponse(status = "400", |
| 178 | + @OpenApiResponse(status = "404", |
177 | 179 | description = "Account does not exist" )
|
178 | 180 | }
|
179 | 181 | )
|
180 | 182 | public void queryAccount(Context ctx) {
|
181 | 183 | Address addr = null;
|
182 | 184 | String addrParam = ctx.pathParam("addr");
|
183 |
| - try { |
184 |
| - long a = Long.parseLong(addrParam); |
185 |
| - addr = Address.create(a); |
186 |
| - if (addr == null) |
187 |
| - throw new BadRequestResponse(jsonError("Invalid address: " + a)); |
188 |
| - } catch (Exception e) { |
189 |
| - throw new BadRequestResponse( |
190 |
| - jsonError("Expected valid account number in path but got [" + addrParam + "]")); |
| 185 | + |
| 186 | + addr = Address.parse(addrParam); |
| 187 | + if (addr == null) { |
| 188 | + throw new BadRequestResponse(jsonError("Invalid address: " + addrParam)); |
191 | 189 | }
|
192 | 190 |
|
193 | 191 | Result r = doQuery(Lists.of(Symbols.ACCOUNT, addr));
|
|
0 commit comments