BE-MiniERP/modules/inventory/repository/collection_repo.go
2025-06-22 23:23:26 +07:00

34 lines
798 B
Go

package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type CollectionRepository struct {
DB *gorm.DB
}
func NewCollectionRepository(db *gorm.DB) *CollectionRepository {
return &CollectionRepository{DB: db}
}
func (r *CollectionRepository) FindAll() ([]models.Collection, error) {
var collections []models.Collection
err := r.DB.Find(&collections).Error
return collections, err
}
func (r *CollectionRepository) Create(col *models.Collection) error {
return r.DB.Create(col).Error
}
func (r *CollectionRepository) Update(id uint, data *models.Collection) error {
return r.DB.Model(&models.Collection{}).Where("id = ?", id).Updates(data).Error
}
func (r *CollectionRepository) Delete(id uint) error {
return r.DB.Delete(&models.Collection{}, id).Error
}