34 lines
736 B
Go
34 lines
736 B
Go
package repository
|
|
|
|
import (
|
|
"BE-MiniERP/modules/inventory/models"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ColourRepository struct {
|
|
DB *gorm.DB
|
|
}
|
|
|
|
func NewColourRepository(db *gorm.DB) *ColourRepository {
|
|
return &ColourRepository{DB: db}
|
|
}
|
|
|
|
func (r *ColourRepository) FindAll() ([]models.Colour, error) {
|
|
var colours []models.Colour
|
|
err := r.DB.Find(&colours).Error
|
|
return colours, err
|
|
}
|
|
|
|
func (r *ColourRepository) Create(colour *models.Colour) error {
|
|
return r.DB.Create(colour).Error
|
|
}
|
|
|
|
func (r *ColourRepository) Update(id uint, data *models.Colour) error {
|
|
return r.DB.Model(&models.Colour{}).Where("id = ?", id).Updates(data).Error
|
|
}
|
|
|
|
func (r *ColourRepository) Delete(id uint) error {
|
|
return r.DB.Delete(&models.Colour{}, id).Error
|
|
}
|