-
Notifications
You must be signed in to change notification settings - Fork 2
/
confirm_your_details.go
70 lines (57 loc) · 2.19 KB
/
confirm_your_details.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
package certificateprovider
import (
"net/http"
"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
type confirmYourDetailsData struct {
App page.AppData
Errors validation.List
Lpa *lpastore.Lpa
CertificateProvider *actor.CertificateProviderProvidedDetails
PhoneNumberLabel string
AddressLabel string
DetailComponentContent string
}
func ConfirmYourDetails(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) page.Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error {
certificateProvider, err := certificateProviderStore.Get(r.Context())
if err != nil {
return err
}
lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
}
if r.Method == http.MethodPost {
certificateProvider.Tasks.ConfirmYourDetails = actor.TaskCompleted
if err := certificateProviderStore.Put(r.Context(), certificateProvider); err != nil {
return err
}
redirect := page.Paths.CertificateProvider.YourRole
if !lpa.SignedAt.IsZero() {
redirect = page.Paths.CertificateProvider.TaskList
}
return redirect.Redirect(w, r, appData, certificateProvider.LpaID)
}
data := &confirmYourDetailsData{
App: appData,
CertificateProvider: certificateProvider,
Lpa: lpa,
PhoneNumberLabel: "mobileNumber",
AddressLabel: "address",
DetailComponentContent: "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentLay",
}
if lpa.Donor.Channel.IsPaper() {
data.PhoneNumberLabel = "contactNumber"
}
if lpa.CertificateProvider.Relationship.IsProfessionally() {
data.AddressLabel = "workAddress"
data.DetailComponentContent = "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentProfessional"
}
return tmpl(w, data)
}
}