mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-115,116,117): implement chickin CRUD, approve logic, and stock availabilit
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user