refactor: update data access layer to use GORM repositories

- Replace SQL-based queries with GORM repository calls
- Update all model interfaces to use repository pattern
- Fix compilation errors in core/model/ files
- Update mocks to match new repository interfaces
- Modify API handlers to use new repository layer
- Maintain backward compatibility with existing interfaces

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-06-30 22:08:08 +12:00
parent bd3f101fb4
commit 0d1cb22044
11 changed files with 524 additions and 204 deletions

View File

@@ -3,9 +3,10 @@ package model
import (
"errors"
"fmt"
"time"
"github.com/openaccounting/oa-server/core/model/types"
"github.com/openaccounting/oa-server/core/ws"
"time"
)
type TransactionInterface interface {
@@ -105,7 +106,7 @@ func (model *Model) GetTransactionsByAccount(orgId string, userId string, accoun
}
if !model.accountsContainWriteAccess(userAccounts, accountId) {
return nil, errors.New(fmt.Sprintf("%s %s", "user does not have permission to access account", accountId))
return nil, fmt.Errorf("%s %s", "user does not have permission to access account", accountId)
}
return model.db.GetTransactionsByAccount(accountId, options)
@@ -142,7 +143,7 @@ func (model *Model) DeleteTransaction(id string, userId string, orgId string) (e
for _, split := range transaction.Splits {
if !model.accountsContainWriteAccess(userAccounts, split.AccountId) {
return errors.New(fmt.Sprintf("%s %s", "user does not have permission to access account", split.AccountId))
return fmt.Errorf("%s %s", "user does not have permission to access account", split.AccountId)
}
}
@@ -189,13 +190,13 @@ func (model *Model) checkSplits(transaction *types.Transaction) (err error) {
for _, split := range transaction.Splits {
if !model.accountsContainWriteAccess(userAccounts, split.AccountId) {
return errors.New(fmt.Sprintf("%s %s", "user does not have permission to access account", split.AccountId))
return fmt.Errorf("%s %s", "user does not have permission to access account", split.AccountId)
}
account := model.getAccountFromList(userAccounts, split.AccountId)
if account.HasChildren == true {
return errors.New("Cannot use parent account for split")
if !account.HasChildren {
return errors.New("cannot use parent account for split")
}
if account.Currency == org.Currency && split.NativeAmount != split.Amount {