lib/app/ingest-services.go

65 lines
1.8 KiB
Go
Raw Normal View History

2021-02-06 21:18:47 +00:00
package app
import (
"fmt"
"time"
"code.tnxs.net/taxnexus/lib/api/devops/devops_client/ingest"
"code.tnxs.net/taxnexus/lib/api/devops/devops_models"
"github.com/google/uuid"
)
// NewIngestParams is a prams type
type NewIngestParams struct {
accountID string
backendID string
objectType string
objList []*devops_models.Ingest
principal *User
ref string
}
// NewIngest is an ingest helper function
func NewIngest(params *NewIngestParams) (string, error) {
sugar.Debug("ops.newIngest: 📥")
if params.accountID == "" || params.principal.TenantID == "" {
return "", fmt.Errorf("ops.newIngest: 💣 ⛔ params.AccountID or params.TaxnexusAccount are blank")
}
dt := time.Now().Format(dateTimeFormat)
theIngest := &devops_models.Ingest{
AccountID: &params.accountID,
BackendID: params.backendID,
EndDate: dt,
ID: uuid.New().String(),
IngestDate: dt,
IngestType: "fabric",
ObjectType: &params.objectType,
Ref: params.ref,
StartDate: dt,
Status: "new",
}
params.objList = []*devops_models.Ingest{theIngest}
_, err := PostIngests(params)
if err != nil {
return "", err
}
sugar.Debugf("ops.newIngest: 👍 📤, Ingest ID=%s", theIngest.ID)
return theIngest.ID, nil
}
// PostIngests is an ingest helper function
func PostIngests(params *NewIngestParams) ([]*devops_models.Ingest, error) {
sugar.Debugf("ops.postIngests: 📥 len=%d", len(params.objList))
devopsParams := ingest.NewPostIngestsParams()
devopsParams.IngestRequest = &devops_models.IngestRequest{
Data: params.objList,
}
response, err := devopsClient.Ingest.PostIngests(devopsParams, params.principal.Auth)
if err != nil {
sugar.Errorf("ops.postIngests: 💣 ⛔ post to devops error %w", err)
return nil, err
}
sugar.Debugf("ops.postIngests: 👍 📤 len(ingests)=%d", len(response.Payload.Data))
return response.Payload.Data, nil
}