Skip to content

Commit

Permalink
Reorganize output folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Dec 7, 2023
1 parent 641d9b5 commit 080de66
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 284 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
node_modules
package-lock.json
package-lock.json
tmp
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ setup:
go install golang.org/x/tools/cmd/goimports@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/pressly/goose/v3/cmd/goose@latest
go install github.com/cosmtrek/air@latest
npm i
go get ./...

Expand All @@ -14,7 +15,7 @@ build: ## Installs and compiles dependencies

run: ## Start dev mode
make db-up
go run main.go
air main.go

test:
go test ./... -v -cover -p 1
Expand All @@ -27,7 +28,7 @@ lint:

include ./pkg/conf/dev.env
DBDSN:="host=$(POSTGRES_HOST) user=$(POSTGRES_USER) password=$(POSTGRES_PASSWORD) dbname=$(POSTGRES_DB) port=$(POSTGRES_PORT) sslmode=disable"
MIGRATE_OPTIONS=-allow-missing -dir="./migrations"
MIGRATE_OPTIONS=-allow-missing -dir="./pkg/db/migrations"

db-up: ## Migrate down on database
goose -v $(MIGRATE_OPTIONS) postgres $(DBDSN) up
Expand All @@ -39,21 +40,23 @@ db-rebuild: ## Reset the database
make db-down
make db-up

OUTPUT_YAML:="./pkg/static/api.yaml"

bundle-api:
npx @redocly/cli bundle \
pkg/api/openapi.yaml \
--output ./pkg/api.yaml
--output $(OUTPUT_YAML)

validate-api:
make bundle-api
npx @redocly/cli lint \
./pkg/api.yaml \
$(OUTPUT_YAML) \
--format=checkstyle

generate-api: ## Generate server bindings, move model files, fix imports
make validate-api
npx @openapitools/openapi-generator-cli generate \
-i pkg/api.yaml \
-i $(OUTPUT_YAML) \
-g go-server \
-o pkg/rest \
--additional-properties=packageName=api \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/stretchr/testify v1.8.4
)

require github.com/jmoiron/sqlx v1.3.5 // indirect
require github.com/jmoiron/sqlx v1.3.5

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
22 changes: 22 additions & 0 deletions pkg/api/endpoints/user/trading_account_by_id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
get:
tags:
- user
summary: Get trading account
description: Returns user's trading account
operationId: getTradingAccount
parameters:
- in: path
name: trading_account_id
required: true
schema:
$ref: '../../models/trading_account.yaml#/components/schemas/TradingAccountId'

responses:
"200":
description: Success
content:
application/json:
schema:
$ref: '../../models/trading_account.yaml#/components/schemas/TradingAccount'
"404":
description: Error
30 changes: 30 additions & 0 deletions pkg/api/models/trading_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,41 @@ components:
TradingAccountId:
$ref: './shared.yaml#/components/schemas/Id'

TradingAccountInstrument:
type: object
properties:
name:
$ref: "./instrument.yaml#/components/schemas/InstrumentName"
amount:
$ref: "./shared.yaml#/components/schemas/MoneyAmount"
amountReserved:
$ref: "./shared.yaml#/components/schemas/MoneyAmount"
amountAvailable:
$ref: "./shared.yaml#/components/schemas/MoneyAmount"
value:
$ref: "./shared.yaml#/components/schemas/MoneyAmount"
currency:
$ref: "./currency.yaml#/components/schemas/CurrencyName"
required:
- name
- amount
- amountReserved
- amountAvailable
- value
- currency

TradingAccount:
type: object
properties:
id:
$ref: '#/components/schemas/TradingAccountId'
instruments:
type: array
items:
$ref: "#/components/schemas/TradingAccountInstrument"
required:
- id
- instruments

parameters:
TradingAccountId:
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ paths:
$ref: ./endpoints/user/trades.yaml
/trade_orders/{trading_account_id}:
$ref: ./endpoints/user/trade_orders.yaml
/trading_account/{trading_account_id}:
$ref: ./endpoints/user/trading_account_by_id.yaml

# # ADMIN OPERATIONS
/apps/{app_entity_id}:
Expand Down
16 changes: 15 additions & 1 deletion pkg/models/trading_account.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
package models

import "open-outcry/pkg/db"
import (
"open-outcry/pkg/db"

"github.com/shopspring/decimal"
)

// `trading_account.pub_id` db reference
type TradingAccountId string

type TradingAccountInstrument struct {
Amount decimal.Decimal
AmountAvailable float64
AmountReserved float64
Name InstrumentName
Value float64
Currency CurrencyName
}

type TradingAccount struct {
Id TradingAccountId
AppEntityId AppEntityExternalId
// Instruments []TradingAccountInstrument
}

