Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/zero order #172

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading