Skip to content

Commit

Permalink
Change some names
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Dec 15, 2023
1 parent 158cde7 commit aebbff9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 59 deletions.
26 changes: 13 additions & 13 deletions internal/shared/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package shared
import "time"

type LpaInit struct {
Type Type `json:"type"`
Donor Donor `json:"donor" dynamodbav:""`
Attorneys []Attorney `json:"attorneys" dynamodbav:""`
LpaType LpaType `json:"lpaType"`
Donor Donor `json:"donor"`
Attorneys []Attorney `json:"attorneys"`
CertificateProvider CertificateProvider `json:"certificateProvider"`
PeopleToNotify []PersonToNotify `json:"peopleToNotify"`
HowAttorneysMakeDecisions HowMakeDecisions `json:"howAttorneysMakeDecisions"`
Expand All @@ -14,29 +14,29 @@ type LpaInit struct {
HowReplacementAttorneysMakeDecisionsDetails string `json:"howReplacementAttorneysMakeDecisionsDetails"`
HowReplacementAttorneysStepIn HowStepIn `json:"howReplacementAttorneysStepIn"`
HowReplacementAttorneysStepInDetails string `json:"howReplacementAttorneysStepInDetails"`
WhenTheLpaCanBeUsed CanUseWhen `json:"whenTheLpaCanBeUsed"`
WhenTheLpaCanBeUsed CanUse `json:"whenTheLpaCanBeUsed"`
LifeSustainingTreatmentOption LifeSustainingTreatment `json:"lifeSustainingTreatmentOption"`
Restrictions string `json:"restrictions"`
SignedAt time.Time `json:"signedAt"`
}

type Lpa struct {
LpaInit
Uid string `json:"uid" dynamodbav:""`
Status LpaStatus `json:"status" dynamodbav:""`
RegistrationDate time.Time `json:"registrationDate" dynamodbav:""`
UpdatedAt time.Time `json:"updatedAt" dynamodbav:""`
Uid string `json:"uid"`
Status LpaStatus `json:"status"`
RegistrationDate time.Time `json:"registrationDate"`
UpdatedAt time.Time `json:"updatedAt"`
}

type Type string
type LpaType string

const (
TypeHealthWelfare = Type("hw")
TypePropertyFinance = Type("pfa")
LpaTypePersonalWelfare = LpaType("personal-welfare")
LpaTypePropertyAndAffairs = LpaType("property-and-affairs")
)

func (e Type) IsValid() bool {
return e == TypeHealthWelfare || e == TypePropertyFinance
func (e LpaType) IsValid() bool {
return e == LpaTypePersonalWelfare || e == LpaTypePropertyAndAffairs
}

type LpaStatus string
Expand Down
64 changes: 32 additions & 32 deletions internal/shared/person.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package shared

type Address struct {
Line1 string `json:"line1" dynamodbav:""`
Line2 string `json:"line2" dynamodbav:""`
Line3 string `json:"line3" dynamodbav:""`
Town string `json:"town" dynamodbav:""`
Postcode string `json:"postcode" dynamodbav:""`
Country string `json:"country" dynamodbav:""`
Line1 string `json:"line1"`
Line2 string `json:"line2"`
Line3 string `json:"line3"`
Town string `json:"town"`
Postcode string `json:"postcode"`
Country string `json:"country"`
}

type Person struct {
FirstNames string `json:"firstNames" dynamodbav:""`
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
Address Address `json:"address" dynamodbav:""`
Address Address `json:"address"`
}

type Donor struct {
Person
DateOfBirth Date `json:"dateOfBirth" dynamodbav:""`
Email string `json:"email" dynamodbav:""`
OtherNamesKnownBy string `json:"otherNamesKnownBy" dynamodbav:""`
DateOfBirth Date `json:"dateOfBirth"`
Email string `json:"email"`
OtherNamesKnownBy string `json:"otherNamesKnownBy"`
}

type CertificateProvider struct {
Person
Email string `json:"email" dynamodbav:""`
CarryOutBy CarryOutBy `json:"carryOutBy"`
Email string `json:"email"`
Channel Channel `json:"channel"`
}

type CarryOutBy string
type Channel string

const (
CarryOutByOnline = CarryOutBy("online")
CarryOutByPaper = CarryOutBy("paper")
ChannelOnline = Channel("online")
ChannelPaper = Channel("paper")
)

func (e CarryOutBy) IsValid() bool {
return e == CarryOutByOnline || e == CarryOutByPaper
func (e Channel) IsValid() bool {
return e == ChannelOnline || e == ChannelPaper
}

type AttorneyStatus string
Expand All @@ -53,9 +53,9 @@ func (a AttorneyStatus) IsValid() bool {

type Attorney struct {
Person
DateOfBirth Date `json:"dateOfBirth" dynamodbav:""`
Email string `json:"email" dynamodbav:""`
Status AttorneyStatus `json:"status" dynamodbav:""`
DateOfBirth Date `json:"dateOfBirth"`
Email string `json:"email"`
Status AttorneyStatus `json:"status"`
}

type PersonToNotify struct {
Expand All @@ -68,7 +68,7 @@ const (
HowMakeDecisionsUnset = HowMakeDecisions("")
HowMakeDecisionsJointly = HowMakeDecisions("jointly")
HowMakeDecisionsJointlyAndSeverally = HowMakeDecisions("jointly-and-severally")
HowMakeDecisionsJointlyForSomeSeverallyForOthers = HowMakeDecisions("mixed")
HowMakeDecisionsJointlyForSomeSeverallyForOthers = HowMakeDecisions("jointly-for-some-severally-for-others")
)

func (e HowMakeDecisions) IsValid() bool {
Expand All @@ -83,29 +83,29 @@ type HowStepIn string

const (
HowStepInUnset = HowStepIn("")
HowStepInAllCanNoLongerAct = HowStepIn("all")
HowStepInOneCanNoLongerAct = HowStepIn("one")
HowStepInAnotherWay = HowStepIn("other")
HowStepInAllCanNoLongerAct = HowStepIn("all-can-no-longer-act")
HowStepInOneCanNoLongerAct = HowStepIn("one-can-no-longer-act")
HowStepInAnotherWay = HowStepIn("another-way")
)

func (e HowStepIn) IsValid() bool {
return e == HowStepInUnset || e == HowStepInAllCanNoLongerAct || e == HowStepInOneCanNoLongerAct || e == HowStepInAnotherWay
}

type CanUseWhen string
type CanUse string

const (
CanUseWhenUnset = CanUseWhen("")
CanUseWhenCapacityLost = CanUseWhen("when-capacity-lost")
CanUseWhenHasCapacity = CanUseWhen("when-has-capacity")
CanUseUnset = CanUse("")
CanUseWhenCapacityLost = CanUse("when-capacity-lost")
CanUseWhenHasCapacity = CanUse("when-has-capacity")
)

func (e CanUseWhen) IsValid() bool {
func (e CanUse) IsValid() bool {
return e == CanUseWhenCapacityLost || e == CanUseWhenHasCapacity
}

func (e CanUseWhen) Unset() bool {
return e == CanUseWhenUnset
func (e CanUse) Unset() bool {
return e == CanUseUnset
}

type LifeSustainingTreatment string
Expand Down
10 changes: 5 additions & 5 deletions lambda/create/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ func Validate(lpa shared.LpaInit) []shared.FieldError {
activeAttorneyCount, replacementAttorneyCount := countAttorneys(lpa.Attorneys)

return flatten(
validateIsValid("/type", lpa.Type),
validateIsValid("/lpaType", lpa.LpaType),
required("/donor/firstNames", lpa.Donor.FirstNames),
required("/donor/lastName", lpa.Donor.LastName),
validateDate("/donor/dateOfBirth", lpa.Donor.DateOfBirth),
validateAddress("/donor/address", lpa.Donor.Address),
required("/certificateProvider/firstNames", lpa.CertificateProvider.FirstNames),
required("/certificateProvider/lastName", lpa.CertificateProvider.LastName),
validateAddress("/certificateProvider/address", lpa.CertificateProvider.Address),
validateIsValid("/certificateProvider/carryOutBy", lpa.CertificateProvider.CarryOutBy),
validateIfElse(lpa.CertificateProvider.CarryOutBy == shared.CarryOutByOnline,
validateIsValid("/certificateProvider/channel", lpa.CertificateProvider.Channel),
validateIfElse(lpa.CertificateProvider.Channel == shared.ChannelOnline,
required("/certificateProvider/email", lpa.CertificateProvider.Email),
empty("/certificateProvider/email", lpa.CertificateProvider.Email)),
validateAttorneys("/attorneys", lpa.Attorneys),
Expand All @@ -42,10 +42,10 @@ func Validate(lpa shared.LpaInit) []shared.FieldError {
validateIfElse(lpa.HowReplacementAttorneysMakeDecisions == shared.HowMakeDecisionsJointlyForSomeSeverallyForOthers,
required("/howReplacementAttorneysMakeDecisionsDetails", lpa.HowReplacementAttorneysMakeDecisionsDetails),
empty("/howReplacementAttorneysMakeDecisionsDetails", lpa.HowReplacementAttorneysMakeDecisionsDetails)),
validateIf(lpa.Type == "hw", flatten(
validateIf(lpa.LpaType == shared.LpaTypePersonalWelfare, flatten(
validateIsValid("/lifeSustainingTreatmentOption", lpa.LifeSustainingTreatmentOption),
validateUnset("/whenTheLpaCanBeUsed", lpa.WhenTheLpaCanBeUsed))),
validateIf(lpa.Type == "pfa", flatten(
validateIf(lpa.LpaType == shared.LpaTypePropertyAndAffairs, flatten(
validateIsValid("/whenTheLpaCanBeUsed", lpa.WhenTheLpaCanBeUsed),
validateUnset("/lifeSustainingTreatmentOption", lpa.LifeSustainingTreatmentOption))),
validateTime("/signedAt", lpa.SignedAt),
Expand Down
18 changes: 9 additions & 9 deletions lambda/create/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestValidateLpaInvalid(t *testing.T) {
}{
"empty": {
contains: []shared.FieldError{
{Source: "/type", Detail: "field is required"},
{Source: "/lpaType", Detail: "field is required"},
{Source: "/donor/firstNames", Detail: "field is required"},
{Source: "/donor/lastName", Detail: "field is required"},
{Source: "/donor/dateOfBirth", Detail: "field is required"},
Expand All @@ -200,7 +200,7 @@ func TestValidateLpaInvalid(t *testing.T) {
"online certificate provider missing email": {
lpa: shared.LpaInit{
CertificateProvider: shared.CertificateProvider{
CarryOutBy: shared.CarryOutByOnline,
Channel: shared.ChannelOnline,
},
},
contains: []shared.FieldError{
Expand All @@ -210,8 +210,8 @@ func TestValidateLpaInvalid(t *testing.T) {
"paper certificate provider with email": {
lpa: shared.LpaInit{
CertificateProvider: shared.CertificateProvider{
CarryOutBy: shared.CarryOutByPaper,
Email: "something",
Channel: shared.ChannelPaper,
Email: "something",
},
},
contains: []shared.FieldError{
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestValidateLpaInvalid(t *testing.T) {
},
"health welfare with when can be used": {
lpa: shared.LpaInit{
Type: shared.TypeHealthWelfare,
LpaType: shared.LpaTypePersonalWelfare,
WhenTheLpaCanBeUsed: shared.CanUseWhenHasCapacity,
},
contains: []shared.FieldError{
Expand All @@ -342,7 +342,7 @@ func TestValidateLpaInvalid(t *testing.T) {
},
"property finance with life sustaining treatment": {
lpa: shared.LpaInit{
Type: shared.TypePropertyFinance,
LpaType: shared.LpaTypePropertyAndAffairs,
LifeSustainingTreatmentOption: shared.LifeSustainingTreatmentOptionA,
},
contains: []shared.FieldError{
Expand All @@ -364,7 +364,7 @@ func TestValidateLpaInvalid(t *testing.T) {

func TestValidateLpaValid(t *testing.T) {
lpa := shared.LpaInit{
Type: "hw",
LpaType: "personal-welfare",
Donor: shared.Donor{
Person: shared.Person{
FirstNames: "Otto",
Expand All @@ -390,8 +390,8 @@ func TestValidateLpaValid(t *testing.T) {
LastName: "Person",
Address: validAddress,
},
Email: "[email protected]",
CarryOutBy: "online",
Email: "[email protected]",
Channel: "online",
},
LifeSustainingTreatmentOption: shared.LifeSustainingTreatmentOptionA,
SignedAt: time.Now(),
Expand Down

0 comments on commit aebbff9

Please sign in to comment.