invites: add /count route
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
lm "github.com/hrfee/jfa-go/logmessages"
|
lm "github.com/hrfee/jfa-go/logmessages"
|
||||||
"github.com/itchyny/timefmt-go"
|
"github.com/itchyny/timefmt-go"
|
||||||
"github.com/lithammer/shortuuid/v3"
|
"github.com/lithammer/shortuuid/v3"
|
||||||
|
"github.com/timshannon/badgerhold/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -258,6 +259,22 @@ func (app *appContext) GenerateInvite(gc *gin.Context) {
|
|||||||
respondBool(200, true, gc)
|
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.
|
// @Summary Get invites.
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} getInvitesDTO
|
// @Success 200 {object} getInvitesDTO
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ func (app *appContext) loadRoutes(router *gin.Engine) {
|
|||||||
api.POST(p+"/users/enable", app.EnableDisableUsers)
|
api.POST(p+"/users/enable", app.EnableDisableUsers)
|
||||||
api.POST(p+"/invites", app.GenerateInvite)
|
api.POST(p+"/invites", app.GenerateInvite)
|
||||||
api.GET(p+"/invites", app.GetInvites)
|
api.GET(p+"/invites", app.GetInvites)
|
||||||
|
api.GET(p+"/invites/count", app.GetInviteCount)
|
||||||
api.DELETE(p+"/invites", app.DeleteInvite)
|
api.DELETE(p+"/invites", app.DeleteInvite)
|
||||||
api.POST(p+"/invites/profile", app.SetProfile)
|
api.POST(p+"/invites/profile", app.SetProfile)
|
||||||
api.GET(p+"/profiles", app.GetProfiles)
|
api.GET(p+"/profiles", app.GetProfiles)
|
||||||
|
|||||||
Reference in New Issue
Block a user