All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.swagger.petstore3.controllers.StoreController Maven / Gradle / Ivy

/*
 * SwaggerPetstoreOpenAPI30Lib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

package io.swagger.petstore3.controllers;

import com.fasterxml.jackson.core.type.TypeReference;
import io.apimatic.core.ApiCall;
import io.apimatic.core.ErrorCase;
import io.apimatic.core.GlobalConfiguration;
import io.swagger.petstore3.ApiHelper;
import io.swagger.petstore3.DateTimeHelper;
import io.swagger.petstore3.Server;
import io.swagger.petstore3.exceptions.ApiException;
import io.swagger.petstore3.http.request.HttpMethod;
import io.swagger.petstore3.models.Order;
import io.swagger.petstore3.models.OrderStatusEnum;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

/**
 * This class lists all the endpoints of the groups.
 */
public final class StoreController extends BaseController {

    /**
     * Initializes the controller.
     * @param globalConfig    Configurations added in client.
     */
    public StoreController(GlobalConfiguration globalConfig) {
        super(globalConfig);
    }

    /**
     * Returns a map of status codes to quantities.
     * @return    Returns the Map of String, Integer response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public Map getInventory() throws ApiException, IOException {
        return prepareGetInventoryRequest().execute();
    }

    /**
     * Returns a map of status codes to quantities.
     * @return    Returns the Map of String, Integer response from the API call
     */
    public CompletableFuture> getInventoryAsync() {
        try { 
            return prepareGetInventoryRequest().executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for getInventory.
     */
    private ApiCall, ApiException> prepareGetInventoryRequest() throws IOException {
        return new ApiCall.Builder, ApiException>()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/store/inventory")
                        .withAuth(auth -> auth
                                .add("api_key"))
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response,
                                        new TypeReference>(){}))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * Place a new order in the store.
     * @param  id  Optional parameter: Example:
     * @param  petId  Optional parameter: Example:
     * @param  quantity  Optional parameter: Example:
     * @param  shipDate  Optional parameter: Example:
     * @param  orderStatus  Optional parameter: Order Status
     * @param  complete  Optional parameter: Example:
     * @return    Returns the Order response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public Order placeOrder(
            final Long id,
            final Long petId,
            final Integer quantity,
            final LocalDateTime shipDate,
            final OrderStatusEnum orderStatus,
            final Boolean complete) throws ApiException, IOException {
        return preparePlaceOrderRequest(id, petId, quantity, shipDate, orderStatus,
                complete).execute();
    }

    /**
     * Place a new order in the store.
     * @param  id  Optional parameter: Example:
     * @param  petId  Optional parameter: Example:
     * @param  quantity  Optional parameter: Example:
     * @param  shipDate  Optional parameter: Example:
     * @param  orderStatus  Optional parameter: Order Status
     * @param  complete  Optional parameter: Example:
     * @return    Returns the Order response from the API call
     */
    public CompletableFuture placeOrderAsync(
            final Long id,
            final Long petId,
            final Integer quantity,
            final LocalDateTime shipDate,
            final OrderStatusEnum orderStatus,
            final Boolean complete) {
        try { 
            return preparePlaceOrderRequest(id, petId, quantity, shipDate, orderStatus,
            complete).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for placeOrder.
     */
    private ApiCall preparePlaceOrderRequest(
            final Long id,
            final Long petId,
            final Integer quantity,
            final LocalDateTime shipDate,
            final OrderStatusEnum orderStatus,
            final Boolean complete) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/store/order")
                        .formParam(param -> param.key("id")
                                .value(id).isRequired(false))
                        .formParam(param -> param.key("petId")
                                .value(petId).isRequired(false))
                        .formParam(param -> param.key("quantity")
                                .value(quantity).isRequired(false))
                        .formParam(param -> param.key("shipDate")
                                .value(DateTimeHelper.toRfc8601DateTime(shipDate)).isRequired(false))
                        .formParam(param -> param.key("orderStatus")
                                .value((orderStatus != null) ? orderStatus.value() : "approved").isRequired(false))
                        .formParam(param -> param.key("complete")
                                .value(complete).isRequired(false))
                        .headerParam(param -> param.key("Content-Type")
                                .value("application/x-www-form-urlencoded").isRequired(false))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .httpMethod(HttpMethod.POST))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, Order.class))
                        .nullify404(false)
                        .localErrorCase("405",
                                 ErrorCase.setReason("Invalid input",
                                (reason, context) -> new ApiException(reason, context)))
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * For valid response try integer IDs with value <= 5 or > 10. Other values will generate
     * exceptions.
     * @param  orderId  Required parameter: ID of order that needs to be fetched
     * @return    Returns the Order response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public Order getOrderById(
            final long orderId) throws ApiException, IOException {
        return prepareGetOrderByIdRequest(orderId).execute();
    }

    /**
     * For valid response try integer IDs with value <= 5 or > 10. Other values will generate
     * exceptions.
     * @param  orderId  Required parameter: ID of order that needs to be fetched
     * @return    Returns the Order response from the API call
     */
    public CompletableFuture getOrderByIdAsync(
            final long orderId) {
        try { 
            return prepareGetOrderByIdRequest(orderId).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for getOrderById.
     */
    private ApiCall prepareGetOrderByIdRequest(
            final long orderId) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/store/order/{orderId}")
                        .templateParam(param -> param.key("orderId").value(orderId).isRequired(false)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, Order.class))
                        .nullify404(false)
                        .localErrorCase("400",
                                 ErrorCase.setReason("Invalid ID supplied",
                                (reason, context) -> new ApiException(reason, context)))
                        .localErrorCase("404",
                                 ErrorCase.setReason("Order not found",
                                (reason, context) -> new ApiException(reason, context)))
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will
     * generate API errors.
     * @param  orderId  Required parameter: ID of the order that needs to be deleted
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public void deleteOrder(
            final long orderId) throws ApiException, IOException {
        prepareDeleteOrderRequest(orderId).execute();
    }

    /**
     * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will
     * generate API errors.
     * @param  orderId  Required parameter: ID of the order that needs to be deleted
     * @return    Returns the void response from the API call
     */
    public CompletableFuture deleteOrderAsync(
            final long orderId) {
        try { 
            return prepareDeleteOrderRequest(orderId).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for deleteOrder.
     */
    private ApiCall prepareDeleteOrderRequest(
            final long orderId) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/store/order/{orderId}")
                        .templateParam(param -> param.key("orderId").value(orderId).isRequired(false)
                                .shouldEncode(true))
                        .httpMethod(HttpMethod.DELETE))
                .responseHandler(responseHandler -> responseHandler
                        .nullify404(false)
                        .localErrorCase("400",
                                 ErrorCase.setReason("Invalid ID supplied",
                                (reason, context) -> new ApiException(reason, context)))
                        .localErrorCase("404",
                                 ErrorCase.setReason("Order not found",
                                (reason, context) -> new ApiException(reason, context)))
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy