Skip to content

Commit d2c2926

Browse files
authored
refactor: add sqlc for organisation invites (#2520)
* Refactor organisation invite repository to a standalone module using SQLc-generation. * Add comprehensive unit tests for organisation invites module
1 parent 3462af0 commit d2c2926

17 files changed

+2399
-577
lines changed

api/handlers/organisation_invite.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/frain-dev/convoy/auth"
1414
"github.com/frain-dev/convoy/database/postgres"
1515
"github.com/frain-dev/convoy/datastore"
16+
"github.com/frain-dev/convoy/internal/organisation_invites"
1617
"github.com/frain-dev/convoy/internal/organisation_members"
1718
"github.com/frain-dev/convoy/internal/organisations"
1819
m "github.com/frain-dev/convoy/internal/pkg/middleware"
@@ -55,7 +56,7 @@ func (h *Handler) InviteUserToOrganisation(w http.ResponseWriter, r *http.Reques
5556

5657
inviteService := &services.InviteUserService{
5758
Queue: h.A.Queue,
58-
InviteRepo: postgres.NewOrgInviteRepo(h.A.DB),
59+
InviteRepo: organisation_invites.New(h.A.Logger, h.A.DB),
5960
InviteeEmail: newIV.InviteeEmail,
6061
Licenser: h.A.Licenser,
6162
Role: newIV.Role,
@@ -82,7 +83,7 @@ func (h *Handler) GetPendingOrganisationInvites(w http.ResponseWriter, r *http.R
8283
}
8384

8485
pageable := m.GetPageableFromContext(r.Context())
85-
invites, paginationData, err := postgres.NewOrgInviteRepo(h.A.DB).LoadOrganisationsInvitesPaged(r.Context(), org.UID, datastore.InviteStatusPending, pageable)
86+
invites, paginationData, err := organisation_invites.New(h.A.Logger, h.A.DB).LoadOrganisationsInvitesPaged(r.Context(), org.UID, datastore.InviteStatusPending, pageable)
8687
if err != nil {
8788
log.FromContext(r.Context()).WithError(err).Error("failed to load organisation invites")
8889
_ = render.Render(w, r, util.NewServiceErrResponse(err))
@@ -111,7 +112,7 @@ func (h *Handler) ProcessOrganisationMemberInvite(w http.ResponseWriter, r *http
111112

112113
prc := services.ProcessInviteService{
113114
Queue: h.A.Queue,
114-
InviteRepo: postgres.NewOrgInviteRepo(h.A.DB),
115+
InviteRepo: organisation_invites.New(h.A.Logger, h.A.DB),
115116
UserRepo: postgres.NewUserRepo(h.A.DB),
116117
OrgRepo: organisations.New(h.A.Logger, h.A.DB),
117118
OrgMemberRepo: organisation_members.New(h.A.Logger, h.A.DB),
@@ -136,7 +137,7 @@ func (h *Handler) FindUserByInviteToken(w http.ResponseWriter, r *http.Request)
136137

137138
fub := &services.FindUserByInviteTokenService{
138139
Queue: h.A.Queue,
139-
InviteRepo: postgres.NewOrgInviteRepo(h.A.DB),
140+
InviteRepo: organisation_invites.New(h.A.Logger, h.A.DB),
140141
OrgRepo: organisations.New(h.A.Logger, h.A.DB),
141142
UserRepo: postgres.NewUserRepo(h.A.DB),
142143
Token: token,
@@ -174,7 +175,7 @@ func (h *Handler) ResendOrganizationInvite(w http.ResponseWriter, r *http.Reques
174175

175176
rom := &services.ResendOrgMemberService{
176177
Queue: h.A.Queue,
177-
InviteRepo: postgres.NewOrgInviteRepo(h.A.DB),
178+
InviteRepo: organisation_invites.New(h.A.Logger, h.A.DB),
178179
InviteID: chi.URLParam(r, "inviteID"),
179180
User: user,
180181
Organisation: org,
@@ -204,7 +205,7 @@ func (h *Handler) CancelOrganizationInvite(w http.ResponseWriter, r *http.Reques
204205

205206
cancelInvite := services.CancelOrgMemberService{
206207
Queue: h.A.Queue,
207-
InviteRepo: postgres.NewOrgInviteRepo(h.A.DB),
208+
InviteRepo: organisation_invites.New(h.A.Logger, h.A.DB),
208209
InviteID: chi.URLParam(r, "inviteID"),
209210
}
210211

api/testdb/seed.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/frain-dev/convoy/database/postgres"
2222
"github.com/frain-dev/convoy/datastore"
2323
"github.com/frain-dev/convoy/internal/api_keys"
24+
"github.com/frain-dev/convoy/internal/organisation_invites"
2425
"github.com/frain-dev/convoy/internal/organisation_members"
2526
"github.com/frain-dev/convoy/internal/organisations"
2627
"github.com/frain-dev/convoy/internal/portal_links"
@@ -286,7 +287,8 @@ func SeedOrganisationInvite(db database.Database, org *datastore.Organisation, e
286287
UpdatedAt: time.Now(),
287288
}
288289

289-
orgInviteRepo := postgres.NewOrgInviteRepo(db)
290+
logger := log.NewLogger(os.Stdout)
291+
orgInviteRepo := organisation_invites.New(logger, db)
290292
err := orgInviteRepo.CreateOrganisationInvite(context.TODO(), iv)
291293
if err != nil {
292294
return nil, err

0 commit comments

Comments
 (0)