Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Dec 15, 2023
1 parent b83dc48 commit ee1cf92
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cart/internal/usecase/cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
cartTTL = 5 * time.Minute
cartTTL = 24 * time.Hour
)

type ICartUsecase interface {
Expand Down
2 changes: 1 addition & 1 deletion config/cart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ postgres:
pg_url: 'postgres://postgres:root@cart_postgres:5432/postgres?sslmode=disable'

worker:
cart_ttl: 5m
cart_ttl: 24h
cart_task_worker_interval: 1s

logger:
Expand Down
4 changes: 1 addition & 3 deletions config/rbac/roles.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@
"ADMIN": [
"ModerateProduct",

"GetCart",
"DeleteCart",
"DeleteCartCartlines",

"GetUserByEmail",
"GetUsers",

"GetOrders"
],
"SUPERADMIN": [
"GetUsers",
"ChangeUserRole"
]
}
6 changes: 6 additions & 0 deletions order/internal/api/grpc/controller/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"google.golang.org/grpc/status"
)

const maxCancellationTime = 24 * time.Hour

func checkOrderAccessPermission(
ctx context.Context,
orderUsecase usecase.IOrderUsecase,
Expand Down Expand Up @@ -311,6 +313,10 @@ func DeleteOrder(
return status.Errorf(codes.NotFound, "Order not found")
}

if time.Since(order.CreatedAt) > maxCancellationTime {
return status.Errorf(codes.Canceled, "Maximum order cancellation time has been exceeded")
}

if err = orderUsecase.DeleteOrder(ctx, orderID); err != nil {
return status.Errorf(codes.Internal, "Failed to delete order: %s", err)
}
Expand Down

0 comments on commit ee1cf92

Please sign in to comment.