add carts

This commit is contained in:
Daniel Goc
2026-03-24 14:46:38 +01:00
parent 04538d4373
commit c464c02301
8 changed files with 303 additions and 13 deletions

View File

@@ -3,3 +3,5 @@ package constdata
// PASSWORD_VALIDATION_REGEX is used by the frontend (JavaScript supports lookaheads).
const PASSWORD_VALIDATION_REGEX = `^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}$`
const SHOP_ID = 1
const MAX_AMOUNT_OF_CARTS_PER_USER = 10
const DEFAULT_NEW_CART_NAME = "new cart"

View File

@@ -51,6 +51,10 @@ var (
// Typed errors for menu handler
ErrNoRootFound = errors.New("no root found in categories table")
// Typed errors for carts handler
ErrMaxAmtOfCartsReached = errors.New("maximal amount of carts reached")
ErrUserHasNoSuchCart = errors.New("user does not have cart with given id")
)
// Error represents an error with HTTP status code
@@ -141,6 +145,11 @@ func GetErrorCode(c fiber.Ctx, err error) string {
case errors.Is(err, ErrNoRootFound):
return i18n.T_(c, "error.no_root_found")
case errors.Is(err, ErrMaxAmtOfCartsReached):
return i18n.T_(c, "error.max_amt_of_carts_reached")
case errors.Is(err, ErrUserHasNoSuchCart):
return i18n.T_(c, "error.max_amt_of_carts_reached")
default:
return i18n.T_(c, "error.err_internal_server_error")
}
@@ -176,7 +185,9 @@ func GetErrorStatus(err error) int {
errors.Is(err, ErrBadField),
errors.Is(err, ErrInvalidXHTML),
errors.Is(err, ErrBadPaging),
errors.Is(err, ErrNoRootFound):
errors.Is(err, ErrNoRootFound),
errors.Is(err, ErrMaxAmtOfCartsReached),
errors.Is(err, ErrUserHasNoSuchCart):
return fiber.StatusBadRequest
case errors.Is(err, ErrEmailExists):
return fiber.StatusConflict