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

io.swagger.petstore3.controllers.UserController 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.JsonProcessingException;
import io.apimatic.core.ApiCall;
import io.apimatic.core.ErrorCase;
import io.apimatic.core.GlobalConfiguration;
import io.swagger.petstore3.ApiHelper;
import io.swagger.petstore3.Server;
import io.swagger.petstore3.exceptions.ApiException;
import io.swagger.petstore3.http.request.HttpMethod;
import io.swagger.petstore3.models.User;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

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

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

    /**
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public void logoutUser() throws ApiException, IOException {
        prepareLogoutUserRequest().execute();
    }

    /**
     * @return    Returns the void response from the API call
     */
    public CompletableFuture logoutUserAsync() {
        try { 
            return prepareLogoutUserRequest().executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for logoutUser.
     */
    private ApiCall prepareLogoutUserRequest() throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/user/logout")
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * Creates list of users with given input array.
     * @param  body  Optional parameter: Example:
     * @return    Returns the User 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 User createUsersWithListInput(
            final List body) throws ApiException, IOException {
        return prepareCreateUsersWithListInputRequest(body).execute();
    }

    /**
     * Creates list of users with given input array.
     * @param  body  Optional parameter: Example:
     * @return    Returns the User response from the API call
     */
    public CompletableFuture createUsersWithListInputAsync(
            final List body) {
        try { 
            return prepareCreateUsersWithListInputRequest(body).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for createUsersWithListInput.
     */
    private ApiCall prepareCreateUsersWithListInputRequest(
            final List body) throws JsonProcessingException, IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/user/createWithList")
                        .bodyParam(param -> param.value(body).isRequired(false))
                        .bodySerializer(() ->  ApiHelper.serialize(body))
                        .headerParam(param -> param.key("Content-Type")
                                .value("application/json").isRequired(false))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .httpMethod(HttpMethod.POST))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, User.class))
                        .nullify404(false)
                        .localErrorCase(ErrorCase.DEFAULT,
                                 ErrorCase.setReason("successful operation",
                                (reason, context) -> new ApiException(reason, context)))
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * This can only be done by the logged in user.
     * @param  id  Optional parameter: Example:
     * @param  username  Optional parameter: Example:
     * @param  firstName  Optional parameter: Example:
     * @param  lastName  Optional parameter: Example:
     * @param  email  Optional parameter: Example:
     * @param  password  Optional parameter: Example:
     * @param  phone  Optional parameter: Example:
     * @param  userStatus  Optional parameter: User Status
     * @return    Returns the User 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 User createUser(
            final Long id,
            final String username,
            final String firstName,
            final String lastName,
            final String email,
            final String password,
            final String phone,
            final Integer userStatus) throws ApiException, IOException {
        return prepareCreateUserRequest(id, username, firstName, lastName, email, password, phone,
                userStatus).execute();
    }

    /**
     * This can only be done by the logged in user.
     * @param  id  Optional parameter: Example:
     * @param  username  Optional parameter: Example:
     * @param  firstName  Optional parameter: Example:
     * @param  lastName  Optional parameter: Example:
     * @param  email  Optional parameter: Example:
     * @param  password  Optional parameter: Example:
     * @param  phone  Optional parameter: Example:
     * @param  userStatus  Optional parameter: User Status
     * @return    Returns the User response from the API call
     */
    public CompletableFuture createUserAsync(
            final Long id,
            final String username,
            final String firstName,
            final String lastName,
            final String email,
            final String password,
            final String phone,
            final Integer userStatus) {
        try { 
            return prepareCreateUserRequest(id, username, firstName, lastName, email, password, phone,
            userStatus).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for createUser.
     */
    private ApiCall prepareCreateUserRequest(
            final Long id,
            final String username,
            final String firstName,
            final String lastName,
            final String email,
            final String password,
            final String phone,
            final Integer userStatus) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/user")
                        .formParam(param -> param.key("id")
                                .value(id).isRequired(false))
                        .formParam(param -> param.key("username")
                                .value(username).isRequired(false))
                        .formParam(param -> param.key("firstName")
                                .value(firstName).isRequired(false))
                        .formParam(param -> param.key("lastName")
                                .value(lastName).isRequired(false))
                        .formParam(param -> param.key("email")
                                .value(email).isRequired(false))
                        .formParam(param -> param.key("password")
                                .value(password).isRequired(false))
                        .formParam(param -> param.key("phone")
                                .value(phone).isRequired(false))
                        .formParam(param -> param.key("userStatus")
                                .value(userStatus).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, User.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * @param  username  Optional parameter: The user name for login
     * @param  password  Optional parameter: The password for login in clear text
     * @return    Returns the String 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 String loginUser(
            final String username,
            final String password) throws ApiException, IOException {
        return prepareLoginUserRequest(username, password).execute();
    }

    /**
     * @param  username  Optional parameter: The user name for login
     * @param  password  Optional parameter: The password for login in clear text
     * @return    Returns the String response from the API call
     */
    public CompletableFuture loginUserAsync(
            final String username,
            final String password) {
        try { 
            return prepareLoginUserRequest(username, password).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for loginUser.
     */
    private ApiCall prepareLoginUserRequest(
            final String username,
            final String password) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/user/login")
                        .queryParam(param -> param.key("username")
                                .value(username).isRequired(false))
                        .queryParam(param -> param.key("password")
                                .value(password).isRequired(false))
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> new String(response))
                        .nullify404(false)
                        .localErrorCase("400",
                                 ErrorCase.setReason("Invalid username/password supplied",
                                (reason, context) -> new ApiException(reason, context)))
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * @param  name  Required parameter: The name that needs to be fetched. Use user1 for testing.
     * @return    Returns the User 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 User getUserByName(
            final String name) throws ApiException, IOException {
        return prepareGetUserByNameRequest(name).execute();
    }

    /**
     * @param  name  Required parameter: The name that needs to be fetched. Use user1 for testing.
     * @return    Returns the User response from the API call
     */
    public CompletableFuture getUserByNameAsync(
            final String name) {
        try { 
            return prepareGetUserByNameRequest(name).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

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

    /**
     * This can only be done by the logged in user.
     * @param  name  Required parameter: name that need to be deleted
     * @param  id  Optional parameter: Example:
     * @param  username  Optional parameter: Example:
     * @param  firstName  Optional parameter: Example:
     * @param  lastName  Optional parameter: Example:
     * @param  email  Optional parameter: Example:
     * @param  password  Optional parameter: Example:
     * @param  phone  Optional parameter: Example:
     * @param  userStatus  Optional parameter: User Status
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public void updateUser(
            final String name,
            final Long id,
            final String username,
            final String firstName,
            final String lastName,
            final String email,
            final String password,
            final String phone,
            final Integer userStatus) throws ApiException, IOException {
        prepareUpdateUserRequest(name, id, username, firstName, lastName, email, password, phone,
                userStatus).execute();
    }

    /**
     * This can only be done by the logged in user.
     * @param  name  Required parameter: name that need to be deleted
     * @param  id  Optional parameter: Example:
     * @param  username  Optional parameter: Example:
     * @param  firstName  Optional parameter: Example:
     * @param  lastName  Optional parameter: Example:
     * @param  email  Optional parameter: Example:
     * @param  password  Optional parameter: Example:
     * @param  phone  Optional parameter: Example:
     * @param  userStatus  Optional parameter: User Status
     * @return    Returns the void response from the API call
     */
    public CompletableFuture updateUserAsync(
            final String name,
            final Long id,
            final String username,
            final String firstName,
            final String lastName,
            final String email,
            final String password,
            final String phone,
            final Integer userStatus) {
        try { 
            return prepareUpdateUserRequest(name, id, username, firstName, lastName, email, password, phone,
            userStatus).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for updateUser.
     */
    private ApiCall prepareUpdateUserRequest(
            final String name,
            final Long id,
            final String username,
            final String firstName,
            final String lastName,
            final String email,
            final String password,
            final String phone,
            final Integer userStatus) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/user/{name}")
                        .formParam(param -> param.key("id")
                                .value(id).isRequired(false))
                        .formParam(param -> param.key("username")
                                .value(username).isRequired(false))
                        .formParam(param -> param.key("firstName")
                                .value(firstName).isRequired(false))
                        .formParam(param -> param.key("lastName")
                                .value(lastName).isRequired(false))
                        .formParam(param -> param.key("email")
                                .value(email).isRequired(false))
                        .formParam(param -> param.key("password")
                                .value(password).isRequired(false))
                        .formParam(param -> param.key("phone")
                                .value(phone).isRequired(false))
                        .formParam(param -> param.key("userStatus")
                                .value(userStatus).isRequired(false))
                        .templateParam(param -> param.key("name").value(name)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("Content-Type")
                                .value("application/x-www-form-urlencoded").isRequired(false))
                        .httpMethod(HttpMethod.PUT))
                .responseHandler(responseHandler -> responseHandler
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * This can only be done by the logged in user.
     * @param  name  Required parameter: The name 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 deleteUser(
            final String name) throws ApiException, IOException {
        prepareDeleteUserRequest(name).execute();
    }

    /**
     * This can only be done by the logged in user.
     * @param  name  Required parameter: The name that needs to be deleted
     * @return    Returns the void response from the API call
     */
    public CompletableFuture deleteUserAsync(
            final String name) {
        try { 
            return prepareDeleteUserRequest(name).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for deleteUser.
     */
    private ApiCall prepareDeleteUserRequest(
            final String name) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/user/{name}")
                        .templateParam(param -> param.key("name").value(name)
                                .shouldEncode(true))
                        .httpMethod(HttpMethod.DELETE))
                .responseHandler(responseHandler -> responseHandler
                        .nullify404(false)
                        .localErrorCase("400",
                                 ErrorCase.setReason("Invalid username supplied",
                                (reason, context) -> new ApiException(reason, context)))
                        .localErrorCase("404",
                                 ErrorCase.setReason("User not found",
                                (reason, context) -> new ApiException(reason, context)))
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy