MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / ValidateCreateAccount

Method ValidateCreateAccount

api/model/model.go:189–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

187}
188
189func (a *CreateAccount) ValidateCreateAccount() error {
190 return validation.ValidateStruct(a,
191 validation.Field(&a.LedgerId, validation.When(a.BalanceId == "", validation.Required.Error("Ledger ID is required when Balance ID is not provided"))),
192 validation.Field(&a.IdentityId, validation.When(a.BalanceId == "", validation.Required.Error("Identity ID is required when Balance ID is not provided"))),
193 validation.Field(&a.Currency, validation.When(a.BalanceId == "", validation.Required.Error("currency is required when Balance ID is not provided"))),
194 validation.Field(&a.LedgerId, validation.By(func(value interface{}) error {
195 if a.BalanceId != "" && a.LedgerId != "" {
196 return errors.New("either LedgerId or BalanceId must be provided, not both")
197 }
198 return nil
199 })),
200 validation.Field(&a.Currency, validation.By(func(value interface{}) error {
201 if a.BalanceId != "" && a.Currency != "" {
202 return errors.New("either Currency or BalanceId must be provided, not both")
203 }
204 return nil
205 })),
206 )
207}
208
209func (l *CreateLedger) ToLedger() model.Ledger {
210 return model.Ledger{Name: l.Name, MetaData: l.MetaData}

Callers 2

CreateAccountMethod · 0.95

Calls 1

ErrorMethod · 0.45

Tested by 1