-
Notifications
You must be signed in to change notification settings - Fork 2
/
edit_organisation_name.go
44 lines (36 loc) · 1.22 KB
/
edit_organisation_name.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
package supporter
import (
"net/http"
"net/url"
"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
type editOrganisationNameData struct {
App page.AppData
Errors validation.List
Form *organisationNameForm
}
func EditOrganisationName(tmpl template.Template, organisationStore OrganisationStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error {
data := &editOrganisationNameData{
App: appData,
Form: &organisationNameForm{
Name: organisation.Name,
},
}
if r.Method == http.MethodPost {
data.Form = readOrganisationNameForm(r, "yourOrganisationName")
data.Errors = data.Form.Validate()
if data.Errors.None() {
organisation.Name = data.Form.Name
if err := organisationStore.Put(r.Context(), organisation); err != nil {
return err
}
return page.Paths.Supporter.OrganisationDetails.RedirectQuery(w, r, appData, url.Values{"updated": {"name"}})
}
}
return tmpl(w, data)
}
}