From 9409370984af46ccb88ca299bb3065f4ca60dec0 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 27 May 2025 18:22:17 +0100 Subject: [PATCH] invites: add /count route --- api-invites.go | 17 +++++++++++++++++ router.go | 1 + 2 files changed, 18 insertions(+) diff --git a/api-invites.go b/api-invites.go index 34bbea7..ef6b2e1 100644 --- a/api-invites.go +++ b/api-invites.go @@ -11,6 +11,7 @@ import ( lm "github.com/hrfee/jfa-go/logmessages" "github.com/itchyny/timefmt-go" "github.com/lithammer/shortuuid/v3" + "github.com/timshannon/badgerhold/v4" ) const ( @@ -258,6 +259,22 @@ func (app *appContext) GenerateInvite(gc *gin.Context) { respondBool(200, true, gc) } +// @Summary Get the number of invites stored in the database. +// @Produce json +// @Success 200 {object} PageCountDTO +// @Router /invites/count [get] +// @Security Bearer +// @tags Invites +func (app *appContext) GetInviteCount(gc *gin.Context) { + resp := PageCountDTO{} + var err error + resp.Count, err = app.storage.db.Count(&Invite{}, &badgerhold.Query{}) + if err != nil { + resp.Count = 0 + } + gc.JSON(200, resp) +} + // @Summary Get invites. // @Produce json // @Success 200 {object} getInvitesDTO diff --git a/router.go b/router.go index 31df88b..a7e3113 100644 --- a/router.go +++ b/router.go @@ -200,6 +200,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) { api.POST(p+"/users/enable", app.EnableDisableUsers) api.POST(p+"/invites", app.GenerateInvite) api.GET(p+"/invites", app.GetInvites) + api.GET(p+"/invites/count", app.GetInviteCount) api.DELETE(p+"/invites", app.DeleteInvite) api.POST(p+"/invites/profile", app.SetProfile) api.GET(p+"/profiles", app.GetProfiles)