Update Tranaction
This commit is contained in:
@@ -208,6 +208,8 @@ type License interface {
|
||||
}
|
||||
|
||||
type TransactionRepository interface {
|
||||
FindByID(ctx context.Context, id string) (*entity.Transaction, error)
|
||||
Create(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error)
|
||||
GetTransactionList(ctx mycontext.Context, req entity.TransactionSearch) ([]*entity.TransactionList, int, error)
|
||||
Update(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error)
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ func (r *TransactionRepository) Create(ctx context.Context, trx *gorm.DB, transa
|
||||
}
|
||||
|
||||
// Update updates an existing transaction in the database.
|
||||
func (r *TransactionRepository) Update(ctx context.Context, transaction *entity.Transaction) (*entity.Transaction, error) {
|
||||
if err := r.db.WithContext(ctx).Save(transaction).Error; err != nil {
|
||||
func (r *TransactionRepository) Update(ctx context.Context, trx *gorm.DB, transaction *entity.Transaction) (*entity.Transaction, error) {
|
||||
if err := trx.WithContext(ctx).Save(transaction).Error; err != nil {
|
||||
zap.L().Error("error when updating transaction", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
@@ -137,22 +137,30 @@ func (r *TransactionRepository) GetTransactionList(ctx mycontext.Context, req en
|
||||
query := r.db.Table("transactions t").
|
||||
Select("t.id, t.transaction_type, t.status, t.created_at, s.name as site_name, p.name as partner_name, t.amount").
|
||||
Joins("left join sites s on t.site_id = s.id").
|
||||
Joins("left join partners p on t.partner_id = p.id").
|
||||
Where("t.partner_id = ?", req.PartnerID)
|
||||
Joins("left join partners p on t.partner_id = p.id")
|
||||
|
||||
if req.SiteID != nil {
|
||||
query = query.Where("t.site_id = ?", req.SiteID)
|
||||
}
|
||||
|
||||
if req.Type != "" {
|
||||
query = query.Where("t.transaction_type = ?", req.Type)
|
||||
}
|
||||
|
||||
if req.Status != "" {
|
||||
query = query.Where("t.status = ?", req.Status)
|
||||
}
|
||||
|
||||
if req.Date != "" {
|
||||
query = query.Where("DATE(t.created_at) = ?", req.Date)
|
||||
}
|
||||
|
||||
if req.PartnerID != nil {
|
||||
query = query.Where("t.partner_id = ?", req.PartnerID)
|
||||
}
|
||||
|
||||
query = query.Order("t.created_at DESC")
|
||||
|
||||
query = query.Count(&total)
|
||||
|
||||
if req.Offset > 0 {
|
||||
|
||||
Reference in New Issue
Block a user