Documentation
¶
Index ¶
- Constants
- Variables
- func CheckInventoryOwnership(ctx context.Context, id uint, userID uint) (bool, error)
- func DeleteInventoryByID(c *gin.Context)
- func DeleteMyInventoryByID(c *gin.Context)
- func FindItemIDByItemName(inventories Inventories, itemname string) uint
- func GetInventories(c *gin.Context)
- func GetInventoryByID(c *gin.Context)
- func GetMyInventory(c *gin.Context)
- func GetMyInventoryByID(c *gin.Context)
- func InsertInventory(ctx context.Context, i *Inventory) error
- func PostInventory(c *gin.Context)
- func PostMyInventory(c *gin.Context)
- func PutInventoryByID(c *gin.Context)
- func PutMyInventoryByID(c *gin.Context)
- type Inventories
- type Inventory
- type InventoryCreateAdminRequest
- type InventoryCreateRequest
- type InventoryUpdateRequest
Constants ¶
const DefaultCurrency = "EUR"
DefaultCurrency is the default currency used when none is specified This matches the database default value in the Currency enum
Variables ¶
var ErrNoItemFound = errors.New("no item found")
ErrNoItemFound is returned when no item is found for a given request.
Functions ¶
func CheckInventoryOwnership ¶ added in v1.3.0
CheckInventoryOwnership verifies if an inventory item belongs to a specific user. Returns true if the item belongs to the user, false otherwise.
func DeleteInventoryByID ¶
DeleteInventoryByID deletes an inventory by ID @Summary [ADMIN] Delete an inventory by ID @Description Deletes an inventory by ID - for admin use only @Security Bearer @Tags Internal @Produce json @Param id path int true "Inventory ID" @Success 200 {object} apitypes.OkResponse "Inventory deleted" @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/inventories/{id} [delete]
func DeleteMyInventoryByID ¶
DeleteMyInventoryByID deletes an inventory by ID @Summary Delete an inventory by ID @Description Deletes an inventory by ID @Security Bearer @Tags Inventories @Produce json @Param id path int true "Inventory ID" @Success 200 {object} apitypes.OkResponse "Inventory deleted" @Failure 400 {object} apitypes.ErrorResponse "Invalid ID format" @Failure 401 {object} apitypes.ErrorResponse "Unauthorized" @Failure 403 {object} apitypes.ErrorResponse "This item does not belong to you" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /v1/myinventory/{id} [delete]
func FindItemIDByItemName ¶ added in v0.15.0
func FindItemIDByItemName(inventories Inventories, itemname string) uint
FindItemIDByItemName finds an inventory item ID by its name Returns 0 if not found
func GetInventories ¶
GetInventories gets all inventories @Summary [ADMIN] Get all inventories @Description Retrieves a list of all inventories - for admin use only @Security Bearer @Tags Internal @Produce json @Success 200 {object} inventories.Inventories "List of Inventories" @Failure 404 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/inventories [get]
func GetInventoryByID ¶
GetInventoryByID gets an inventory by ID @Summary [ADMIN] Get an inventory by ID @Description Retrieves an inventory by ID - for admin use only @Security Bearer @Tags Internal @Produce json @Param id path int true "Inventory ID" @Success 200 {object} inventories.Inventory @Failure 400 {object} apitypes.ErrorResponse @Failure 404 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/inventories/{id} [get]
func GetMyInventory ¶
GetMyInventory gets all inventories of the user @Summary Get all inventories of the user @Description Retrieves a list of all inventories of the user @Security Bearer @Tags Inventories @Produce json @Success 200 {object} inventories.Inventories @Failure 401 {object} apitypes.ErrorResponse "Unauthorized" @Failure 404 {object} apitypes.ErrorResponse "No Inventory Found" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /v1/myinventory [get]
func GetMyInventoryByID ¶
GetMyInventoryByID gets an inventory by ID @Summary Get an inventory by ID @Description Retrieves an inventory by ID @Security Bearer @Tags Inventories @Produce json @Param id path int true "Inventory ID" @Success 200 {object} inventories.Inventory "Inventory" @Failure 401 {object} apitypes.ErrorResponse "Unauthorized" @Failure 403 {object} apitypes.ErrorResponse "This item does not belong to you" @Failure 404 {object} apitypes.ErrorResponse "Inventory not found" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /v1/myinventory/{id} [get]
func InsertInventory ¶
InsertInventory creates a new inventory item with timestamps
func PostInventory ¶
PostInventory creates an inventory @Summary [ADMIN] Create an inventory @Description Creates an inventory - for admin use only @Security Bearer @Tags Internal @Accept json @Produce json @Param inventory body inventories.Inventory true "Inventory" @Success 201 {object} inventories.Inventory @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/inventories [post]
func PostMyInventory ¶
PostMyInventory creates an inventory @Summary Create an inventory @Description Creates an inventory @Security Bearer @Tags Inventories @Accept json @Produce json @Param inventory body inventories.InventoryCreateRequest true "Inventory" @Success 201 {object} inventories.Inventory "Inventory Updated" @Failure 400 {object} apitypes.ErrorResponse "Invalid payload" @Failure 401 {object} apitypes.ErrorResponse "Unauthorized" @Failure 500 {object} apitypes.ErrorResponse "Internal Server Error" @Router /v1/myinventory [post]
func PutInventoryByID ¶
PutInventoryByID updates an inventory by ID @Summary [ADMIN] Update an inventory by ID @Description Updates an inventory by ID - for admin use only @Security Bearer @Tags Internal @Accept json @Produce json @Param id path int true "Inventory ID" @Param inventory body inventories.InventoryUpdateRequest true "Inventory" @Success 200 {object} inventories.Inventory @Failure 400 {object} apitypes.ErrorResponse @Failure 400 {object} apitypes.ErrorResponse @Failure 500 {object} apitypes.ErrorResponse @Router /admin/inventories/{id} [put]
func PutMyInventoryByID ¶
PutMyInventoryByID updates an inventory by ID @Summary Update an inventory by ID @Description Updates an inventory by ID @Security Bearer @Tags Inventories @Accept json @Produce json @Param id path int true "Inventory ID" @Param inventory body inventories.InventoryUpdateRequest true "Inventory" @Success 200 {object} inventories.Inventory "Inventory Updated" @Failure 400 {object} map[string]interface{} "Invalid ID format" @Failure 400 {object} map[string]interface{} "Invalid payload" @Failure 401 {object} map[string]interface{} "Unauthorized" @Failure 403 {object} map[string]interface{} "This item does not belong to you" @Failure 500 {object} map[string]interface{} "Internal Server Error" @Router /v1/myinventory/{id} [put]
Types ¶
type Inventories ¶ added in v0.15.0
type Inventories []Inventory
Inventories represents a collection of inventory items
type Inventory ¶ added in v0.15.0
type Inventory struct {
ID uint `json:"id"`
UserID uint `json:"user_id"`
ItemName string `json:"item_name"`
Category string `json:"category"`
Description string `json:"description"`
Weight int `json:"weight"`
URL string `json:"url"`
Price int `json:"price"`
Currency string `json:"currency"`
HasImage bool `json:"has_image"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Inventory represents an item in a user's inventory
func FindInventoryByID ¶ added in v1.3.0
FindInventoryByID retrieves a single inventory item by ID. Returns the item if found, nil with ErrNoItemFound if not found, or error if query fails.
func FindInventoryItemByAttributes ¶ added in v0.13.0
func FindInventoryItemByAttributes( ctx context.Context, userID uint, itemName, category, description string, ) (*Inventory, error)
FindInventoryItemByAttributes finds an existing inventory item for a user by exact match on item_name, category, and description. Returns the item if found, nil with ErrNoItemFound if not found, or error if query fails.
type InventoryCreateAdminRequest ¶ added in v1.0.0
type InventoryCreateAdminRequest struct {
UserID uint `json:"user_id" binding:"required"`
ItemName string `json:"item_name" binding:"required"`
Category string `json:"category" binding:"required"`
Description string `json:"description"`
Weight int `json:"weight"`
URL string `json:"url"`
Price int `json:"price"`
Currency string `json:"currency"`
}
InventoryCreateAdminRequest represents the input for creating an inventory item (admin endpoint)
type InventoryCreateRequest ¶ added in v1.0.0
type InventoryCreateRequest struct {
ItemName string `json:"item_name" binding:"required"`
Category string `json:"category" binding:"required"`
Description string `json:"description"`
Weight int `json:"weight"`
URL string `json:"url"`
Price int `json:"price"`
Currency string `json:"currency"`
}
InventoryCreateRequest represents the input for creating an inventory item (user endpoint)
type InventoryUpdateRequest ¶ added in v1.0.0
type InventoryUpdateRequest struct {
ItemName string `json:"item_name" binding:"required"`
Category string `json:"category" binding:"required"`
Description string `json:"description"`
Weight int `json:"weight"`
URL string `json:"url"`
Price int `json:"price"`
Currency string `json:"currency"`
}
InventoryUpdateRequest represents the input for updating an inventory item