lib/app/applog-helpers.go

55 lines
1.4 KiB
Go
Raw Normal View History

2021-01-14 06:36:35 +00:00
package app
import (
"database/sql"
"time"
"code.tnxs.net/taxnexus/lib/api/workflow/workflow_models"
"github.com/google/uuid"
)
2021-01-18 03:13:54 +00:00
// UnMarshalLog decodes swagger to first class object
func UnMarshalLog(s *workflow_models.AppLog) *Log {
2021-01-14 06:36:35 +00:00
if s.ID == "" {
s.ID = uuid.New().String()
}
createdDate, e0 := time.Parse(dateTimeFormat, s.CreatedDate)
sourceTimestamp, e1 := time.Parse(dateTimeFormat, s.SourceTimestamp)
2021-01-18 03:13:54 +00:00
return &Log{
2021-01-14 06:36:35 +00:00
AccountID: s.AccountID,
CompanyID: s.CompanyID,
CreatedByID: s.CreatedByID,
ID: s.ID,
Message: s.Message,
ObjectID: s.ObjectID,
ObjectType: s.ObjectType,
Severity: s.Severity,
Source: s.Source,
CreatedDate: sql.NullTime{
Time: createdDate,
Valid: e0 == nil,
},
SourceTimestamp: sql.NullTime{
Time: sourceTimestamp,
Valid: e1 == nil,
},
}
}
2021-01-18 03:13:54 +00:00
// MarshalToSwagger encodes first class object
func (obj *Log) MarshalToSwagger() *workflow_models.AppLog {
2021-01-14 06:36:35 +00:00
return &workflow_models.AppLog{
ID: obj.ID,
AccountID: obj.AccountID,
CompanyID: obj.CompanyID,
CreatedByID: obj.CreatedByID,
CreatedDate: obj.CreatedDate.Time.Format(dateTimeFormat),
Message: obj.Message,
ObjectType: obj.ObjectType,
ObjectID: obj.ObjectID,
Severity: obj.Severity,
Source: obj.Source,
SourceTimestamp: obj.SourceTimestamp.Time.Format(dateTimeFormat),
}
}