-
Notifications
You must be signed in to change notification settings - Fork 2
/
delete_organisation.go
47 lines (37 loc) · 1.45 KB
/
delete_organisation.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
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/search"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
type deleteOrganisationData struct {
App page.AppData
Errors validation.List
InProgressLPACount int
}
func DeleteOrganisation(tmpl template.Template, organisationStore OrganisationStore, sessionStore SessionStore, searchClient SearchClient) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error {
if r.Method == http.MethodPost {
if err := organisationStore.SoftDelete(r.Context(), organisation); err != nil {
return err
}
if err := sessionStore.ClearLogin(r, w); err != nil {
return err
}
return page.Paths.Supporter.OrganisationDeleted.RedirectQuery(w, r, appData, url.Values{"organisationName": {appData.SupporterData.OrganisationName}})
}
inProgressLPACount, err := searchClient.CountWithQuery(r.Context(), search.CountWithQueryReq{MustNotExist: "RegisteredAt"})
if err != nil {
return err
}
data := &deleteOrganisationData{
App: appData,
InProgressLPACount: inProgressLPACount,
}
return tmpl(w, data)
}
}