-
Notifications
You must be signed in to change notification settings - Fork 2
/
lpa.go
681 lines (603 loc) · 24.6 KB
/
lpa.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
package lpastore
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"slices"
"time"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
)
type lpaRequest struct {
LpaType actor.LpaType `json:"lpaType"`
Channel actor.Channel `json:"channel"`
Donor lpaRequestDonor `json:"donor"`
Attorneys []lpaRequestAttorney `json:"attorneys"`
TrustCorporations []lpaRequestTrustCorporation `json:"trustCorporations,omitempty"`
CertificateProvider lpaRequestCertificateProvider `json:"certificateProvider"`
PeopleToNotify []lpaRequestPersonToNotify `json:"peopleToNotify,omitempty"`
HowAttorneysMakeDecisions actor.AttorneysAct `json:"howAttorneysMakeDecisions,omitempty"`
HowAttorneysMakeDecisionsDetails string `json:"howAttorneysMakeDecisionsDetails,omitempty"`
HowReplacementAttorneysMakeDecisions actor.AttorneysAct `json:"howReplacementAttorneysMakeDecisions,omitempty"`
HowReplacementAttorneysMakeDecisionsDetails string `json:"howReplacementAttorneysMakeDecisionsDetails,omitempty"`
HowReplacementAttorneysStepIn actor.ReplacementAttorneysStepIn `json:"howReplacementAttorneysStepIn,omitempty"`
HowReplacementAttorneysStepInDetails string `json:"howReplacementAttorneysStepInDetails,omitempty"`
Restrictions string `json:"restrictionsAndConditions"`
WhenTheLpaCanBeUsed actor.CanBeUsedWhen `json:"whenTheLpaCanBeUsed,omitempty"`
LifeSustainingTreatmentOption actor.LifeSustainingTreatment `json:"lifeSustainingTreatmentOption,omitempty"`
SignedAt time.Time `json:"signedAt"`
CertificateProviderNotRelatedConfirmedAt *time.Time `json:"certificateProviderNotRelatedConfirmedAt,omitempty"`
}
type lpaRequestDonor struct {
UID actoruid.UID `json:"uid"`
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
DateOfBirth date.Date `json:"dateOfBirth"`
Email string `json:"email"`
Address place.Address `json:"address"`
OtherNamesKnownBy string `json:"otherNamesKnownBy,omitempty"`
ContactLanguagePreference localize.Lang `json:"contactLanguagePreference"`
}
type lpaRequestAttorney struct {
UID actoruid.UID `json:"uid"`
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
DateOfBirth date.Date `json:"dateOfBirth"`
Email string `json:"email,omitempty"`
Address place.Address `json:"address"`
Status string `json:"status"`
Channel actor.Channel `json:"channel"`
}
type lpaRequestTrustCorporation struct {
UID actoruid.UID `json:"uid"`
Name string `json:"name"`
CompanyNumber string `json:"companyNumber"`
Email string `json:"email,omitempty"`
Address place.Address `json:"address"`
Status string `json:"status"`
Channel actor.Channel `json:"channel"`
}
type lpaRequestCertificateProvider struct {
UID actoruid.UID `json:"uid"`
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
Address place.Address `json:"address"`
Channel actor.Channel `json:"channel"`
}
type lpaRequestPersonToNotify struct {
UID actoruid.UID `json:"uid"`
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
Address place.Address `json:"address"`
}
func (c *Client) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) error {
body := lpaRequest{
LpaType: donor.Type,
Channel: actor.ChannelOnline,
Donor: lpaRequestDonor{
UID: donor.Donor.UID,
FirstNames: donor.Donor.FirstNames,
LastName: donor.Donor.LastName,
DateOfBirth: donor.Donor.DateOfBirth,
Email: donor.Donor.Email,
Address: donor.Donor.Address,
OtherNamesKnownBy: donor.Donor.OtherNames,
ContactLanguagePreference: donor.Donor.ContactLanguagePreference,
},
CertificateProvider: lpaRequestCertificateProvider{
UID: donor.CertificateProvider.UID,
FirstNames: donor.CertificateProvider.FirstNames,
LastName: donor.CertificateProvider.LastName,
Email: donor.CertificateProvider.Email,
Phone: donor.CertificateProvider.Mobile,
Address: donor.CertificateProvider.Address,
Channel: donor.CertificateProvider.CarryOutBy,
},
Restrictions: donor.Restrictions,
SignedAt: donor.SignedAt,
}
if !donor.CertificateProviderNotRelatedConfirmedAt.IsZero() {
body.CertificateProviderNotRelatedConfirmedAt = &donor.CertificateProviderNotRelatedConfirmedAt
}
switch donor.Type {
case actor.LpaTypePropertyAndAffairs:
body.WhenTheLpaCanBeUsed = donor.WhenCanTheLpaBeUsed
case actor.LpaTypePersonalWelfare:
body.LifeSustainingTreatmentOption = donor.LifeSustainingTreatmentOption
}
if donor.Attorneys.Len() > 1 {
body.HowAttorneysMakeDecisions = donor.AttorneyDecisions.How
body.HowAttorneysMakeDecisionsDetails = donor.AttorneyDecisions.Details
}
if donor.ReplacementAttorneys.Len() > 0 && donor.AttorneyDecisions.How.IsJointlyAndSeverally() {
body.HowReplacementAttorneysStepIn = donor.HowShouldReplacementAttorneysStepIn
body.HowReplacementAttorneysStepInDetails = donor.HowShouldReplacementAttorneysStepInDetails
}
if donor.ReplacementAttorneys.Len() > 1 && (donor.HowShouldReplacementAttorneysStepIn.IsWhenAllCanNoLongerAct() || !donor.AttorneyDecisions.How.IsJointlyAndSeverally()) {
body.HowReplacementAttorneysMakeDecisions = donor.ReplacementAttorneyDecisions.How
body.HowReplacementAttorneysMakeDecisionsDetails = donor.ReplacementAttorneyDecisions.Details
}
for _, attorney := range donor.Attorneys.Attorneys {
body.Attorneys = append(body.Attorneys, lpaRequestAttorney{
UID: attorney.UID,
FirstNames: attorney.FirstNames,
LastName: attorney.LastName,
DateOfBirth: attorney.DateOfBirth,
Email: attorney.Email,
Address: attorney.Address,
Status: statusActive,
Channel: attorney.Channel(),
})
}
if trustCorporation := donor.Attorneys.TrustCorporation; trustCorporation.Name != "" {
body.TrustCorporations = append(body.TrustCorporations, lpaRequestTrustCorporation{
UID: trustCorporation.UID,
Name: trustCorporation.Name,
CompanyNumber: trustCorporation.CompanyNumber,
Email: trustCorporation.Email,
Address: trustCorporation.Address,
Status: statusActive,
Channel: trustCorporation.Channel(),
})
}
for _, attorney := range donor.ReplacementAttorneys.Attorneys {
body.Attorneys = append(body.Attorneys, lpaRequestAttorney{
UID: attorney.UID,
FirstNames: attorney.FirstNames,
LastName: attorney.LastName,
DateOfBirth: attorney.DateOfBirth,
Email: attorney.Email,
Address: attorney.Address,
Status: statusReplacement,
Channel: attorney.Channel(),
})
}
if trustCorporation := donor.ReplacementAttorneys.TrustCorporation; trustCorporation.Name != "" {
body.TrustCorporations = append(body.TrustCorporations, lpaRequestTrustCorporation{
UID: trustCorporation.UID,
Name: trustCorporation.Name,
CompanyNumber: trustCorporation.CompanyNumber,
Email: trustCorporation.Email,
Address: trustCorporation.Address,
Status: statusReplacement,
Channel: trustCorporation.Channel(),
})
}
for _, person := range donor.PeopleToNotify {
body.PeopleToNotify = append(body.PeopleToNotify, lpaRequestPersonToNotify{
UID: person.UID,
FirstNames: person.FirstNames,
LastName: person.LastName,
Address: person.Address,
})
}
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(body); err != nil {
return err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPut, c.baseURL+"/lpas/"+donor.LpaUID, &buf)
if err != nil {
return err
}
resp, err := c.do(ctx, donor.Donor.UID, req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
body, _ := io.ReadAll(resp.Body)
return responseError{
name: fmt.Sprintf("expected 201 response but got %d", resp.StatusCode),
body: string(body),
}
}
return nil
}
type lpaResponseAttorney struct {
lpaRequestAttorney
Mobile string `json:"mobile"`
SignedAt time.Time `json:"signedAt"`
ContactLanguagePreference localize.Lang `json:"contactLanguagePreference"`
}
type lpaResponseTrustCorporation struct {
lpaRequestTrustCorporation
Mobile string `json:"mobile"`
Signatories []TrustCorporationSignatory `json:"signatories"`
ContactLanguagePreference localize.Lang `json:"contactLanguagePreference"`
}
type Attorney struct {
UID actoruid.UID
FirstNames string
LastName string
DateOfBirth date.Date
Email string
Address place.Address
Mobile string
SignedAt time.Time
ContactLanguagePreference localize.Lang
Channel actor.Channel
}
func (a Attorney) FullName() string {
return a.FirstNames + " " + a.LastName
}
type TrustCorporation struct {
UID actoruid.UID
Name string
CompanyNumber string
Email string
Address place.Address
Mobile string
Signatories []TrustCorporationSignatory
ContactLanguagePreference localize.Lang
Channel actor.Channel
}
type TrustCorporationSignatory struct {
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
ProfessionalTitle string `json:"professionalTitle"`
SignedAt time.Time `json:"signedAt"`
}
type CertificateProvider struct {
UID actoruid.UID `json:"uid"`
FirstNames string `json:"firstNames"`
LastName string `json:"lastName"`
Email string `json:"email,omitempty"`
Phone string `json:"phone,omitempty"`
Address place.Address `json:"address"`
Channel actor.Channel `json:"channel"`
SignedAt time.Time `json:"signedAt"`
ContactLanguagePreference localize.Lang `json:"contactLanguagePreference"`
// Relationship is not stored in the lpa-store so is defaulted to
// Professional. We require it to determine whether to show the home address
// page to a certificate provider.
Relationship actor.CertificateProviderRelationship
}
func (c CertificateProvider) FullName() string {
return c.FirstNames + " " + c.LastName
}
type lpaResponse struct {
LpaType actor.LpaType `json:"lpaType"`
Donor lpaRequestDonor `json:"donor"`
Channel actor.Channel `json:"channel"`
Attorneys []lpaResponseAttorney `json:"attorneys"`
TrustCorporations []lpaResponseTrustCorporation `json:"trustCorporations,omitempty"`
CertificateProvider CertificateProvider `json:"certificateProvider"`
PeopleToNotify []lpaRequestPersonToNotify `json:"peopleToNotify,omitempty"`
HowAttorneysMakeDecisions actor.AttorneysAct `json:"howAttorneysMakeDecisions,omitempty"`
HowAttorneysMakeDecisionsDetails string `json:"howAttorneysMakeDecisionsDetails,omitempty"`
HowReplacementAttorneysMakeDecisions actor.AttorneysAct `json:"howReplacementAttorneysMakeDecisions,omitempty"`
HowReplacementAttorneysMakeDecisionsDetails string `json:"howReplacementAttorneysMakeDecisionsDetails,omitempty"`
HowReplacementAttorneysStepIn actor.ReplacementAttorneysStepIn `json:"howReplacementAttorneysStepIn,omitempty"`
HowReplacementAttorneysStepInDetails string `json:"howReplacementAttorneysStepInDetails,omitempty"`
Restrictions string `json:"restrictionsAndConditions"`
WhenTheLpaCanBeUsed actor.CanBeUsedWhen `json:"whenTheLpaCanBeUsed,omitempty"`
LifeSustainingTreatmentOption actor.LifeSustainingTreatment `json:"lifeSustainingTreatmentOption,omitempty"`
SignedAt time.Time `json:"signedAt"`
CertificateProviderNotRelatedConfirmedAt *time.Time `json:"certificateProviderNotRelatedConfirmedAt,omitempty"`
UID string `json:"uid"`
Status string `json:"status"`
RegistrationDate time.Time `json:"registrationDate"`
UpdatedAt time.Time `json:"updatedAt"`
}
type Attorneys struct {
Attorneys []Attorney
TrustCorporation TrustCorporation
}
func (a Attorneys) Len() int {
if a.TrustCorporation.Name != "" {
return 1 + len(a.Attorneys)
}
return len(a.Attorneys)
}
func (a Attorneys) Index(uid actoruid.UID) int {
return slices.IndexFunc(a.Attorneys, func(a Attorney) bool { return a.UID == uid })
}
func (a Attorneys) Get(uid actoruid.UID) (Attorney, bool) {
idx := a.Index(uid)
if idx == -1 {
return Attorney{}, false
}
return a.Attorneys[idx], true
}
func (a Attorneys) FullNames() []string {
var names []string
if a.TrustCorporation.Name != "" {
names = append(names, a.TrustCorporation.Name)
}
for _, a := range a.Attorneys {
names = append(names, fmt.Sprintf("%s %s", a.FirstNames, a.LastName))
}
return names
}
type Lpa struct {
LpaKey dynamo.LpaKeyType
LpaOwnerKey dynamo.LpaOwnerKeyType
LpaID string
LpaUID string
RegisteredAt time.Time
WithdrawnAt time.Time
PerfectAt time.Time
UpdatedAt time.Time
Type actor.LpaType
Channel actor.Channel
Donor actor.Donor
Attorneys Attorneys
ReplacementAttorneys Attorneys
CertificateProvider CertificateProvider
PeopleToNotify actor.PeopleToNotify
AttorneyDecisions actor.AttorneyDecisions
ReplacementAttorneyDecisions actor.AttorneyDecisions
HowShouldReplacementAttorneysStepIn actor.ReplacementAttorneysStepIn
HowShouldReplacementAttorneysStepInDetails string
Restrictions string
WhenCanTheLpaBeUsed actor.CanBeUsedWhen
LifeSustainingTreatmentOption actor.LifeSustainingTreatment
SignedAt time.Time
CertificateProviderNotRelatedConfirmedAt time.Time
DonorIdentityConfirmed bool
Submitted bool
Paid bool
IsOrganisationDonor bool
Drafted bool
}
func (l Lpa) AllAttorneysSigned() bool {
if l.Attorneys.Len() == 0 {
return false
}
for _, attorneys := range []Attorneys{l.Attorneys, l.ReplacementAttorneys} {
for _, a := range attorneys.Attorneys {
if a.SignedAt.IsZero() {
return false
}
}
if t := attorneys.TrustCorporation; t.Name != "" {
if len(t.Signatories) == 0 {
return false
}
for _, s := range t.Signatories {
if s.SignedAt.IsZero() {
return false
}
}
}
}
return true
}
func lpaResponseToLpa(l lpaResponse) *Lpa {
var attorneys, replacementAttorneys []Attorney
for _, a := range l.Attorneys {
at := Attorney{
UID: a.UID,
FirstNames: a.FirstNames,
LastName: a.LastName,
DateOfBirth: a.DateOfBirth,
Email: a.Email,
Address: a.Address,
Mobile: a.Mobile,
SignedAt: a.SignedAt,
ContactLanguagePreference: a.ContactLanguagePreference,
Channel: a.Channel,
}
if a.Status == "replacement" {
replacementAttorneys = append(replacementAttorneys, at)
} else if a.Status == "active" {
attorneys = append(attorneys, at)
}
}
var trustCorporation, replacementTrustCorporation TrustCorporation
for _, t := range l.TrustCorporations {
tc := TrustCorporation{
UID: t.UID,
Name: t.Name,
CompanyNumber: t.CompanyNumber,
Email: t.Email,
Address: t.Address,
Mobile: t.Mobile,
Signatories: t.Signatories,
ContactLanguagePreference: t.ContactLanguagePreference,
Channel: t.Channel,
}
if t.Status == "replacement" {
replacementTrustCorporation = tc
} else if t.Status == "active" {
trustCorporation = tc
}
}
var peopleToNotify []actor.PersonToNotify
for _, p := range l.PeopleToNotify {
peopleToNotify = append(peopleToNotify, actor.PersonToNotify{
UID: p.UID,
FirstNames: p.FirstNames,
LastName: p.LastName,
Address: p.Address,
})
}
var confirmedAt time.Time
if v := l.CertificateProviderNotRelatedConfirmedAt; v != nil {
confirmedAt = *v
}
return &Lpa{
LpaUID: l.UID,
RegisteredAt: l.RegistrationDate,
UpdatedAt: l.UpdatedAt,
Type: l.LpaType,
Channel: l.Channel,
Donor: actor.Donor{
UID: l.Donor.UID,
FirstNames: l.Donor.FirstNames,
LastName: l.Donor.LastName,
DateOfBirth: l.Donor.DateOfBirth,
Email: l.Donor.Email,
Address: l.Donor.Address,
OtherNames: l.Donor.OtherNamesKnownBy,
},
Attorneys: Attorneys{
Attorneys: attorneys,
TrustCorporation: trustCorporation,
},
ReplacementAttorneys: Attorneys{
Attorneys: replacementAttorneys,
TrustCorporation: replacementTrustCorporation,
},
CertificateProvider: l.CertificateProvider,
PeopleToNotify: peopleToNotify,
AttorneyDecisions: actor.AttorneyDecisions{
How: l.HowAttorneysMakeDecisions,
Details: l.HowAttorneysMakeDecisionsDetails,
},
ReplacementAttorneyDecisions: actor.AttorneyDecisions{
How: l.HowReplacementAttorneysMakeDecisions,
Details: l.HowReplacementAttorneysMakeDecisionsDetails,
},
HowShouldReplacementAttorneysStepIn: l.HowReplacementAttorneysStepIn,
HowShouldReplacementAttorneysStepInDetails: l.HowReplacementAttorneysStepInDetails,
Restrictions: l.Restrictions,
WhenCanTheLpaBeUsed: l.WhenTheLpaCanBeUsed,
LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption,
SignedAt: l.SignedAt,
CertificateProviderNotRelatedConfirmedAt: confirmedAt,
}
}
func FromDonorProvidedDetails(l *actor.DonorProvidedDetails) *Lpa {
attorneys := Attorneys{}
for _, a := range l.Attorneys.Attorneys {
attorneys.Attorneys = append(attorneys.Attorneys, Attorney{
UID: a.UID,
FirstNames: a.FirstNames,
LastName: a.LastName,
DateOfBirth: a.DateOfBirth,
Email: a.Email,
Address: a.Address,
})
}
if c := l.Attorneys.TrustCorporation; c.Name != "" {
attorneys.TrustCorporation = TrustCorporation{
UID: c.UID,
Name: c.Name,
CompanyNumber: c.CompanyNumber,
Email: c.Email,
Address: c.Address,
}
}
var replacementAttorneys Attorneys
for _, a := range l.ReplacementAttorneys.Attorneys {
replacementAttorneys.Attorneys = append(replacementAttorneys.Attorneys, Attorney{
UID: a.UID,
FirstNames: a.FirstNames,
LastName: a.LastName,
DateOfBirth: a.DateOfBirth,
Email: a.Email,
Address: a.Address,
})
}
if c := l.ReplacementAttorneys.TrustCorporation; c.Name != "" {
replacementAttorneys.TrustCorporation = TrustCorporation{
UID: c.UID,
Name: c.Name,
CompanyNumber: c.CompanyNumber,
Email: c.Email,
Address: c.Address,
}
}
return &Lpa{
LpaID: l.LpaID,
LpaUID: l.LpaUID,
UpdatedAt: l.UpdatedAt,
Type: l.Type,
Donor: l.Donor,
Attorneys: attorneys,
ReplacementAttorneys: replacementAttorneys,
CertificateProvider: CertificateProvider{
UID: l.CertificateProvider.UID,
FirstNames: l.CertificateProvider.FirstNames,
LastName: l.CertificateProvider.LastName,
Email: l.CertificateProvider.Email,
Phone: l.CertificateProvider.Mobile,
Address: l.CertificateProvider.Address,
Channel: l.CertificateProvider.CarryOutBy,
},
PeopleToNotify: l.PeopleToNotify,
AttorneyDecisions: l.AttorneyDecisions,
ReplacementAttorneyDecisions: l.ReplacementAttorneyDecisions,
HowShouldReplacementAttorneysStepIn: l.HowShouldReplacementAttorneysStepIn,
HowShouldReplacementAttorneysStepInDetails: l.HowShouldReplacementAttorneysStepInDetails,
Restrictions: l.Restrictions,
WhenCanTheLpaBeUsed: l.WhenCanTheLpaBeUsed,
LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption,
SignedAt: l.SignedAt,
CertificateProviderNotRelatedConfirmedAt: l.CertificateProviderNotRelatedConfirmedAt,
}
}
func (c *Client) Lpa(ctx context.Context, lpaUID string) (*Lpa, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/lpas/"+lpaUID, nil)
if err != nil {
return nil, err
}
resp, err := c.do(ctx, actoruid.Service, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
switch resp.StatusCode {
case http.StatusOK:
var v lpaResponse
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, err
}
return lpaResponseToLpa(v), nil
case http.StatusNotFound:
return nil, ErrNotFound
default:
body, _ := io.ReadAll(resp.Body)
return nil, responseError{
name: fmt.Sprintf("expected 200 response but got %d", resp.StatusCode),
body: string(body),
}
}
}
type lpasRequest struct {
UIDs []string `json:"uids"`
}
type lpasResponse struct {
Lpas []lpaResponse `json:"lpas"`
}
func (c *Client) Lpas(ctx context.Context, lpaUIDs []string) ([]*Lpa, error) {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(lpasRequest{UIDs: lpaUIDs}); err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/lpas", &buf)
if err != nil {
return nil, err
}
resp, err := c.do(ctx, actoruid.Service, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, responseError{
name: fmt.Sprintf("expected 200 response but got %d", resp.StatusCode),
body: string(body),
}
}
var v lpasResponse
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, err
}
var lpas []*Lpa
for _, l := range v.Lpas {
lpas = append(lpas, lpaResponseToLpa(l))
}
return lpas, nil
}