+ ledger account open endpoint

This commit is contained in:
Stephan D
2026-01-05 12:57:17 +01:00
parent 9a5c087940
commit 2f34b5a827
4 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package srequest
import (
"strings"
"github.com/tech/sendico/pkg/merrors"
)
type LedgerAccountType string
const (
LedgerAccountTypeUnspecified LedgerAccountType = "unspecified"
LedgerAccountTypeAsset LedgerAccountType = "asset"
LedgerAccountTypeLiability LedgerAccountType = "liability"
LedgerAccountTypeRevenue LedgerAccountType = "revenue"
LedgerAccountTypeExpense LedgerAccountType = "expense"
)
type LedgerAccountStatus string
const (
LedgerAccountStatusUnspecified LedgerAccountStatus = "unspecified"
LedgerAccountStatusActive LedgerAccountStatus = "active"
LedgerAccountStatusFrozen LedgerAccountStatus = "frozen"
)
type CreateLedgerAccount struct {
AccountCode string `json:"accountCode"`
AccountType LedgerAccountType `json:"accountType"`
Currency string `json:"currency"`
Status LedgerAccountStatus `json:"status,omitempty"`
AllowNegative bool `json:"allowNegative,omitempty"`
IsSettlement bool `json:"isSettlement,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
func (r *CreateLedgerAccount) Validate() error {
if strings.TrimSpace(r.AccountCode) == "" {
return merrors.InvalidArgument("accountCode is required", "accountCode")
}
if strings.TrimSpace(r.Currency) == "" {
return merrors.InvalidArgument("currency is required", "currency")
}
if strings.TrimSpace(string(r.AccountType)) == "" || strings.EqualFold(string(r.AccountType), string(LedgerAccountTypeUnspecified)) {
return merrors.InvalidArgument("accountType is required", "accountType")
}
return nil
}

View File

@@ -29,6 +29,11 @@ type ledgerAccountsResponse struct {
Accounts []ledgerAccount `json:"accounts"`
}
type ledgerAccountResponse struct {
authResponse `json:",inline"`
Account ledgerAccount `json:"account"`
}
type ledgerMoney struct {
Amount string `json:"amount"`
Currency string `json:"currency"`
@@ -57,6 +62,13 @@ func LedgerAccounts(logger mlogger.Logger, accounts []*ledgerv1.LedgerAccount, a
})
}
func LedgerAccountCreated(logger mlogger.Logger, account *ledgerv1.LedgerAccount, accessToken *TokenData) http.HandlerFunc {
return response.Created(logger, ledgerAccountResponse{
Account: toLedgerAccount(account),
authResponse: authResponse{AccessToken: *accessToken},
})
}
func LedgerBalance(logger mlogger.Logger, resp *ledgerv1.BalanceResponse, accessToken *TokenData) http.HandlerFunc {
return response.Ok(logger, ledgerBalanceResponse{
Balance: toLedgerBalance(resp),