feat(BE-115,116,117): implement chickin CRUD, approve logic, and stock availabilit

This commit is contained in:
aguhh18
2025-10-20 06:01:16 +07:00
parent 68a670a2bd
commit 83c3e61113
34 changed files with 558 additions and 199 deletions
@@ -0,0 +1,21 @@
package repository
import (
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
)
type AuditLogRepository interface {
repository.BaseRepository[entity.AuditLog]
}
type AuditLogRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.AuditLog]
}
func NewAuditLogRepository(db *gorm.DB) AuditLogRepository {
return &AuditLogRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.AuditLog](db),
}
}
@@ -0,0 +1,21 @@
package repository
import (
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
)
type StockAvailabilityRepository interface {
repository.BaseRepository[entity.StockAvailability]
}
type StockAvailabilityRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.StockAvailability]
}
func NewStockAvailabilityRepository(db *gorm.DB) StockAvailabilityRepository {
return &StockAvailabilityRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.StockAvailability](db),
}
}
@@ -0,0 +1,88 @@
package repository
import (
"context"
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
"gorm.io/gorm"
)
type StockLogRepository interface {
repository.BaseRepository[entity.StockLog]
GetByFlaggable(ctx context.Context, logType string, logId uint) ([]*entity.StockLog, error)
GetByProductWarehouse(ctx context.Context, productWarehouseId uint, limit int) ([]*entity.StockLog, error)
GetByTransactionType(ctx context.Context, transactionType string, limit int) ([]*entity.StockLog, error)
}
type StockLogRepositoryImpl struct {
*repository.BaseRepositoryImpl[entity.StockLog]
}
func NewStockLogRepository(db *gorm.DB) StockLogRepository {
return &StockLogRepositoryImpl{
BaseRepositoryImpl: repository.NewBaseRepository[entity.StockLog](db),
}
}
func (r *StockLogRepositoryImpl) GetByFlaggable(ctx context.Context, logType string, logId uint) ([]*entity.StockLog, error) {
var stockLogs []*entity.StockLog
err := r.DB().WithContext(ctx).
Where("log_type = ? AND log_id = ?", logType, logId).
Preload("ProductWarehouse").
Preload("ProductWarehouse.Product").
Preload("ProductWarehouse.Warehouse").
Order("created_at DESC").
Find(&stockLogs).Error
if err != nil {
return nil, err
}
return stockLogs, nil
}
func (r *StockLogRepositoryImpl) GetByProductWarehouse(ctx context.Context, productWarehouseId uint, limit int) ([]*entity.StockLog, error) {
var stockLogs []*entity.StockLog
query := r.DB().WithContext(ctx).
Where("product_warehouse_id = ?", productWarehouseId).
Preload("ProductWarehouse").
Preload("ProductWarehouse.Product").
Preload("ProductWarehouse.Warehouse").
Order("created_at DESC")
if limit > 0 {
query = query.Limit(limit)
}
err := query.Find(&stockLogs).Error
if err != nil {
return nil, err
}
return stockLogs, nil
}
func (r *StockLogRepositoryImpl) GetByTransactionType(ctx context.Context, transactionType string, limit int) ([]*entity.StockLog, error) {
var stockLogs []*entity.StockLog
query := r.DB().WithContext(ctx).
Where("transaction_type = ?", transactionType).
Preload("ProductWarehouse").
Preload("ProductWarehouse.Product").
Preload("ProductWarehouse.Warehouse").
Order("created_at DESC")
if limit > 0 {
query = query.Limit(limit)
}
err := query.Find(&stockLogs).Error
if err != nil {
return nil, err
}
return stockLogs, nil
}