repository

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 7 Imported by: 0

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

View Source
const CategoryTableName = "categories"
View Source
const ProductTableName = "products"

Variables

View Source
var ErrCategoryNotFound = errors.New("category not found")
View Source
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

func (r *NewRepository) CreateProduct(ctx context.Context, product *model.Product) (err error)

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

func (r *NewRepository) GetCategoryByID(ctx context.Context, id int) (*model.Category, error)

GetCategoryByID retrieves a category by its ID from the database. It returns the category or an error if not found.

func (*NewRepository) GetProductDetail

func (r *NewRepository) GetProductDetail(ctx context.Context, id int) (product *model.Product, err error)

func (*NewRepository) UpdateCategory

func (r *NewRepository) UpdateCategory(ctx context.Context, id int, category *model.Category) error

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.

Directories

Path Synopsis
Package model provides data structures for database entities.
Package model provides data structures for database entities.

Jump to

Keyboard shortcuts

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