Skip to content

Commit

Permalink
Merge pull request #3 from foomo/fix/utils-circular-dependencies
Browse files Browse the repository at this point in the history
Fix: import cycle
  • Loading branch information
danielthomas74 authored Sep 15, 2023
2 parents 0edbef3 + 32392b9 commit 18fb246
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
18 changes: 7 additions & 11 deletions constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package constants

import (
"github.com/foomo/contentfulvalidation/validator"
)

const (
SeverityFatal validator.Severity = "fatal"
SeverityError validator.Severity = "error"
SeverityWarn validator.Severity = "warn"
SeverityInfo validator.Severity = "info"
SeverityFatal Severity = "fatal"
SeverityError Severity = "error"
SeverityWarn Severity = "warn"
SeverityInfo Severity = "info"
)

const (
HealthError validator.Health = "error"
HealthWarn validator.Health = "warn"
HealthOk validator.Health = "ok"
HealthError Health = "error"
HealthWarn Health = "warn"
HealthOk Health = "ok"
)

const DateFormat = "02 Jan 2006"
4 changes: 4 additions & 0 deletions constants/vo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package constants

type Severity string
type Health string
17 changes: 1 addition & 16 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package utils

import (
"encoding/json"
catvo "github.com/bestbytes/catalogue/vo"
"github.com/foomo/contentfulvalidation/constants"
"github.com/foomo/contentfulvalidation/validator"
"time"

catvo "github.com/bestbytes/catalogue/vo"
"github.com/foomo/contentful"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -54,16 +52,3 @@ func ConvertTimeFormat(timeToFormat string, parseTemplate string, formatTemplate
}
return p.Format(formatTemplate), nil
}

func InitEmptyValidationResult(modelType validator.ModelType, modelID validator.ModelID, title string, internalTitle string, lastUpdatedDate string) *validator.ValidationResult {
var messages []*validator.ValidationResultMessage
return &validator.ValidationResult{
ID: modelID,
Title: title,
InternalTitle: internalTitle,
LastUpdatedDate: lastUpdatedDate,
ModelType: modelType,
Health: constants.HealthOk,
Messages: messages,
}
}
10 changes: 5 additions & 5 deletions validator/validationresult.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ type ValidationResult struct {
InternalTitle string `json:"internalTitle,omitempty"`
LastUpdatedDate string `json:"lastUpdatedDate,omitempty"`
ModelType ModelType `json:"modelType"`
Health Health `json:"health"`
Health constants.Health `json:"health"`
Messages []*ValidationResultMessage `json:"messages"`
}

type ValidationResultMessage struct {
Code MessageCode `json:"code"`
Message string `json:"message"`
Severity Severity `json:"severity"`
Code MessageCode `json:"code"`
Message string `json:"message"`
Severity constants.Severity `json:"severity"`
}

func (result *ValidationResult) Log(severity Severity, message string, code MessageCode) {
func (result *ValidationResult) Log(severity constants.Severity, message string, code MessageCode) {
msg := &ValidationResultMessage{
Code: code,
Message: message,
Expand Down
19 changes: 16 additions & 3 deletions validator/validator.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package validator

import (
"github.com/foomo/contentfulvalidation/constants"
"github.com/foomo/contentfulvalidation/errors"
"github.com/foomo/contentfulvalidation/utils"
"strings"
"time"

"github.com/foomo/contentfulvalidation/constants"
"github.com/foomo/contentfulvalidation/errors"
"github.com/foomo/contentfulvalidation/utils"
"github.com/foomo/contentserver/client"
keellog "github.com/foomo/keel/log"
"go.uber.org/zap"
Expand Down Expand Up @@ -159,3 +159,16 @@ func (v *Validator) getValidatorByType(modelType ModelType) (ModelValidator, *er
}
return validator, nil
}

func InitEmptyValidationResult(modelType ModelType, modelID ModelID, title string, internalTitle string, lastUpdatedDate string) *ValidationResult {
var messages []*ValidationResultMessage
return &ValidationResult{
ID: modelID,
Title: title,
InternalTitle: internalTitle,
LastUpdatedDate: lastUpdatedDate,
ModelType: modelType,
Health: constants.HealthOk,
Messages: messages,
}
}
2 changes: 0 additions & 2 deletions validator/vo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ type SysType string
type ModelType string
type ModelID string
type MessageCode string
type Severity string
type Health string

type ValidationResults map[ModelType]map[ModelID]*ValidationResult

Expand Down

0 comments on commit 18fb246

Please sign in to comment.