const tradingAccountBaseQuery = `
Expand Down
2 changes: 2 additions & 0 deletions pkg/rest/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ api/model_trade_order_side.go
api/model_trade_order_status.go
api/model_trade_order_time_in_force.go
api/model_trade_order_type.go
api/model_trading_account.go
api/model_trading_account_instrument.go
api/openapi.yaml
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-07T20:17:17.914519+02:00[Europe/Riga]
- Build date: 2023-12-07T21:14:18.495777+02:00[Europe/Riga]


### Running the server
Expand Down
2 changes: 2 additions & 0 deletions pkg/rest/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type UserAPIRouter interface {
GetTradeById(http.ResponseWriter, *http.Request)
GetTradeOrders(http.ResponseWriter, *http.Request)
GetTrades(http.ResponseWriter, *http.Request)
GetTradingAccount(http.ResponseWriter, *http.Request)
}

// UsersAPIRouter defines the required methods for binding the api requests to a responses for the UsersAPI
Expand Down Expand Up @@ -86,6 +87,7 @@ type UserAPIServicer interface {
GetTradeById(context.Context, interface{}, interface{}) (ImplResponse, error)
GetTradeOrders(context.Context, interface{}) (ImplResponse, error)
GetTrades(context.Context, interface{}) (ImplResponse, error)
GetTradingAccount(context.Context, interface{}) (ImplResponse, error)
}

// UsersAPIServicer defines the api actions for the UsersAPI service
Expand Down
19 changes: 19 additions & 0 deletions pkg/rest/api/api_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (c *UserAPIController) Routes() Routes {
"/trades/{trading_account_id}",
c.GetTrades,
},
"GetTradingAccount": Route{
strings.ToUpper("Get"),
"/trading_account/{trading_account_id}",
c.GetTradingAccount,
},
}
}

Expand Down Expand Up @@ -167,3 +172,17 @@ func (c *UserAPIController) GetTrades(w http.ResponseWriter, r *http.Request) {
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

// GetTradingAccount - Get trading account
func (c *UserAPIController) GetTradingAccount(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
tradingAccountIdParam := params["trading_account_id"]
result, err := c.service.GetTradingAccount(r.Context(), tradingAccountIdParam)
// 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)
}
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 @@ -109,3 +109,17 @@ func (s *UserAPIService) GetTrades(ctx context.Context, tradingAccountId interfa

return Response(http.StatusNotImplemented, nil), errors.New("GetTrades method not implemented")
}

// GetTradingAccount - Get trading account
func (s *UserAPIService) GetTradingAccount(ctx context.Context, tradingAccountId interface{}) (ImplResponse, error) {
// TODO - update GetTradingAccount 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, TradingAccount{}) or use other options such as http.Ok ...
// return Response(200, TradingAccount{}), 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("GetTradingAccount method not implemented")
}
36 changes: 36 additions & 0 deletions pkg/rest/api/model_trading_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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

type TradingAccount struct {
Id *interface{} `json:"id"`

Instruments *interface{} `json:"instruments"`
}

// AssertTradingAccountRequired checks if the required fields are not zero-ed
func AssertTradingAccountRequired(obj TradingAccount) error {
elements := map[string]interface{}{
"id": obj.Id,
"instruments": obj.Instruments,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}

return nil
}

// AssertTradingAccountConstraints checks if the values respects the defined constraints
func AssertTradingAccountConstraints(obj TradingAccount) error {
return nil
}
51 changes: 51 additions & 0 deletions pkg/rest/api/model_trading_account_instrument.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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

type TradingAccountInstrument struct {

// Ticker-like name of the instrument. For monetary instruments, a currency pair is used.
Name *interface{} `json:"name"`

Amount *interface{} `json:"amount"`

AmountReserved *interface{} `json:"amountReserved"`

AmountAvailable *interface{} `json:"amountAvailable"`

Value *interface{} `json:"value"`

// ISO 4217 Currency symbol
Currency *interface{} `json:"currency"`
}

// AssertTradingAccountInstrumentRequired checks if the required fields are not zero-ed
func AssertTradingAccountInstrumentRequired(obj TradingAccountInstrument) error {
elements := map[string]interface{}{
"name": obj.Name,
"amount": obj.Amount,
"amountReserved": obj.AmountReserved,
"amountAvailable": obj.AmountAvailable,
"value": obj.Value,
"currency": obj.Currency,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}

return nil
}

// AssertTradingAccountInstrumentConstraints checks if the values respects the defined constraints
func AssertTradingAccountInstrumentConstraints(obj TradingAccountInstrument) error {
return nil
}
Loading

0 comments on commit 080de66

Please sign in to comment.