Skip to content

Commit

Permalink
Fix typo for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Dec 7, 2023
1 parent 080de66 commit dd4678a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 150 deletions.
2 changes: 1 addition & 1 deletion pkg/api/endpoints/user/trade_orders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get:

post:
tags:
- users
- user
summary: Create trade order
description: Creates a trade order
operationId: createTrade
Expand Down
2 changes: 0 additions & 2 deletions pkg/rest/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 2 additions & 15 deletions pkg/rest/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
35 changes: 35 additions & 0 deletions pkg/rest/api/api_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package api

import (
"encoding/json"
"net/http"
"strings"

Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions pkg/rest/api/api_user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
88 changes: 0 additions & 88 deletions pkg/rest/api/api_users.go

This file was deleted.

41 changes: 0 additions & 41 deletions pkg/rest/api/api_users_service.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/rest/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/static/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ paths:
description: Error
post:
tags:
- users
- user
summary: Create trade order
description: Creates a trade order
operationId: createTrade
Expand Down

0 comments on commit dd4678a

Please sign in to comment.