invites: add /count route

This commit is contained in:
Harvey Tindall
2025-05-27 18:22:17 +01:00
parent 006fde502e
commit 9409370984
2 changed files with 18 additions and 0 deletions

View File

@@ -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

View File

@@ -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)