Update API
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/sales/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type CustomerRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewCustomerRepository(db *gorm.DB) *CustomerRepository {
|
||||
return &CustomerRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *CustomerRepository) FindAll() ([]models.Customer, error) {
|
||||
var customers []models.Customer
|
||||
err := r.DB.Find(&customers).Error
|
||||
return customers, err
|
||||
}
|
||||
|
||||
func (r *CustomerRepository) Create(customer *models.Customer) error {
|
||||
return r.DB.Create(customer).Error
|
||||
}
|
||||
|
||||
func (r *CustomerRepository) Update(id uint, data *models.Customer) error {
|
||||
return r.DB.Model(&models.Customer{}).Where("id = ?", id).Updates(data).Error
|
||||
}
|
||||
|
||||
func (r *CustomerRepository) Delete(id uint) error {
|
||||
return r.DB.Delete(&models.Customer{}, id).Error
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/sales/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type InvoiceLineRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewInvoiceLineRepository(db *gorm.DB) *InvoiceLineRepository {
|
||||
return &InvoiceLineRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *InvoiceLineRepository) FindAll() ([]models.InvoiceLine, error) {
|
||||
var result []models.InvoiceLine
|
||||
err := r.DB.Find(&result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *InvoiceLineRepository) Create(data *models.InvoiceLine) error {
|
||||
return r.DB.Create(data).Error
|
||||
}
|
||||
|
||||
func (r *InvoiceLineRepository) Update(id uint, data *models.InvoiceLine) error {
|
||||
return r.DB.Model(&models.InvoiceLine{}).Where("id = ?", id).Updates(data).Error
|
||||
}
|
||||
|
||||
func (r *InvoiceLineRepository) Delete(id uint) error {
|
||||
return r.DB.Delete(&models.InvoiceLine{}, id).Error
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/sales/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type PaymentRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewPaymentRepository(db *gorm.DB) *PaymentRepository {
|
||||
return &PaymentRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *PaymentRepository) FindAll() ([]models.Payment, error) {
|
||||
var result []models.Payment
|
||||
err := r.DB.Find(&result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *PaymentRepository) Create(data *models.Payment) error {
|
||||
return r.DB.Create(data).Error
|
||||
}
|
||||
|
||||
func (r *PaymentRepository) Update(id uint, data *models.Payment) error {
|
||||
return r.DB.Model(&models.Payment{}).Where("id = ?", id).Updates(data).Error
|
||||
}
|
||||
|
||||
func (r *PaymentRepository) Delete(id uint) error {
|
||||
return r.DB.Delete(&models.Payment{}, id).Error
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/sales/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SalesOrderItemRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewSalesOrderItemRepository(db *gorm.DB) *SalesOrderItemRepository {
|
||||
return &SalesOrderItemRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *SalesOrderItemRepository) FindAll() ([]models.SalesOrderItem, error) {
|
||||
var result []models.SalesOrderItem
|
||||
err := r.DB.Find(&result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *SalesOrderItemRepository) Create(data *models.SalesOrderItem) error {
|
||||
return r.DB.Create(data).Error
|
||||
}
|
||||
|
||||
func (r *SalesOrderItemRepository) Update(id uint, data *models.SalesOrderItem) error {
|
||||
return r.DB.Model(&models.SalesOrderItem{}).Where("id = ?", id).Updates(data).Error
|
||||
}
|
||||
|
||||
func (r *SalesOrderItemRepository) Delete(id uint) error {
|
||||
return r.DB.Delete(&models.SalesOrderItem{}, id).Error
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"BE-MiniERP/modules/sales/models"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type SalesOrderRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewSalesOrderRepository(db *gorm.DB) *SalesOrderRepository {
|
||||
return &SalesOrderRepository{DB: db}
|
||||
}
|
||||
|
||||
func (r *SalesOrderRepository) FindAll() ([]models.SalesOrder, error) {
|
||||
var result []models.SalesOrder
|
||||
err := r.DB.Find(&result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *SalesOrderRepository) Create(data *models.SalesOrder) error {
|
||||
return r.DB.Create(data).Error
|
||||
}
|
||||
|
||||
func (r *SalesOrderRepository) Update(id uint, data *models.SalesOrder) error {
|
||||
return r.DB.Model(&models.SalesOrder{}).Where("id = ?", id).Updates(data).Error
|
||||
}
|
||||
|
||||
func (r *SalesOrderRepository) Delete(id uint) error {
|
||||
return r.DB.Delete(&models.SalesOrder{}, id).Error
|
||||
}
|
||||
Reference in New Issue
Block a user