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

Function parseExternalTransaction

internal/files/files.go:399–446  ·  view source on GitHub ↗
(record []string, columnMap map[string]int, source string)

Source from the content-addressed store, hash-verified

397}
398
399func parseExternalTransaction(record []string, columnMap map[string]int, source string) (model.ExternalTransaction, error) {
400 if len(record) != len(columnMap) {
401 return model.ExternalTransaction{}, fmt.Errorf("incorrect number of fields in record")
402 }
403
404 id, err := getRequiredField(record, columnMap, "id")
405 if err != nil {
406 return model.ExternalTransaction{}, err
407 }
408
409 amountStr, err := getRequiredField(record, columnMap, "amount")
410 if err != nil {
411 return model.ExternalTransaction{}, err
412 }
413
414 currency, err := getRequiredField(record, columnMap, "currency")
415 if err != nil {
416 return model.ExternalTransaction{}, err
417 }
418
419 amount := parseFloat(amountStr)
420
421 reference, err := getRequiredField(record, columnMap, "reference")
422 if err != nil {
423 return model.ExternalTransaction{}, err
424 }
425
426 description, err := getRequiredField(record, columnMap, "description")
427 if err != nil {
428 return model.ExternalTransaction{}, err
429 }
430
431 dateStr, err := getRequiredField(record, columnMap, "date")
432 if err != nil {
433 return model.ExternalTransaction{}, err
434 }
435 date := parseTime(dateStr)
436
437 return model.ExternalTransaction{
438 ID: id,
439 Amount: amount,
440 Currency: currency,
441 Reference: reference,
442 Description: description,
443 Date: date,
444 Source: source,
445 }, nil
446}
447
448func getRequiredField(record []string, columnMap map[string]int, field string) (string, error) {
449 if index, exists := columnMap[field]; exists && index < len(record) {

Callers 1

processWorkerFunction · 0.85

Calls 3

getRequiredFieldFunction · 0.85
parseFloatFunction · 0.85
parseTimeFunction · 0.85

Tested by

no test coverage detected