Documentation ¶
Index ¶
- Variables
- func NewPostgresRepository(ctx context.Context, db *sqlx.DB, log zerolog.Logger) *postgresRepository
- type Category
- type Operations
- type PaginationResult
- type Product
- type Repository
- type Service
- func (s *Service) CreateCategory(ctx context.Context, data *Category) (*Category, error)
- func (s *Service) CreateProduct(ctx context.Context, data *Product) (*Product, error)
- func (s *Service) DeleteProduct(ctx context.Context, id int) error
- func (s *Service) GetCategory(ctx context.Context, id int) (*Category, error)
- func (s *Service) GetProduct(ctx context.Context, id int) (*Product, error)
- func (s *Service) ListCategories(ctx context.Context, limit int, offset int) (*PaginationResult[*Category], error)
- func (s *Service) ListProducts(ctx context.Context, limit int, offset int) (*PaginationResult[*Product], error)
- func (s *Service) SearchCategoriesByName(ctx context.Context, searchTerm string) ([]*Category, error)
- func (s *Service) SearchProductsByName(ctx context.Context, searchTerm string) ([]*Product, error)
- func (s *Service) UpdateCategory(ctx context.Context, id int, data *Category) (*Category, error)
- func (s *Service) UpdateProduct(ctx context.Context, id int, data *Product) (*Product, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotExist = errors.New("resource does not exist")
Functions ¶
Types ¶
type Category ¶
type Operations ¶
type Operations interface { GetProduct(tx context.Context, id int) (*Product, error) CreateProduct(tx context.Context, data *Product) (*Product, error) ListProducts(tx context.Context, limit int, offset int) (*PaginationResult[*Product], error) UpdateProduct(tx context.Context, id int, data *Product) (*Product, error) DeleteProduct(tx context.Context, id int) error SearchProductsByName(ctx context.Context, searchTerm string) ([]*Product, error) GetCategory(ctx context.Context, id int) (*Category, error) CreateCategory(ctx context.Context, data *Category) (*Category, error) ListCategories(ctx context.Context, limit int, offset int) (*PaginationResult[*Category], error) UpdateCategory(ctx context.Context, id int, data *Category) (*Category, error) SearchCategoriesByName(ctx context.Context, searchTerm string) ([]*Category, error) }
type PaginationResult ¶
type Product ¶
type Product struct { ID int `json:"id"` Name string `json:"name" validate:"required"` Description string `json:"description"` Price float32 `json:"price" db:"price" validate:"gt=0"` SKU string `json:"sku" db:"sku" validate:"required,len=5"` ImageURL string `json:"image_url" db:"image_url"` CategoryID int `json:"category_id" db:"category_id" validate:"required"` CreatedAt time.Time `json:"created_at,omitempty" db:"created_at"` UpdatedAt time.Time `json:"updated_at,omitempty" db:"updated_at"` DeletedAt string `json:"deleted_at,omitempty" db:"deleted_at"` }
type Repository ¶
type Repository interface { GetProductByID(ctx context.Context, id int) (*Product, error) GetAllProducts(ctx context.Context, limit int, offset int) ([]*Product, error) CreateProduct(ctx context.Context, p *Product) (*Product, error) UpdateProduct(ctx context.Context, p *Product) (*Product, error) GetProductsByCategory(ctx context.Context, categoryID int) ([]*Product, error) DeleteProduct(ctx context.Context, id int) error CountProducts(ctx context.Context) (int, error) SearchProductsByName(ctx context.Context, searchTerm string) ([]*Product, error) GetCategoryByID(ctx context.Context, id int) (*Category, error) GetAllCategories(ctx context.Context, limit, offset int) ([]*Category, error) CreateCategory(ctx context.Context, name string) (*Category, error) UpdateCategory(ctx context.Context, id int, name string) (*Category, error) SearchCategoriesByName(ctx context.Context, searchTerm string) ([]*Category, error) CountCategories(ctx context.Context) (int, error) }
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo Repository) *Service
func (*Service) CreateCategory ¶
func (*Service) CreateProduct ¶
func (*Service) GetCategory ¶
func (*Service) GetProduct ¶
func (*Service) ListCategories ¶
func (*Service) ListProducts ¶
func (*Service) SearchCategoriesByName ¶
func (*Service) SearchProductsByName ¶
func (*Service) UpdateCategory ¶
Click to show internal directories.
Click to hide internal directories.