diff --git a/pkg/api/endpoints/user/trade_orders.yaml b/pkg/api/endpoints/user/trade_orders.yaml index e6278b4..f93cdf9 100644 --- a/pkg/api/endpoints/user/trade_orders.yaml +++ b/pkg/api/endpoints/user/trade_orders.yaml @@ -19,7 +19,7 @@ get: post: tags: - - users + - user summary: Create trade order description: Creates a trade order operationId: createTrade diff --git a/pkg/rest/.openapi-generator/FILES b/pkg/rest/.openapi-generator/FILES index d3cb36e..1bd5322 100644 --- a/pkg/rest/.openapi-generator/FILES +++ b/pkg/rest/.openapi-generator/FILES @@ -5,8 +5,6 @@ api/api_admin_service.go api/api_public.go api/api_user.go api/api_user_service.go -api/api_users.go -api/api_users_service.go api/error.go api/helpers.go api/impl.go diff --git a/pkg/rest/README.md b/pkg/rest/README.md index 8458219..fe4d7cf 100644 --- a/pkg/rest/README.md +++ b/pkg/rest/README.md @@ -24,7 +24,7 @@ To see how to make this your own, look here: [README](https://openapi-generator.tech) - API version: 1.0.0 -- Build date: 2023-12-07T21:14:18.495777+02:00[Europe/Riga] +- Build date: 2023-12-07T21:19:37.002526+02:00[Europe/Riga] ### Running the server diff --git a/pkg/rest/api/api.go b/pkg/rest/api/api.go index 1bb5ca1..af02887 100644 --- a/pkg/rest/api/api.go +++ b/pkg/rest/api/api.go @@ -38,6 +38,7 @@ type PublicAPIRouter interface { // The UserAPIRouter implementation should parse necessary information from the http request, // pass the data to a UserAPIServicer to perform the required actions, then write the service results to the http response. type UserAPIRouter interface { + CreateTrade(http.ResponseWriter, *http.Request) DeleteTradeById(http.ResponseWriter, *http.Request) GetBookOrders(http.ResponseWriter, *http.Request) GetPaymentAccounts(http.ResponseWriter, *http.Request) @@ -47,13 +48,6 @@ type UserAPIRouter interface { GetTradingAccount(http.ResponseWriter, *http.Request) } -// UsersAPIRouter defines the required methods for binding the api requests to a responses for the UsersAPI -// The UsersAPIRouter implementation should parse necessary information from the http request, -// pass the data to a UsersAPIServicer to perform the required actions, then write the service results to the http response. -type UsersAPIRouter interface { - CreateTrade(http.ResponseWriter, *http.Request) -} - // AdminAPIServicer defines the api actions for the AdminAPI service // This interface intended to stay up to date with the openapi yaml used to generate it, // while the service implementation can be ignored with the .openapi-generator-ignore file @@ -81,6 +75,7 @@ type PublicAPIServicer interface { // while the service implementation can be ignored with the .openapi-generator-ignore file // and updated with the logic required for the API. type UserAPIServicer interface { + CreateTrade(context.Context, interface{}, CreateTradeRequest) (ImplResponse, error) DeleteTradeById(context.Context, interface{}, interface{}) (ImplResponse, error) GetBookOrders(context.Context, interface{}) (ImplResponse, error) GetPaymentAccounts(context.Context, interface{}) (ImplResponse, error) @@ -89,11 +84,3 @@ type UserAPIServicer interface { GetTrades(context.Context, interface{}) (ImplResponse, error) GetTradingAccount(context.Context, interface{}) (ImplResponse, error) } - -// UsersAPIServicer defines the api actions for the UsersAPI service -// This interface intended to stay up to date with the openapi yaml used to generate it, -// while the service implementation can be ignored with the .openapi-generator-ignore file -// and updated with the logic required for the API. -type UsersAPIServicer interface { - CreateTrade(context.Context, interface{}, CreateTradeRequest) (ImplResponse, error) -} diff --git a/pkg/rest/api/api_user.go b/pkg/rest/api/api_user.go index bdb5427..2946f24 100644 --- a/pkg/rest/api/api_user.go +++ b/pkg/rest/api/api_user.go @@ -10,6 +10,7 @@ package api import ( + "encoding/json" "net/http" "strings" @@ -49,6 +50,11 @@ func NewUserAPIController(s UserAPIServicer, opts ...UserAPIOption) Router { // Routes returns all the api routes for the UserAPIController func (c *UserAPIController) Routes() Routes { return Routes{ + "CreateTrade": Route{ + strings.ToUpper("Post"), + "/trade_orders/{trading_account_id}", + c.CreateTrade, + }, "DeleteTradeById": Route{ strings.ToUpper("Delete"), "/trades/{trading_account_id}/id/{trade_id}", @@ -87,6 +93,35 @@ func (c *UserAPIController) Routes() Routes { } } +// CreateTrade - Create trade order +func (c *UserAPIController) CreateTrade(w http.ResponseWriter, r *http.Request) { + params := mux.Vars(r) + tradingAccountIdParam := params["trading_account_id"] + createTradeRequestParam := CreateTradeRequest{} + d := json.NewDecoder(r.Body) + d.DisallowUnknownFields() + if err := d.Decode(&createTradeRequestParam); err != nil { + c.errorHandler(w, r, &ParsingError{Err: err}, nil) + return + } + if err := AssertCreateTradeRequestRequired(createTradeRequestParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + if err := AssertCreateTradeRequestConstraints(createTradeRequestParam); err != nil { + c.errorHandler(w, r, err, nil) + return + } + result, err := c.service.CreateTrade(r.Context(), tradingAccountIdParam, createTradeRequestParam) + // If an error occurred, encode the error with the status code + if err != nil { + c.errorHandler(w, r, err, &result) + return + } + // If no error, encode the body and the result code + EncodeJSONResponse(result.Body, &result.Code, w) +} + // DeleteTradeById - Cancel trade func (c *UserAPIController) DeleteTradeById(w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) diff --git a/pkg/rest/api/api_user_service.go b/pkg/rest/api/api_user_service.go index fc4e213..86c73b9 100644 --- a/pkg/rest/api/api_user_service.go +++ b/pkg/rest/api/api_user_service.go @@ -26,6 +26,20 @@ func NewUserAPIService() UserAPIServicer { return &UserAPIService{} } +// CreateTrade - Create trade order +func (s *UserAPIService) CreateTrade(ctx context.Context, tradingAccountId interface{}, createTradeRequest CreateTradeRequest) (ImplResponse, error) { + // TODO - update CreateTrade with the required logic for this service method. + // Add api_user_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. + + // TODO: Uncomment the next line to return response Response(200, TradeOrder{}) or use other options such as http.Ok ... + // return Response(200, TradeOrder{}), nil + + // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... + // return Response(404, nil),nil + + return Response(http.StatusNotImplemented, nil), errors.New("CreateTrade method not implemented") +} + // DeleteTradeById - Cancel trade func (s *UserAPIService) DeleteTradeById(ctx context.Context, tradingAccountId interface{}, tradeId interface{}) (ImplResponse, error) { // TODO - update DeleteTradeById with the required logic for this service method. diff --git a/pkg/rest/api/api_users.go b/pkg/rest/api/api_users.go deleted file mode 100644 index 9148a85..0000000 --- a/pkg/rest/api/api_users.go +++ /dev/null @@ -1,88 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # Introduction This API is documented in **OpenAPI 3.0 format**. This API the following operations: * Retrieve a list of available instruments * Retrieve a list of executed trades # Basics * API calls have to be secured with HTTPS. * All data has to be submitted UTF-8 encoded. * The reply is sent JSON encoded. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -import ( - "encoding/json" - "net/http" - "strings" - - "github.com/gorilla/mux" -) - -// UsersAPIController binds http requests to an api service and writes the service results to the http response -type UsersAPIController struct { - service UsersAPIServicer - errorHandler ErrorHandler -} - -// UsersAPIOption for how the controller is set up. -type UsersAPIOption func(*UsersAPIController) - -// WithUsersAPIErrorHandler inject ErrorHandler into controller -func WithUsersAPIErrorHandler(h ErrorHandler) UsersAPIOption { - return func(c *UsersAPIController) { - c.errorHandler = h - } -} - -// NewUsersAPIController creates a default api controller -func NewUsersAPIController(s UsersAPIServicer, opts ...UsersAPIOption) Router { - controller := &UsersAPIController{ - service: s, - errorHandler: DefaultErrorHandler, - } - - for _, opt := range opts { - opt(controller) - } - - return controller -} - -// Routes returns all the api routes for the UsersAPIController -func (c *UsersAPIController) Routes() Routes { - return Routes{ - "CreateTrade": Route{ - strings.ToUpper("Post"), - "/trade_orders/{trading_account_id}", - c.CreateTrade, - }, - } -} - -// CreateTrade - Create trade order -func (c *UsersAPIController) CreateTrade(w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - tradingAccountIdParam := params["trading_account_id"] - createTradeRequestParam := CreateTradeRequest{} - d := json.NewDecoder(r.Body) - d.DisallowUnknownFields() - if err := d.Decode(&createTradeRequestParam); err != nil { - c.errorHandler(w, r, &ParsingError{Err: err}, nil) - return - } - if err := AssertCreateTradeRequestRequired(createTradeRequestParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - if err := AssertCreateTradeRequestConstraints(createTradeRequestParam); err != nil { - c.errorHandler(w, r, err, nil) - return - } - result, err := c.service.CreateTrade(r.Context(), tradingAccountIdParam, createTradeRequestParam) - // If an error occurred, encode the error with the status code - if err != nil { - c.errorHandler(w, r, err, &result) - return - } - // If no error, encode the body and the result code - EncodeJSONResponse(result.Body, &result.Code, w) -} diff --git a/pkg/rest/api/api_users_service.go b/pkg/rest/api/api_users_service.go deleted file mode 100644 index 4e1a3f2..0000000 --- a/pkg/rest/api/api_users_service.go +++ /dev/null @@ -1,41 +0,0 @@ -/* - * OPEN OUTCRY API - * - * # Introduction This API is documented in **OpenAPI 3.0 format**. This API the following operations: * Retrieve a list of available instruments * Retrieve a list of executed trades # Basics * API calls have to be secured with HTTPS. * All data has to be submitted UTF-8 encoded. * The reply is sent JSON encoded. - * - * API version: 1.0.0 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package api - -import ( - "context" - "errors" - "net/http" -) - -// UsersAPIService is a service that implements the logic for the UsersAPIServicer -// This service should implement the business logic for every endpoint for the UsersAPI API. -// Include any external packages or services that will be required by this service. -type UsersAPIService struct { -} - -// NewUsersAPIService creates a default api service -func NewUsersAPIService() UsersAPIServicer { - return &UsersAPIService{} -} - -// CreateTrade - Create trade order -func (s *UsersAPIService) CreateTrade(ctx context.Context, tradingAccountId interface{}, createTradeRequest CreateTradeRequest) (ImplResponse, error) { - // TODO - update CreateTrade with the required logic for this service method. - // Add api_users_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation. - - // TODO: Uncomment the next line to return response Response(200, TradeOrder{}) or use other options such as http.Ok ... - // return Response(200, TradeOrder{}), nil - - // TODO: Uncomment the next line to return response Response(404, {}) or use other options such as http.Ok ... - // return Response(404, nil),nil - - return Response(http.StatusNotImplemented, nil), errors.New("CreateTrade method not implemented") -} diff --git a/pkg/rest/api/openapi.yaml b/pkg/rest/api/openapi.yaml index c7ed196..1a12f80 100644 --- a/pkg/rest/api/openapi.yaml +++ b/pkg/rest/api/openapi.yaml @@ -236,7 +236,7 @@ paths: description: Error summary: Create trade order tags: - - users + - user /trading_account/{trading_account_id}: get: description: Returns user's trading account diff --git a/pkg/static/api.yaml b/pkg/static/api.yaml index 21b37c0..736744c 100644 --- a/pkg/static/api.yaml +++ b/pkg/static/api.yaml @@ -206,7 +206,7 @@ paths: description: Error post: tags: - - users + - user summary: Create trade order description: Creates a trade order operationId: createTrade