-feat 修复部分bug
This commit is contained in:
@@ -24,6 +24,7 @@ type TransactionFilter struct {
|
||||
// Entity filters
|
||||
CategoryID *uint
|
||||
AccountID *uint
|
||||
LedgerID *uint // 账本过滤
|
||||
TagIDs []uint
|
||||
Type *models.TransactionType
|
||||
Currency *models.Currency
|
||||
@@ -277,6 +278,13 @@ func (r *TransactionRepository) applyFilters(query *gorm.DB, filter TransactionF
|
||||
if filter.RecurringID != nil {
|
||||
query = query.Where("recurring_id = ?", *filter.RecurringID)
|
||||
}
|
||||
// LedgerID filter - requires subquery to get accounts belonging to the ledger
|
||||
if filter.LedgerID != nil {
|
||||
query = query.Where("account_id IN (?)",
|
||||
r.db.Model(&models.Account{}).
|
||||
Select("id").
|
||||
Where("ledger_id = ?", *filter.LedgerID))
|
||||
}
|
||||
// UserID provided in argument takes precedence, but if filter has it, we can redundant check or ignore.
|
||||
// The caller `List` already applied `Where("user_id = ?", userID)`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user