Documentation
¶
Overview ¶
Package repository provides data access layer for the application. It includes database operations for categories, products, and other entities.
Package repository provides data access layer for the application. It includes database operations for categories, products, and other entities.
Package repository provides data access layer for the application. It includes database operations for categories, products, and other entities.
Index ¶
- Constants
- Variables
- type CategoryRepository
- type DBRepository
- type NewRepository
- func (r *NewRepository) CreateCategory(ctx context.Context, category *model.Category) (int64, error)
- func (r *NewRepository) CreateProduct(ctx context.Context, product *model.Product) (err error)
- func (r *NewRepository) DeleteCategory(ctx context.Context, id int) error
- func (r *NewRepository) DeleteProduct(ctx context.Context, id int) (err error)
- func (r *NewRepository) GetCategoryByID(ctx context.Context, id int) (*model.Category, error)
- func (r *NewRepository) GetProductDetail(ctx context.Context, id int) (product *model.Product, err error)
- func (r *NewRepository) UpdateCategory(ctx context.Context, id int, category *model.Category) error
- func (r *NewRepository) UpdateProduct(ctx context.Context, pid int, product *model.Product) (err error)
- type ProductRepository
Constants ¶
const CategoryTableName = "categories"
const ProductTableName = "products"
Variables ¶
var ErrCategoryNotFound = errors.New("category not found")
var ErrProductNotFound = errors.New("product not found")
Functions ¶
This section is empty.
Types ¶
type CategoryRepository ¶
type CategoryRepository interface { CreateCategory(ctx context.Context, category *model.Category) (int64, error) GetCategoryByID(ctx context.Context, id int) (*model.Category, error) UpdateCategory(ctx context.Context, id int, category *model.Category) error DeleteCategory(ctx context.Context, id int) error }
type DBRepository ¶
type DBRepository interface { // Product Repository ProductRepository // Category Repository CategoryRepository }
func NewDBRepository ¶
func NewDBRepository(db *database.Database) DBRepository
NewDBRepository creates a new instance of the DBRepository interface using the provided database. The returned DBRepository implementation is the NewRepository struct, which wraps the provided database.
type NewRepository ¶
type NewRepository struct {
// contains filtered or unexported fields
}
func (*NewRepository) CreateCategory ¶
func (r *NewRepository) CreateCategory(ctx context.Context, category *model.Category) (int64, error)
CreateCategory creates a new category in the database. It returns the ID of the created category or an error.
func (*NewRepository) CreateProduct ¶
CreateProduct creates a new product in the database using the provided product data. It returns an error if the creation fails.
func (*NewRepository) DeleteCategory ¶
func (r *NewRepository) DeleteCategory(ctx context.Context, id int) error
DeleteCategory removes a category from the database by its ID. It returns an error if the deletion fails.
func (*NewRepository) DeleteProduct ¶
func (r *NewRepository) DeleteProduct(ctx context.Context, id int) (err error)
DeleteProduct deletes a product from the database by the given ID. It returns an error if the deletion fails.
func (*NewRepository) GetCategoryByID ¶
GetCategoryByID retrieves a category by its ID from the database. It returns the category or an error if not found.
func (*NewRepository) GetProductDetail ¶
func (*NewRepository) UpdateCategory ¶
UpdateCategory updates an existing category in the database. It returns an error if the update fails.
func (*NewRepository) UpdateProduct ¶
func (r *NewRepository) UpdateProduct(ctx context.Context, pid int, product *model.Product) (err error)
UpdateProduct updates an existing product in the database with the provided product data. It returns an error if the update fails.
type ProductRepository ¶
type ProductRepository interface { GetProductDetail(ctx context.Context, id int) (product *model.Product, err error) CreateProduct(ctx context.Context, product *model.Product) (err error) UpdateProduct(ctx context.Context, pid int, product *model.Product) (err error) DeleteProduct(ctx context.Context, id int) (err error) }
ProductRepository defines the methods for interacting with the product repository. The methods allow for retrieving product details, creating new products, updating existing products, and deleting products.