lib/app/eftitem-helpers.go

51 lines
1.3 KiB
Go
Raw Permalink Normal View History

2021-01-14 06:36:35 +00:00
package app
import (
"database/sql"
"time"
"code.tnxs.net/taxnexus/lib/api/ops/ops_models"
"github.com/google/uuid"
)
// UnMarshalEftItem decodes swagger to a first class object
func UnMarshalEftItem(s *ops_models.EftItem) *EftItem {
if s.ID == "" {
s.ID = uuid.New().String()
}
createdDate, e0 := time.Parse(dateTimeFormat, s.CreatedDate)
lastModfiedDate, e1 := time.Parse(dateTimeFormat, s.LastModifiedDate)
return &EftItem{
ID: s.ID,
Amount: s.Amount,
CreatedByID: s.CreatedByID,
EftID: s.EftID,
InvoiceID: s.InvoiceID,
LastModifiedByID: s.LastModifiedByID,
TenantID: s.TenantID,
CreatedDate: sql.NullTime{
Time: createdDate,
Valid: e0 == nil,
},
LastModifiedDate: sql.NullTime{
Time: lastModfiedDate,
Valid: e1 == nil,
},
}
}
// MarshalToSwagger encodes a first class object to swagger
func (obj *EftItem) MarshalToSwagger() *ops_models.EftItem {
return &ops_models.EftItem{
ID: obj.ID,
Amount: obj.Amount,
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
EftID: obj.EftID,
InvoiceID: obj.InvoiceID,
LastModifiedByID: obj.LastModifiedByID,
LastModifiedDate: obj.LastModifiedDate.Time.Format(dateTimeFormat),
TenantID: obj.TenantID,
}
}