-
Notifications
You must be signed in to change notification settings - Fork 0
/
deputy_hub.go
73 lines (60 loc) · 1.83 KB
/
deputy_hub.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
package server
import (
"github.com/ministryofjustice/opg-sirius-supervision-deputy-hub/internal/sirius"
"html/template"
"net/http"
"net/url"
)
type DeputyHubInformation interface {
GetDeputyClients(sirius.Context, sirius.ClientListParams) (sirius.ClientList, error)
}
type deputyHubVars struct {
SuccessMessage template.HTML
ActiveClientCount int
AppVars
}
func renderTemplateForDeputyHub(client DeputyHubInformation, tmpl Template) Handler {
return func(app AppVars, w http.ResponseWriter, r *http.Request) error {
if r.Method != http.MethodGet {
return StatusError(http.StatusMethodNotAllowed)
}
ctx := getContext(r)
var selectedOrderStatuses []string
selectedOrderStatuses = append(selectedOrderStatuses, "ACTIVE")
params := sirius.ClientListParams{
DeputyId: app.DeputyId(),
Search: 1,
DeputyType: app.DeputyType(),
OrderStatuses: selectedOrderStatuses,
}
clientList, err := client.GetDeputyClients(ctx, params)
if err != nil {
return err
}
app.PageName = "Deputy details"
vars := deputyHubVars{
AppVars: app,
ActiveClientCount: clientList.Metadata.TotalActiveClients,
SuccessMessage: template.HTML(getSuccessFromUrl(r.URL, app.DeputyDetails)),
}
return tmpl.ExecuteTemplate(w, "page", vars)
}
}
func getSuccessFromUrl(url *url.URL, deputyDetails sirius.DeputyDetails) string {
switch url.Query().Get("success") {
case "deputyDetails":
return "Deputy details updated"
case "ecm":
return "<abbr title='Executive Case Manager'>ECM</abbr> changed to " + deputyDetails.ExecutiveCaseManager.EcmName
case "importantInformation":
return "Important information updated"
case "newFirm":
return "Firm added"
case "firm":
return "Firm changed to " + deputyDetails.Firm.FirmName
case "teamDetails":
return "Team details updated"
default:
return ""
}
}