added addresses endpoints

This commit is contained in:
Daniel Goc
2026-04-09 12:21:56 +02:00
parent 75997ab15b
commit 1083ab7a61
17 changed files with 684 additions and 15 deletions

View File

@@ -12,6 +12,8 @@ const CATEGORY_TREE_ROOT_ID = 2
const MAX_AMOUNT_OF_CARTS_PER_USER = 10
const DEFAULT_NEW_CART_NAME = "new cart"
const MAX_AMOUNT_OF_ADDRESSES_PER_USER = 10
const USER_LOCALE = "user"
// WEBDAV

View File

@@ -72,6 +72,12 @@ var (
// Typed errors for data parsing
ErrJSONBody = errors.New("invalid JSON body")
// Typed errors for addresses
ErrMaxAmtOfAddressesReached = errors.New("maximal amount of addresses per user reached")
ErrUserHasNoSuchAddress = errors.New("user has no such address")
ErrInvalidCountryID = errors.New("invalid country id")
ErrInvalidAddressJSON = errors.New("invalid address json")
)
// Error represents an error with HTTP status code
@@ -154,7 +160,7 @@ func GetErrorCode(c fiber.Ctx, err error) string {
case errors.Is(err, ErrBadField):
return i18n.T_(c, "error.err_bad_field")
case errors.Is(err, ErrInvalidURLSlug):
return i18n.T_(c, "error.invalid_url_slug")
return i18n.T_(c, "error.err_invalid_url_slug")
case errors.Is(err, ErrInvalidXHTML):
return i18n.T_(c, "error.err_invalid_html")
case errors.Is(err, ErrAIResponseFail):
@@ -166,35 +172,44 @@ func GetErrorCode(c fiber.Ctx, err error) string {
return i18n.T_(c, "error.err_bad_paging")
case errors.Is(err, ErrNoRootFound):
return i18n.T_(c, "error.no_root_found")
return i18n.T_(c, "error.err_no_root_found")
case errors.Is(err, ErrCircularDependency):
return i18n.T_(c, "error.circular_dependency")
return i18n.T_(c, "error.err_circular_dependency")
case errors.Is(err, ErrStartCategoryNotFound):
return i18n.T_(c, "error.start_category_not_found")
return i18n.T_(c, "error.err_start_category_not_found")
case errors.Is(err, ErrRootNeverReached):
return i18n.T_(c, "error.root_never_reached")
return i18n.T_(c, "error.err_root_never_reached")
case errors.Is(err, ErrMaxAmtOfCartsReached):
return i18n.T_(c, "error.max_amt_of_carts_reached")
return i18n.T_(c, "error.err_max_amt_of_carts_reached")
case errors.Is(err, ErrUserHasNoSuchCart):
return i18n.T_(c, "error.user_has_no_such_cart")
return i18n.T_(c, "error.err_user_has_no_such_cart")
case errors.Is(err, ErrProductOrItsVariationDoesNotExist):
return i18n.T_(c, "error.product_or_its_variation_does_not_exist")
return i18n.T_(c, "error.err_product_or_its_variation_does_not_exist")
case errors.Is(err, ErrAccessDenied):
return i18n.T_(c, "error.access_denied")
return i18n.T_(c, "error.err_access_denied")
case errors.Is(err, ErrFolderDoesNotExist):
return i18n.T_(c, "error.folder_does_not_exist")
return i18n.T_(c, "error.err_folder_does_not_exist")
case errors.Is(err, ErrFileDoesNotExist):
return i18n.T_(c, "error.file_does_not_exist")
return i18n.T_(c, "error.err_file_does_not_exist")
case errors.Is(err, ErrNameTaken):
return i18n.T_(c, "error.name_taken")
return i18n.T_(c, "error.err_name_taken")
case errors.Is(err, ErrMissingFileFieldDocument):
return i18n.T_(c, "error.missing_file_field_document")
return i18n.T_(c, "error.err_missing_file_field_document")
case errors.Is(err, ErrJSONBody):
return i18n.T_(c, "error.err_json_body")
case errors.Is(err, ErrMaxAmtOfAddressesReached):
return i18n.T_(c, "error.err_max_amt_of_addresses_reached")
case errors.Is(err, ErrUserHasNoSuchAddress):
return i18n.T_(c, "error.err_user_has_no_such_address")
case errors.Is(err, ErrInvalidCountryID):
return i18n.T_(c, "error.err_invalid_country_id")
case errors.Is(err, ErrInvalidAddressJSON):
return i18n.T_(c, "error.err_invalid_address_json")
default:
return i18n.T_(c, "error.err_internal_server_error")
}
@@ -246,7 +261,11 @@ func GetErrorStatus(err error) int {
errors.Is(err, ErrFileDoesNotExist),
errors.Is(err, ErrNameTaken),
errors.Is(err, ErrMissingFileFieldDocument),
errors.Is(err, ErrJSONBody):
errors.Is(err, ErrJSONBody),
errors.Is(err, ErrMaxAmtOfAddressesReached),
errors.Is(err, ErrUserHasNoSuchAddress),
errors.Is(err, ErrInvalidCountryID),
errors.Is(err, ErrInvalidAddressJSON):
return fiber.StatusBadRequest
case errors.Is(err, ErrEmailExists):
return fiber.StatusConflict