inventories

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCurrency = "EUR"

DefaultCurrency is the default currency used when none is specified This matches the database default value in the Currency enum

Variables

View Source
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

func CheckInventoryOwnership(ctx context.Context, id uint, userID uint) (bool, error)

CheckInventoryOwnership verifies if an inventory item belongs to a specific user. Returns true if the item belongs to the user, false otherwise.

func DeleteInventoryByID

func DeleteInventoryByID(c *gin.Context)

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

func DeleteMyInventoryByID(c *gin.Context)

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

func GetInventories(c *gin.Context)

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

func GetInventoryByID(c *gin.Context)

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

func GetMyInventory(c *gin.Context)

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

func GetMyInventoryByID(c *gin.Context)

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

func InsertInventory(ctx context.Context, i *Inventory) error

InsertInventory creates a new inventory item with timestamps

func PostInventory

func PostInventory(c *gin.Context)

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

func PostMyInventory(c *gin.Context)

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

func PutInventoryByID(c *gin.Context)

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

func PutMyInventoryByID(c *gin.Context)

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

func FindInventoryByID(ctx context.Context, id uint) (*Inventory, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL