lib/app/authority-helpers.go

111 lines
3.2 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/regs/regs_models"
"github.com/google/uuid"
)
2021-01-18 03:13:54 +00:00
// UnMarshalSwaggerAuthority decodes swagger to first class object
2021-01-14 06:36:35 +00:00
func UnMarshalSwaggerAuthority(s *regs_models.Authority) *Authority {
if s.ID == "" {
s.ID = uuid.New().String()
}
authorityDate, e4 := time.Parse(dateFormat, s.Date)
createdDate, e0 := time.Parse(dateTimeFormat, s.CreatedDate)
dateApproved, e2 := time.Parse(dateFormat, s.DateApproved)
if e2 != nil {
dateApproved, e2 = time.Parse(dateFormatAlt, s.DateApproved)
}
lastModfiedDate, e1 := time.Parse(dateTimeFormat, s.LastModifiedDate)
transferDate, e3 := time.Parse(dateFormat, s.TransferDate)
if e3 != nil {
transferDate, e3 = time.Parse(dateFormatAlt, s.TransferDate)
}
return &Authority{
ID: s.ID,
AccountID: s.AccountID,
AddressLine1: s.AddressLine1,
AddressLine2: s.AddressLine2,
BTN: s.BTN,
City: s.City,
ContactID: s.ContactID,
Country: s.Country,
CreatedByID: s.CreatedByID,
LastModifiedByID: s.LastModifiedByID,
LosingCarrier: s.LosingCarrier,
Name: s.Name,
NameLine1: s.NameLine1,
NameLine2: s.NameLine2,
OpportunityID: s.OpportunityID,
OrderID: s.OrderID,
ParentFK: s.ParentFK,
PostalCode: s.PostalCode,
QuoteID: s.QuoteID,
Ref: s.Ref,
State: s.State,
Status: s.Status,
TemplateID: s.TemplateID,
TenantID: s.TenantID,
Type: s.Type,
Date: sql.NullTime{
Time: authorityDate,
Valid: e4 == nil,
},
CreatedDate: sql.NullTime{
Time: createdDate,
Valid: e0 == nil,
},
LastModifiedDate: sql.NullTime{
Time: lastModfiedDate,
Valid: e1 == nil,
},
DateApproved: sql.NullTime{
Time: dateApproved,
Valid: e2 == nil,
},
TransferDate: sql.NullTime{
Time: transferDate,
Valid: e3 == nil,
},
}
}
2021-01-18 03:13:54 +00:00
// MarshalToSwagger encodes first class object
2021-01-14 06:36:35 +00:00
func (obj *Authority) MarshalToSwagger() *regs_models.Authority {
return &regs_models.Authority{
ID: obj.ID,
AccountID: obj.AccountID,
AddressLine1: obj.AddressLine1,
AddressLine2: obj.AddressLine2,
BTN: obj.BTN,
City: obj.City,
ContactID: obj.ContactID,
Country: obj.Country,
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
Date: obj.Date.Time.Format(dateFormat),
DateApproved: obj.DateApproved.Time.Format(dateFormat),
LastModifiedByID: obj.LastModifiedByID,
LastModifiedDate: obj.LastModifiedDate.Time.Format(dateTimeFormat),
LosingCarrier: obj.LosingCarrier,
Name: obj.Name,
NameLine1: obj.NameLine1,
NameLine2: obj.NameLine2,
OpportunityID: obj.OpportunityID,
OrderID: obj.OrderID,
ParentFK: obj.ParentFK,
PostalCode: obj.PostalCode,
QuoteID: obj.QuoteID,
Ref: obj.Ref,
State: obj.State,
Status: obj.Status,
TransferDate: obj.TransferDate.Time.Format(dateFormat),
TenantID: obj.TenantID,
TemplateID: obj.TemplateID,
Type: obj.Type,
}
}