Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk committed Feb 1, 2024
1 parent d32570e commit 937d100
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 119 deletions.
5 changes: 0 additions & 5 deletions internal/actor/organisation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package actor

import (
"strings"
"time"
)

Expand Down Expand Up @@ -30,10 +29,6 @@ type Member struct {
UpdatedAt time.Time
}

func (m *Member) OrganisationID() string {
return strings.Split(m.SK, "ORGANISATION#")[1]
}

// A MemberInvite is created to allow a new Member to join an Organisation
type MemberInvite struct {
PK, SK string
Expand Down
2 changes: 0 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ func App(
supporter.Register(
rootMux,
supporterTmpls,
donorTmpls,
oneLoginClient,
sessionStore,
organisationStore,
notFoundHandler,
errorHandler,
notifyClient,
donorStore,
)

certificateprovider.Register(
Expand Down
18 changes: 0 additions & 18 deletions internal/app/organisation_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,6 @@ func (s *organisationStore) Get(ctx context.Context) (*actor.Organisation, error
return &organisation, nil
}

func (s *organisationStore) GetMember(ctx context.Context) (*actor.Member, error) {
data, err := page.SessionDataFromContext(ctx)
if err != nil {
return nil, err
}

if data.SessionID == "" {
return nil, errors.New("organisationStore.GetMember requires SessionID")
}

var member actor.Member
if err := s.dynamoClient.OneByPartialSk(ctx, memberKey(data.SessionID), organisationKey(""), &member); err != nil {
return nil, err
}

return &member, nil
}

func (s *organisationStore) CreateMemberInvite(ctx context.Context, organisation *actor.Organisation, email, code string) error {
invite := &actor.MemberInvite{
PK: memberInviteKey(code),
Expand Down
1 change: 0 additions & 1 deletion internal/page/app_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type AppData struct {
AppPublicURL string
IsSupporter bool
OrganisationName string
OrganisationID string
}

func (d AppData) Redirect(w http.ResponseWriter, r *http.Request, url string) error {
Expand Down
11 changes: 0 additions & 11 deletions internal/page/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ func (p SupporterPath) Format() string {
return "/supporter" + string(p)
}

func (p SupporterPath) FormatLpa(id string) string {
return "/supporter/lpa/" + id + string(p)
}

func (p SupporterPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData) error {
http.Redirect(w, r, appData.Lang.URL(p.Format()), http.StatusFound)
return nil
Expand All @@ -126,11 +122,6 @@ func (p SupporterPath) RedirectQuery(w http.ResponseWriter, r *http.Request, app
return nil
}

func (p SupporterPath) RedirectToLpa(w http.ResponseWriter, r *http.Request, appData AppData, donor *actor.DonorProvidedDetails) error {
http.Redirect(w, r, appData.Lang.URL(p.FormatLpa(donor.LpaID)), http.StatusFound)
return nil
}

type AttorneyPaths struct {
EnterReferenceNumber Path
Login Path
Expand Down Expand Up @@ -187,7 +178,6 @@ type SupporterPaths struct {
Dashboard SupporterPath
InviteMember SupporterPath
InviteMemberConfirmation SupporterPath
DonorDetails SupporterPath
}

type AppPaths struct {
Expand Down Expand Up @@ -359,7 +349,6 @@ var Paths = AppPaths{
Dashboard: "/supporter-dashboard",
InviteMember: "/invite-member",
InviteMemberConfirmation: "/invite-member-confirmation",
DonorDetails: "/donor-details",
},

HealthCheck: HealthCheckPaths{
Expand Down
16 changes: 3 additions & 13 deletions internal/page/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@ import (

func RouteToPrefix(prefix string, mux http.Handler, notFoundHandler Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
n := 4
idIndex := 2
pathIndex := 3

if strings.Contains(r.URL.Path, "/supporter/") {
n = 5
idIndex = 3
pathIndex = 4
}

parts := strings.SplitN(r.URL.Path, "/", n)
if len(parts) != n {
parts := strings.SplitN(r.URL.Path, "/", 4)
if len(parts) != 4 {
notFoundHandler(AppDataFromContext(r.Context()), w, r)
return
}

id, path := parts[idIndex], "/"+parts[pathIndex]
id, path := parts[2], "/"+parts[3]

r2 := new(http.Request)
*r2 = *r
Expand Down
58 changes: 0 additions & 58 deletions internal/page/supporter/mock_OrganisationStore_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions internal/page/supporter/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type OrganisationStore interface {
CreateMemberInvite(ctx context.Context, organisation *actor.Organisation, email, code string) error
Get(ctx context.Context) (*actor.Organisation, error)
CreateLPA(ctx context.Context, organisationID string) (*actor.DonorProvidedDetails, error)
GetMember(ctx context.Context) (*actor.Member, error)
}

type OneLoginClient interface {
Expand All @@ -39,13 +38,6 @@ type NotifyClient interface {
SendEmail(context context.Context, to string, email notify.Email) error
}

type DonorStore interface {
Get(ctx context.Context) (*actor.DonorProvidedDetails, error)
Latest(ctx context.Context) (*actor.DonorProvidedDetails, error)
Put(ctx context.Context, donor *actor.DonorProvidedDetails) error
Delete(ctx context.Context) error
}

type Template func(io.Writer, interface{}) error

type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation) error
Expand All @@ -54,14 +46,13 @@ type ErrorHandler func(http.ResponseWriter, *http.Request, error)

func Register(
rootMux *http.ServeMux,
supporterTmpls, donorTmpls template.Templates,
supporterTmpls template.Templates,
oneLoginClient OneLoginClient,
sessionStore SessionStore,
organisationStore OrganisationStore,
notFoundHandler page.Handler,
errorHandler page.ErrorHandler,
notifyClient NotifyClient,
donorStore DonorStore,
) {
supporterPaths := page.Paths.Supporter
handleRoot := makeHandle(rootMux, sessionStore, errorHandler)
Expand Down Expand Up @@ -149,7 +140,6 @@ func makeSupporterHandle(mux *http.ServeMux, store sesh.Store, errorHandler page

appData.Page = path.Format()
appData.IsSupporter = true
appData.OrganisationID = organisation.ID
appData.OrganisationName = organisation.Name

ctx = page.ContextWithAppData(page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID, OrganisationID: organisation.ID}), appData)
Expand Down

0 comments on commit 937d100

Please sign in to comment.