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