Update API

This commit is contained in:
2025-06-22 23:23:26 +07:00
parent b077ef9f06
commit 40705fbf3b
63 changed files with 1976 additions and 81 deletions
@@ -0,0 +1,33 @@
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
}
@@ -0,0 +1,33 @@
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
}
@@ -0,0 +1,38 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type ProductRepository struct {
DB *gorm.DB
}
func NewProductRepository(db *gorm.DB) *ProductRepository {
return &ProductRepository{DB: db}
}
func (r *ProductRepository) FindAll() ([]models.Product, error) {
var products []models.Product
err := r.DB.
Preload("Category").
Preload("Collection").
Preload("Colour").
Preload("Size").
Find(&products).Error
return products, err
}
func (r *ProductRepository) Create(product *models.Product) error {
return r.DB.Create(product).Error
}
func (r *ProductRepository) Update(id uint, product *models.Product) error {
return r.DB.Model(&models.Product{}).Where("id = ?", id).Updates(product).Error
}
func (r *ProductRepository) Delete(id uint) error {
return r.DB.Delete(&models.Product{}, id).Error
}
@@ -0,0 +1,33 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type CategoryRepository struct {
DB *gorm.DB
}
func NewCategoryRepository(db *gorm.DB) *CategoryRepository {
return &CategoryRepository{DB: db}
}
func (r *CategoryRepository) FindAll() ([]models.ProductCategory, error) {
var categories []models.ProductCategory
err := r.DB.Find(&categories).Error
return categories, err
}
func (r *CategoryRepository) Create(cat *models.ProductCategory) error {
return r.DB.Create(cat).Error
}
func (r *CategoryRepository) Update(id uint, data *models.ProductCategory) error {
return r.DB.Model(&models.ProductCategory{}).Where("id = ?", id).Updates(data).Error
}
func (r *CategoryRepository) Delete(id uint) error {
return r.DB.Delete(&models.ProductCategory{}, id).Error
}
@@ -0,0 +1,32 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type ProductComponentRepository struct {
DB *gorm.DB
}
func NewProductComponentRepository(db *gorm.DB) *ProductComponentRepository {
return &ProductComponentRepository{DB: db}
}
func (r *ProductComponentRepository) FindAll() ([]models.ProductComponent, error) {
var data []models.ProductComponent
err := r.DB.
Preload("Product").
Preload("Component").
Find(&data).Error
return data, err
}
func (r *ProductComponentRepository) Create(pc *models.ProductComponent) error {
return r.DB.Create(pc).Error
}
func (r *ProductComponentRepository) Delete(id uint) error {
return r.DB.Delete(&models.ProductComponent{}, id).Error
}
@@ -0,0 +1,33 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type ProductionOrderRepository struct {
DB *gorm.DB
}
func NewProductionOrderRepository(db *gorm.DB) *ProductionOrderRepository {
return &ProductionOrderRepository{DB: db}
}
func (r *ProductionOrderRepository) FindAll() ([]models.ProductionOrder, error) {
var orders []models.ProductionOrder
err := r.DB.Preload("Product").Find(&orders).Error
return orders, err
}
func (r *ProductionOrderRepository) Create(order *models.ProductionOrder) error {
return r.DB.Create(order).Error
}
func (r *ProductionOrderRepository) Update(id uint, data *models.ProductionOrder) error {
return r.DB.Model(&models.ProductionOrder{}).Where("id = ?", id).Updates(data).Error
}
func (r *ProductionOrderRepository) Delete(id uint) error {
return r.DB.Delete(&models.ProductionOrder{}, id).Error
}
+33
View File
@@ -0,0 +1,33 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type SizeRepository struct {
DB *gorm.DB
}
func NewSizeRepository(db *gorm.DB) *SizeRepository {
return &SizeRepository{DB: db}
}
func (r *SizeRepository) FindAll() ([]models.Size, error) {
var sizes []models.Size
err := r.DB.Find(&sizes).Error
return sizes, err
}
func (r *SizeRepository) Create(size *models.Size) error {
return r.DB.Create(size).Error
}
func (r *SizeRepository) Update(id uint, data *models.Size) error {
return r.DB.Model(&models.Size{}).Where("id = ?", id).Updates(data).Error
}
func (r *SizeRepository) Delete(id uint) error {
return r.DB.Delete(&models.Size{}, id).Error
}
@@ -0,0 +1,29 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type StockMovementRepository struct {
DB *gorm.DB
}
func NewStockMovementRepository(db *gorm.DB) *StockMovementRepository {
return &StockMovementRepository{DB: db}
}
func (r *StockMovementRepository) FindAll() ([]models.StockMovement, error) {
var movements []models.StockMovement
err := r.DB.
Preload("Product").
Preload("OriginWarehouse").
Preload("DestinationWarehouse").
Find(&movements).Error
return movements, err
}
func (r *StockMovementRepository) Create(movement *models.StockMovement) error {
return r.DB.Create(movement).Error
}
@@ -0,0 +1,33 @@
package repository
import (
"BE-MiniERP/modules/inventory/models"
"gorm.io/gorm"
)
type WarehouseRepository struct {
DB *gorm.DB
}
func NewWarehouseRepository(db *gorm.DB) *WarehouseRepository {
return &WarehouseRepository{DB: db}
}
func (r *WarehouseRepository) FindAll() ([]models.Warehouse, error) {
var warehouses []models.Warehouse
err := r.DB.Find(&warehouses).Error
return warehouses, err
}
func (r *WarehouseRepository) Create(wh *models.Warehouse) error {
return r.DB.Create(wh).Error
}
func (r *WarehouseRepository) Update(id uint, wh *models.Warehouse) error {
return r.DB.Model(&models.Warehouse{}).Where("id = ?", id).Updates(wh).Error
}
func (r *WarehouseRepository) Delete(id uint) error {
return r.DB.Delete(&models.Warehouse{}, id).Error
}