Skip to content

Commit

Permalink
Hotfix/zero order (#172)
Browse files Browse the repository at this point in the history
* avoid size price zero in rest level

* avoid zero size or price on order level

* ddress negative size and price
  • Loading branch information
uv-orbs authored Mar 28, 2024
1 parent 65c3d40 commit 72fb8fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions service/create_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ func (s *Service) createNewOrder(ctx context.Context, input CreateOrderInput, us

logctx.Debug(ctx, "creating new order", logger.String("orderId", orderId.String()), logger.String("clientOrderId", input.ClientOrderID.String()))

if input.Price.IsZero() || input.Price.IsNegative() {
logctx.Warn(ctx, "price has to be positive", logger.String("orderId", orderId.String()), logger.String("price", input.Price.String()))
return models.Order{}, models.ErrInvalidInput
}

if input.Size.IsZero() || input.Size.IsNegative() {
logctx.Warn(ctx, "size has to be positive", logger.String("orderId", orderId.String()), logger.String("size", input.Size.String()))
return models.Order{}, models.ErrInvalidInput
}

order := models.Order{
Id: orderId,
ClientOId: input.ClientOrderID,
Expand Down
4 changes: 2 additions & 2 deletions transport/rest/create_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func parseFields(_ http.ResponseWriter, input pFInput) (*pfParsed, error) {
return nil, fmt.Errorf("'price' is not a valid number format")
}

if decPrice.IsNegative() {
if decPrice.IsZero() || decPrice.IsNegative() {
return nil, fmt.Errorf("'price' must be positive")
}

Expand All @@ -205,7 +205,7 @@ func parseFields(_ http.ResponseWriter, input pFInput) (*pfParsed, error) {
return nil, fmt.Errorf("'size' is not a valid number format")
}

if decSize.IsNegative() {
if decSize.IsZero() || decSize.IsNegative() {
return nil, fmt.Errorf("'size' must be positive")
}

Expand Down

0 comments on commit 72fb8fc

Please sign in to comment.