Skip to content

Commit

Permalink
Move donor data types out of actor into own package (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Jul 29, 2024
1 parent d3f577f commit 953027a
Show file tree
Hide file tree
Showing 91 changed files with 1,283 additions and 1,112 deletions.
162 changes: 4 additions & 158 deletions internal/actor/attorney.go
Original file line number Diff line number Diff line change
@@ -1,163 +1,9 @@
package actor

import (
"fmt"
"slices"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
)

// Attorney contains details about an attorney or replacement attorney, provided by the applicant
type Attorney struct {
// UID for the actor
UID actoruid.UID
// First names of the attorney
FirstNames string
// Last name of the attorney
LastName string
// Email of the attorney
Email string
// Date of birth of the attorney
DateOfBirth date.Date
// Address of the attorney
Address place.Address
}

func (a Attorney) FullName() string {
return fmt.Sprintf("%s %s", a.FirstNames, a.LastName)
}

func (a Attorney) Channel() Channel {
if a.Email != "" {
return ChannelOnline
}

return ChannelPaper
}

// TrustCorporation contains details about a trust corporation, provided by the applicant
type TrustCorporation struct {
// UID for the actor
UID actoruid.UID
// Name of the company
Name string
// CompanyNumber as registered by Companies House
CompanyNumber string
// Email to contact the company
Email string
// Address of the company
Address place.Address
}

func (tc TrustCorporation) Channel() Channel {
if tc.Email != "" {
return ChannelOnline
}

return ChannelPaper
}

type Attorneys struct {
TrustCorporation TrustCorporation
Attorneys []Attorney
}

func (as Attorneys) Len() int {
if as.TrustCorporation.Name == "" {
return len(as.Attorneys)
}

return len(as.Attorneys) + 1
}

func (as Attorneys) Complete() bool {
if as.TrustCorporation.Name != "" && as.TrustCorporation.Address.Line1 == "" {
return false
}

for _, a := range as.Attorneys {
if a.FirstNames == "" || a.Address.Line1 == "" {
return false
}
}

return true
}

func (as Attorneys) Addresses() []place.Address {
var addresses []place.Address

if as.TrustCorporation.Address.String() != "" {
addresses = append(addresses, as.TrustCorporation.Address)
}

for _, attorney := range as.Attorneys {
if attorney.Address.String() != "" && !slices.Contains(addresses, attorney.Address) {
addresses = append(addresses, attorney.Address)
}
}

return addresses
}

func (as Attorneys) Get(uid actoruid.UID) (Attorney, bool) {
idx := as.Index(uid)
if idx == -1 {
return Attorney{}, false
}

return as.Attorneys[idx], true
}

func (as *Attorneys) Put(attorney Attorney) {
idx := as.Index(attorney.UID)
if idx == -1 {
as.Attorneys = append(as.Attorneys, attorney)
} else {
as.Attorneys[idx] = attorney
}
}

func (as *Attorneys) Delete(attorney Attorney) bool {
idx := as.Index(attorney.UID)
if idx == -1 {
return false
}

as.Attorneys = slices.Delete(as.Attorneys, idx, idx+1)
return true
}

func (as *Attorneys) Index(uid actoruid.UID) int {
return slices.IndexFunc(as.Attorneys, func(a Attorney) bool { return a.UID == uid })
}

func (as Attorneys) FullNames() []string {
var names []string

if as.TrustCorporation.Name != "" {
names = append(names, as.TrustCorporation.Name)
}

for _, a := range as.Attorneys {
names = append(names, fmt.Sprintf("%s %s", a.FirstNames, a.LastName))
}

return names
}

func (as Attorneys) FirstNames() []string {
var names []string

if as.TrustCorporation.Name != "" {
names = append(names, as.TrustCorporation.Name)
}

for _, a := range as.Attorneys {
names = append(names, a.FirstNames)
}

return names
}
type Attorney = donordata.Attorney
type TrustCorporation = donordata.TrustCorporation
type Attorneys = donordata.Attorneys
50 changes: 8 additions & 42 deletions internal/actor/attorney_decisions.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,15 @@
package actor

//go:generate enumerator -type AttorneysAct -linecomment -empty
type AttorneysAct uint8
import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"

const (
// Jointly indicates attorneys or replacement attorneys should act jointly
Jointly AttorneysAct = iota + 1 // jointly

// JointlyAndSeverally indicates attorneys or replacement attorneys should act
// jointly and severally
JointlyAndSeverally // jointly-and-severally
type AttorneysAct = donordata.AttorneysAct

// JointlyForSomeSeverallyForOthers indicates attorneys or replacement
// attorneys should act jointly for some decisions, and jointly and severally
// for other decisions
JointlyForSomeSeverallyForOthers // jointly-for-some-severally-for-others
const (
Jointly = donordata.Jointly
JointlyAndSeverally = donordata.JointlyAndSeverally
JointlyForSomeSeverallyForOthers = donordata.JointlyForSomeSeverallyForOthers
)

// AttorneyDecisions contains details about how an attorney or replacement attorney should act, provided by the applicant
type AttorneyDecisions struct {
// How attorneys should make decisions
How AttorneysAct
// Details on how attorneys should make decisions if acting jointly for some decisions, and jointly and severally for other decisions
Details string
}

func MakeAttorneyDecisions(existing AttorneyDecisions, how AttorneysAct, details string) AttorneyDecisions {
if existing.How == how {
if how == JointlyForSomeSeverallyForOthers {
existing.Details = details
}

return existing
}

if how != JointlyForSomeSeverallyForOthers {
return AttorneyDecisions{How: how}
}

return AttorneyDecisions{
How: how,
Details: details,
}
}
type AttorneyDecisions = donordata.AttorneyDecisions

func (d AttorneyDecisions) IsComplete() bool {
return !d.How.Empty()
}
var MakeAttorneyDecisions = donordata.MakeAttorneyDecisions
11 changes: 6 additions & 5 deletions internal/actor/can_be_used_when.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package actor

//go:generate enumerator -type CanBeUsedWhen -linecomment -trimprefix
type CanBeUsedWhen uint8
import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"

type CanBeUsedWhen = donordata.CanBeUsedWhen

const (
CanBeUsedWhenUnknown CanBeUsedWhen = iota
CanBeUsedWhenCapacityLost // when-capacity-lost
CanBeUsedWhenHasCapacity // when-has-capacity
CanBeUsedWhenUnknown = donordata.CanBeUsedWhenUnknown
CanBeUsedWhenCapacityLost = donordata.CanBeUsedWhenCapacityLost
CanBeUsedWhenHasCapacity = donordata.CanBeUsedWhenHasCapacity
)
49 changes: 9 additions & 40 deletions internal/actor/certificate_provider.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,22 @@
package actor

import (
"fmt"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
)

//go:generate enumerator -type CertificateProviderRelationship -linecomment -empty
type CertificateProviderRelationship uint8
type CertificateProviderRelationship = donordata.CertificateProviderRelationship

const (
Personally CertificateProviderRelationship = iota + 1 // personally
Professionally // professionally
Personally = donordata.Personally
Professionally = donordata.Professionally
)

//go:generate enumerator -type CertificateProviderRelationshipLength -linecomment
type CertificateProviderRelationshipLength uint8
type CertificateProviderRelationshipLength = donordata.CertificateProviderRelationshipLength

const (
RelationshipLengthUnknown CertificateProviderRelationshipLength = iota // unknown
LessThanTwoYears // lt-2-years
GreaterThanEqualToTwoYears // gte-2-years
RelationshipLengthUnknown = donordata.RelationshipLengthUnknown
LessThanTwoYears = donordata.LessThanTwoYears
GreaterThanEqualToTwoYears = donordata.GreaterThanEqualToTwoYears
)

// CertificateProvider contains details about the certificate provider, provided by the applicant
type CertificateProvider struct {
// UID for the actor
UID actoruid.UID
// First names of the certificate provider
FirstNames string
// Last name of the certificate provider
LastName string
// Address of the certificate provider
Address place.Address
// Mobile number of the certificate provider, used to send witness codes
Mobile string
// HasNonUKMobile indicates whether the value of Mobile is a non-UK mobile number
HasNonUKMobile bool
// Email of the certificate provider
Email string
// How the certificate provider wants to perform their role (paper or online)
CarryOutBy Channel
// The certificate provider's relationship to the applicant
Relationship CertificateProviderRelationship
// Amount of time Relationship has been in place if Personally
RelationshipLength CertificateProviderRelationshipLength
}

func (c CertificateProvider) FullName() string {
return fmt.Sprintf("%s %s", c.FirstNames, c.LastName)
}
type CertificateProvider = donordata.CertificateProvider
9 changes: 5 additions & 4 deletions internal/actor/channel.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package actor

//go:generate enumerator -type Channel -linecomment -empty -trimprefix
type Channel uint8
import "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"

type Channel = donordata.Channel

const (
ChannelPaper Channel = iota + 1 // paper
ChannelOnline // online
ChannelPaper = donordata.ChannelPaper
ChannelOnline = donordata.ChannelOnline
)
25 changes: 5 additions & 20 deletions internal/actor/correspondent.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
package actor

import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
)

//go:generate enumerator -type CorrespondentShare -linecomment -trimprefix -empty -bits
type CorrespondentShare uint8
type CorrespondentShare = donordata.CorrespondentShare

const (
CorrespondentShareAttorneys CorrespondentShare = 2 << iota
CorrespondentShareCertificateProvider
CorrespondentShareAttorneys = donordata.CorrespondentShareAttorneys
CorrespondentShareCertificateProvider = donordata.CorrespondentShareCertificateProvider
)

type Correspondent struct {
FirstNames string
LastName string
Email string
Organisation string
Telephone string
WantAddress form.YesNo
Address place.Address
Share CorrespondentShare
}

func (c Correspondent) FullName() string {
return c.FirstNames + " " + c.LastName
}
type Correspondent = donordata.Correspondent
Loading

0 comments on commit 953027a

Please sign in to comment.