-
Notifications
You must be signed in to change notification settings - Fork 2
/
person_to_notify.go
55 lines (43 loc) · 1.25 KB
/
person_to_notify.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package actor
import (
"slices"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
)
// PersonToNotify contains details about a person to notify, provided by the applicant
type PersonToNotify struct {
// First names of the person to notify
FirstNames string
// Last name of the person to notify
LastName string
// Address of the person to notify
Address place.Address
// Identifies the person to notify being edited
ID string
}
func (p PersonToNotify) FullName() string {
return p.FirstNames + " " + p.LastName
}
type PeopleToNotify []PersonToNotify
func (ps PeopleToNotify) Get(id string) (PersonToNotify, bool) {
idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.ID == id })
if idx == -1 {
return PersonToNotify{}, false
}
return ps[idx], true
}
func (ps PeopleToNotify) Put(person PersonToNotify) bool {
idx := slices.IndexFunc(ps, func(p PersonToNotify) bool { return p.ID == person.ID })
if idx == -1 {
return false
}
ps[idx] = person
return true
}
func (ps *PeopleToNotify) Delete(personToNotify PersonToNotify) bool {
idx := slices.IndexFunc(*ps, func(p PersonToNotify) bool { return p.ID == personToNotify.ID })
if idx == -1 {
return false
}
*ps = slices.Delete(*ps, idx, idx+1)
return true
}