Refactor server to go-sqlite and ginext [WIP]
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/mathext"
|
||||
"net/http"
|
||||
@@ -37,7 +37,7 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/channels [GET]
|
||||
func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListChannels(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -50,6 +50,12 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var q query
|
||||
ctx, g, errResp := pctx.URI(&u).Query(&q).Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
ctx, errResp := h.app.StartRequest(g, &u, &q, nil, nil)
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
@@ -110,7 +116,7 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Channels: res}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Channels: res}))
|
||||
}
|
||||
|
||||
// GetChannel swaggerdoc
|
||||
@@ -129,14 +135,14 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/channels/{cid} [GET]
|
||||
func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetChannel(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -154,7 +160,7 @@ func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query channel", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, channel.JSON(true)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, channel.JSON(true)))
|
||||
}
|
||||
|
||||
// CreateChannel swaggerdoc
|
||||
@@ -173,7 +179,7 @@ func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/channels [POST]
|
||||
func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) CreateChannel(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -186,7 +192,7 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -247,11 +253,11 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create subscription", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, channel.WithSubscription(langext.Ptr(sub)).JSON(true)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, channel.WithSubscription(langext.Ptr(sub)).JSON(true)))
|
||||
|
||||
} else {
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, channel.WithSubscription(nil).JSON(true)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, channel.WithSubscription(nil).JSON(true)))
|
||||
|
||||
}
|
||||
|
||||
@@ -277,7 +283,7 @@ func (h APIHandler) CreateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/channels/{cid} [PATCH]
|
||||
func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) UpdateChannel(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
@@ -290,7 +296,7 @@ func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -367,7 +373,7 @@ func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query (updated) channel", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, channel.JSON(true)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, channel.JSON(true)))
|
||||
}
|
||||
|
||||
// ListChannelMessages swaggerdoc
|
||||
@@ -391,7 +397,7 @@ func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/channels/{cid}/messages [GET]
|
||||
func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListChannelMessages(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
ChannelUserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
@@ -410,7 +416,7 @@ func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var q query
|
||||
ctx, errResp := h.app.StartRequest(g, &u, &q, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Query(&q).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -455,5 +461,5 @@ func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
res = langext.ArrMap(messages, func(v models.Message) models.MessageJSON { return v.FullJSON() })
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Messages: res, NextPageToken: npt.Token(), PageSize: pageSize}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Messages: res, NextPageToken: npt.Token(), PageSize: pageSize}))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
)
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/clients [GET]
|
||||
func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListClients(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
res := langext.ArrMap(clients, func(v models.Client) models.ClientJSON { return v.JSON() })
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Clients: res}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Clients: res}))
|
||||
}
|
||||
|
||||
// GetClient swaggerdoc
|
||||
@@ -70,14 +70,14 @@ func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/clients/{cid} [GET]
|
||||
func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetClient(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, client.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, client.JSON()))
|
||||
}
|
||||
|
||||
// AddClient swaggerdoc
|
||||
@@ -114,7 +114,7 @@ func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/clients [POST]
|
||||
func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) AddClient(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -153,7 +153,7 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create client in db", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, client.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, client.JSON()))
|
||||
}
|
||||
|
||||
// DeleteClient swaggerdoc
|
||||
@@ -172,14 +172,14 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/clients/{cid} [DELETE]
|
||||
func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) DeleteClient(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to delete client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, client.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, client.JSON()))
|
||||
}
|
||||
|
||||
// UpdateClient swaggerdoc
|
||||
@@ -225,7 +225,7 @@ func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/clients/{cid} [PATCH]
|
||||
func (h APIHandler) UpdateClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) UpdateClient(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
@@ -239,7 +239,7 @@ func (h APIHandler) UpdateClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -303,5 +303,5 @@ func (h APIHandler) UpdateClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query (updated) client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, client.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, client.JSON()))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
)
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/keys [GET]
|
||||
func (h APIHandler) ListUserKeys(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListUserKeys(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (h APIHandler) ListUserKeys(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (h APIHandler) ListUserKeys(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
res := langext.ArrMap(toks, func(v models.KeyToken) models.KeyTokenJSON { return v.JSON() })
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Keys: res}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Keys: res}))
|
||||
}
|
||||
|
||||
// GetCurrentUserKey swaggerdoc
|
||||
@@ -73,13 +73,13 @@ func (h APIHandler) ListUserKeys(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/keys/current [GET]
|
||||
func (h APIHandler) GetCurrentUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetCurrentUserKey(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func (h APIHandler) GetCurrentUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, keytoken.JSON().WithToken(keytoken.Token)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, keytoken.JSON().WithToken(keytoken.Token)))
|
||||
}
|
||||
|
||||
// GetUserKey swaggerdoc
|
||||
@@ -122,14 +122,14 @@ func (h APIHandler) GetCurrentUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/keys/{kid} [GET]
|
||||
func (h APIHandler) GetUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetUserKey(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
KeyID models.KeyTokenID `uri:"kid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func (h APIHandler) GetUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, keytoken.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, keytoken.JSON()))
|
||||
}
|
||||
|
||||
// UpdateUserKey swaggerdoc
|
||||
@@ -168,7 +168,7 @@ func (h APIHandler) GetUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/keys/{kid} [PATCH]
|
||||
func (h APIHandler) UpdateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) UpdateUserKey(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
KeyID models.KeyTokenID `uri:"kid" binding:"entityid"`
|
||||
@@ -182,7 +182,7 @@ func (h APIHandler) UpdateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (h APIHandler) UpdateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
keytoken.Channels = *b.Channels
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, keytoken.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, keytoken.JSON()))
|
||||
}
|
||||
|
||||
// CreateUserKey swaggerdoc
|
||||
@@ -265,7 +265,7 @@ func (h APIHandler) UpdateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/keys [POST]
|
||||
func (h APIHandler) CreateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) CreateUserKey(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func (h APIHandler) CreateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func (h APIHandler) CreateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create keytoken in db", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, keytok.JSON().WithToken(token)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, keytok.JSON().WithToken(token)))
|
||||
}
|
||||
|
||||
// DeleteUserKey swaggerdoc
|
||||
@@ -334,14 +334,14 @@ func (h APIHandler) CreateUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/keys/{kid} [DELETE]
|
||||
func (h APIHandler) DeleteUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) DeleteUserKey(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
KeyID models.KeyTokenID `uri:"kid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -368,5 +368,5 @@ func (h APIHandler) DeleteUserKey(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to delete client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, client.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, client.JSON()))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -11,7 +12,6 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||
ct "blackforestbytes.com/simplecloudnotifier/db/cursortoken"
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/mathext"
|
||||
)
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/messages [GET]
|
||||
func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListMessages(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
PageSize *int `json:"page_size" form:"page_size"`
|
||||
NextPageToken *string `json:"next_page_token" form:"next_page_token"`
|
||||
@@ -155,7 +155,7 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
res = langext.ArrMap(messages, func(v models.Message) models.MessageJSON { return v.FullJSON() })
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Messages: res, NextPageToken: npt.Token(), PageSize: pageSize}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Messages: res, NextPageToken: npt.Token(), PageSize: pageSize}))
|
||||
}
|
||||
|
||||
// GetMessage swaggerdoc
|
||||
@@ -176,13 +176,13 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/messages/{mid} [GET]
|
||||
func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetMessage(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
MessageID models.MessageID `uri:"mid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -204,7 +204,7 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// or we subscribe (+confirmed) to the channel and have read/admin key
|
||||
|
||||
if ctx.CheckPermissionMessageRead(msg) {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, msg.FullJSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, msg.FullJSON()))
|
||||
}
|
||||
|
||||
if uid := ctx.GetPermissionUserID(); uid != nil && ctx.CheckPermissionUserRead(*uid) == nil {
|
||||
@@ -222,7 +222,7 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
|
||||
// => perm okay
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, msg.FullJSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, msg.FullJSON()))
|
||||
}
|
||||
|
||||
return ginresp.APIError(g, 401, apierr.USER_AUTH_FAILED, "You are not authorized for this action", nil)
|
||||
@@ -244,13 +244,13 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/messages/{mid} [DELETE]
|
||||
func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) DeleteMessage(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
MessageID models.MessageID `uri:"mid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -282,5 +282,5 @@ func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to cancel deliveries", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, msg.FullJSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, msg.FullJSON()))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -25,13 +25,13 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/preview/users/{uid} [GET]
|
||||
func (h APIHandler) GetUserPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetUserPreview(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func (h APIHandler) GetUserPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query user", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, user.JSONPreview()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, user.JSONPreview()))
|
||||
}
|
||||
|
||||
// GetChannelPreview swaggerdoc
|
||||
@@ -67,13 +67,13 @@ func (h APIHandler) GetUserPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/preview/channels/{cid} [GET]
|
||||
func (h APIHandler) GetChannelPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetChannelPreview(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func (h APIHandler) GetChannelPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query channel", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, channel.JSONPreview()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, channel.JSONPreview()))
|
||||
}
|
||||
|
||||
// GetUserKeyPreview swaggerdoc
|
||||
@@ -109,13 +109,13 @@ func (h APIHandler) GetChannelPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/preview/keys/{kid} [GET]
|
||||
func (h APIHandler) GetUserKeyPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetUserKeyPreview(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
KeyID models.KeyTokenID `uri:"kid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -133,5 +133,5 @@ func (h APIHandler) GetUserKeyPreview(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query client", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, keytoken.JSONPreview()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, keytoken.JSONPreview()))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -47,7 +47,7 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/subscriptions [GET]
|
||||
func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListUserSubscriptions(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var q query
|
||||
ctx, errResp := h.app.StartRequest(g, &u, &q, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Query(&q).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
jsonres := langext.ArrMap(res, func(v models.Subscription) models.SubscriptionJSON { return v.JSON() })
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Subscriptions: jsonres}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Subscriptions: jsonres}))
|
||||
}
|
||||
|
||||
// ListChannelSubscriptions swaggerdoc
|
||||
@@ -147,7 +147,7 @@ func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/channels/{cid}/subscriptions [GET]
|
||||
func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) ListChannelSubscriptions(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
ChannelID models.ChannelID `uri:"cid" binding:"entityid"`
|
||||
@@ -157,7 +157,7 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
||||
|
||||
res := langext.ArrMap(clients, func(v models.Subscription) models.SubscriptionJSON { return v.JSON() })
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{Subscriptions: res}))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{Subscriptions: res}))
|
||||
}
|
||||
|
||||
// GetSubscription swaggerdoc
|
||||
@@ -201,14 +201,14 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/subscriptions/{sid} [GET]
|
||||
func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetSubscription(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -229,7 +229,7 @@ func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 404, apierr.SUBSCRIPTION_USER_MISMATCH, "Subscription not found", nil)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, subscription.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, subscription.JSON()))
|
||||
}
|
||||
|
||||
// CancelSubscription swaggerdoc
|
||||
@@ -248,14 +248,14 @@ func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/subscriptions/{sid} [DELETE]
|
||||
func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) CancelSubscription(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to delete subscription", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, subscription.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, subscription.JSON()))
|
||||
}
|
||||
|
||||
// CreateSubscription swaggerdoc
|
||||
@@ -301,7 +301,7 @@ func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/subscriptions [POST]
|
||||
func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) CreateSubscription(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
var u uri
|
||||
var q query
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, &q, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Query(&q).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -378,7 +378,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
existingSub.Confirmed = true
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, existingSub.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, existingSub.JSON()))
|
||||
}
|
||||
|
||||
sub, err := h.database.CreateSubscription(ctx, u.UserID, channel, channel.OwnerUserID == u.UserID)
|
||||
@@ -386,7 +386,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create subscription", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, sub.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, sub.JSON()))
|
||||
}
|
||||
|
||||
// UpdateSubscription swaggerdoc
|
||||
@@ -406,7 +406,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid}/subscriptions/{sid} [PATCH]
|
||||
func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) UpdateSubscription(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
SubscriptionID models.SubscriptionID `uri:"sid" binding:"entityid"`
|
||||
@@ -417,7 +417,7 @@ func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -455,5 +455,5 @@ func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query subscription", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, subscription.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, subscription.JSON()))
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
)
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users [POST]
|
||||
func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) CreateUser(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type body struct {
|
||||
FCMToken string `json:"fcm_token"`
|
||||
ProToken *string `json:"pro_token"`
|
||||
@@ -39,7 +39,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, nil, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
log.Info().Msg(fmt.Sprintf("Sucessfully created new user %s (client: %v)", userobj.UserID, b.NoClient))
|
||||
|
||||
if b.NoClient {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, userobj.JSONWithClients(make([]models.Client, 0), adminKey, sendKey, readKey)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, userobj.JSONWithClients(make([]models.Client, 0), adminKey, sendKey, readKey)))
|
||||
} else {
|
||||
err := h.database.DeleteClientsByFCM(ctx, b.FCMToken)
|
||||
if err != nil {
|
||||
@@ -129,7 +129,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to create client in db", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, userobj.JSONWithClients([]models.Client{client}, adminKey, sendKey, readKey)))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, userobj.JSONWithClients([]models.Client{client}, adminKey, sendKey, readKey)))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -149,13 +149,13 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid} [GET]
|
||||
func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) GetUser(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, nil, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query user", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, user.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, user.JSON()))
|
||||
}
|
||||
|
||||
// UpdateUser swaggerdoc
|
||||
@@ -195,7 +195,7 @@ func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/users/{uid} [PATCH]
|
||||
func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h APIHandler) UpdateUser(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid" binding:"entityid"`
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
var u uri
|
||||
var b body
|
||||
ctx, errResp := h.app.StartRequest(g, &u, nil, &b, nil)
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.URI(&u).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -261,5 +261,5 @@ func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query (updated) user", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, user.JSON()))
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, user.JSON()))
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/db/simplectx"
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
sqlite3 "github.com/mattn/go-sqlite3"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/timeext"
|
||||
"net/http"
|
||||
@@ -51,12 +51,18 @@ type pingResponseInfo struct {
|
||||
// @Router /api/ping [put]
|
||||
// @Router /api/ping [delete]
|
||||
// @Router /api/ping [patch]
|
||||
func (h CommonHandler) Ping(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CommonHandler) Ping(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
_, _ = buf.ReadFrom(g.Request.Body)
|
||||
resuestBody := buf.String()
|
||||
|
||||
return ginresp.JSON(http.StatusOK, pingResponse{
|
||||
return ginext.JSON(http.StatusOK, pingResponse{
|
||||
Message: "Pong",
|
||||
Info: pingResponseInfo{
|
||||
Method: g.Request.Method,
|
||||
@@ -78,7 +84,7 @@ func (h CommonHandler) Ping(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api/db-test [post]
|
||||
func (h CommonHandler) DatabaseTest(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CommonHandler) DatabaseTest(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type response struct {
|
||||
Success bool `json:"success"`
|
||||
LibVersion string `json:"libVersion"`
|
||||
@@ -86,8 +92,11 @@ func (h CommonHandler) DatabaseTest(g *gin.Context) ginresp.HTTPResponse {
|
||||
SourceID string `json:"sourceID"`
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
ctx, _, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
libVersion, libVersionNumber, sourceID := sqlite3.Version()
|
||||
|
||||
@@ -96,7 +105,7 @@ func (h CommonHandler) DatabaseTest(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.InternalError(err)
|
||||
}
|
||||
|
||||
return ginresp.JSON(http.StatusOK, response{
|
||||
return ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
LibVersion: libVersion,
|
||||
LibVersionNumber: libVersionNumber,
|
||||
@@ -114,13 +123,16 @@ func (h CommonHandler) DatabaseTest(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api/health [get]
|
||||
func (h CommonHandler) Health(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CommonHandler) Health(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type response struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
ctx, _, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
_, libVersionNumber, _ := sqlite3.Version()
|
||||
|
||||
@@ -161,7 +173,7 @@ func (h CommonHandler) Health(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
}
|
||||
|
||||
return ginresp.JSON(http.StatusOK, response{Status: "ok"})
|
||||
return ginext.JSON(http.StatusOK, response{Status: "ok"})
|
||||
}
|
||||
|
||||
// Sleep swaggerdoc
|
||||
@@ -177,7 +189,7 @@ func (h CommonHandler) Health(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api/sleep/{secs} [post]
|
||||
func (h CommonHandler) Sleep(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CommonHandler) Sleep(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
Seconds float64 `uri:"secs"`
|
||||
}
|
||||
@@ -187,6 +199,12 @@ func (h CommonHandler) Sleep(g *gin.Context) ginresp.HTTPResponse {
|
||||
Duration float64 `json:"duration"`
|
||||
}
|
||||
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
t0 := time.Now().Format(time.RFC3339Nano)
|
||||
|
||||
var u uri
|
||||
@@ -198,15 +216,21 @@ func (h CommonHandler) Sleep(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
t1 := time.Now().Format(time.RFC3339Nano)
|
||||
|
||||
return ginresp.JSON(http.StatusOK, response{
|
||||
return ginext.JSON(http.StatusOK, response{
|
||||
Start: t0,
|
||||
End: t1,
|
||||
Duration: u.Seconds,
|
||||
})
|
||||
}
|
||||
|
||||
func (h CommonHandler) NoRoute(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.JSON(http.StatusNotFound, gin.H{
|
||||
func (h CommonHandler) NoRoute(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return ginext.JSON(http.StatusNotFound, gin.H{
|
||||
"": "================ ROUTE NOT FOUND ================",
|
||||
"FullPath": g.FullPath(),
|
||||
"Method": g.Request.Method,
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
)
|
||||
@@ -47,7 +47,7 @@ func NewCompatHandler(app *logic.Application) CompatHandler {
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /send.php [POST]
|
||||
func (h CompatHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) SendMessage(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type combined struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -92,7 +92,7 @@ func (h CompatHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
} else {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
ErrorID: apierr.NO_ERROR,
|
||||
ErrorHighlight: -1,
|
||||
@@ -127,7 +127,7 @@ func (h CompatHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/register.php [get]
|
||||
func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Register(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
FCMToken *string `json:"fcm_token" form:"fcm_token"`
|
||||
Pro *string `json:"pro" form:"pro"`
|
||||
@@ -216,7 +216,7 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.SendAPIError(g, 500, apierr.DATABASE_ERROR, hl.NONE, "Failed to create userid<old>", err)
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "New user registered",
|
||||
UserID: oldid,
|
||||
@@ -245,7 +245,7 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/info.php [get]
|
||||
func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Info(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -321,7 +321,7 @@ func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(0, "Failed to query user")
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "ok",
|
||||
UserID: *data.UserID,
|
||||
@@ -354,7 +354,7 @@ func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/ack.php [get]
|
||||
func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Ack(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -434,7 +434,7 @@ func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse {
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "ok",
|
||||
PrevAckValue: langext.Conditional(ackBefore, 1, 0),
|
||||
@@ -460,7 +460,7 @@ func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/requery.php [get]
|
||||
func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Requery(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -545,7 +545,7 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse {
|
||||
})
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "ok",
|
||||
Count: len(compMsgs),
|
||||
@@ -573,7 +573,7 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/update.php [get]
|
||||
func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Update(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -673,7 +673,7 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(0, "Failed to query user")
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "user updated",
|
||||
UserID: *data.UserID,
|
||||
@@ -704,7 +704,7 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/expand.php [get]
|
||||
func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Expand(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -779,7 +779,7 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(0, "Failed to query message")
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "ok",
|
||||
Data: models.CompatMessage{
|
||||
@@ -816,7 +816,7 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure default {object} ginresp.compatAPIError
|
||||
//
|
||||
// @Router /api/upgrade.php [get]
|
||||
func (h CompatHandler) Upgrade(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h CompatHandler) Upgrade(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *int64 `json:"user_id" form:"user_id"`
|
||||
UserKey *string `json:"user_key" form:"user_key"`
|
||||
@@ -921,7 +921,7 @@ func (h CompatHandler) Upgrade(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.CompatAPIError(0, "Failed to query user")
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
Message: "user updated",
|
||||
UserID: *data.UserID,
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -41,7 +41,7 @@ func NewExternalHandler(app *logic.Application) ExternalHandler {
|
||||
// @Failure 500 {object} ginresp.apiError "An internal server error occurred - try again later"
|
||||
//
|
||||
// @Router /external/v1/uptime-kuma [POST]
|
||||
func (h ExternalHandler) UptimeKuma(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h ExternalHandler) UptimeKuma(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type query struct {
|
||||
UserID *models.UserID `form:"user_id" example:"7725"`
|
||||
KeyToken *string `form:"key" example:"P3TNH8mvv14fm"`
|
||||
@@ -128,7 +128,7 @@ func (h ExternalHandler) UptimeKuma(g *gin.Context) ginresp.HTTPResponse {
|
||||
return *errResp
|
||||
}
|
||||
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
MessageID: okResp.Message.MessageID,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package handler
|
||||
|
||||
import (
|
||||
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||
primarydb "blackforestbytes.com/simplecloudnotifier/db/impl/primary"
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"net/http"
|
||||
)
|
||||
@@ -49,7 +48,7 @@ func NewMessageHandler(app *logic.Application) MessageHandler {
|
||||
//
|
||||
// @Router / [POST]
|
||||
// @Router /send [POST]
|
||||
func (h MessageHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h MessageHandler) SendMessage(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type combined struct {
|
||||
UserID *models.UserID `json:"user_id" form:"user_id" example:"7725" `
|
||||
KeyToken *string `json:"key" form:"key" example:"P3TNH8mvv14fm" `
|
||||
@@ -78,7 +77,7 @@ func (h MessageHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
var b combined
|
||||
var q combined
|
||||
var f combined
|
||||
ctx, errResp := h.app.StartRequest(g, nil, &q, &b, &f, logic.RequestOptions{IgnoreWrongContentType: true})
|
||||
ctx, g, errResp := h.app.StartRequest(pctx.Form(&f).Query(&q).Body(&b).Start())
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
@@ -91,7 +90,7 @@ func (h MessageHandler) SendMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
} else {
|
||||
return ctx.FinishSuccess(ginresp.JSON(http.StatusOK, response{
|
||||
return ctx.FinishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Success: true,
|
||||
ErrorID: apierr.NO_ERROR,
|
||||
ErrorHighlight: -1,
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/rext"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -27,60 +28,104 @@ func NewWebsiteHandler(app *logic.Application) WebsiteHandler {
|
||||
}
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) Index(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) Index(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "index.html", true)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) APIDocs(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) APIDocs(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "api.html", true)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) APIDocsMore(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) APIDocsMore(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "api_more.html", true)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) MessageSent(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) MessageSent(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "message_sent.html", true)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) FaviconIco(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) FaviconIco(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "favicon.ico", false)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) FaviconPNG(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) FaviconPNG(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "favicon.png", false)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) Javascript(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) Javascript(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
ctx, g, errResp := pctx.Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
type uri struct {
|
||||
Filename string `uri:"fn"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
if err := g.ShouldBindUri(&u); err != nil {
|
||||
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return ginext.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
}
|
||||
|
||||
return h.serveAsset(g, "js/"+u.Filename, false)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) CSS(g *gin.Context) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) CSS(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
Filename string `uri:"fn"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
if err := g.ShouldBindUri(&u); err != nil {
|
||||
return ginresp.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
ctx, g, errResp := pctx.URI(&u).Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.serveAsset(g, "css/"+u.Filename, false)
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) serveAsset(g *gin.Context, fn string, repl bool) ginresp.HTTPResponse {
|
||||
func (h WebsiteHandler) serveAsset(g *gin.Context, fn string, repl bool) ginext.HTTPResponse {
|
||||
_data, err := website.Assets.ReadFile(fn)
|
||||
if err != nil {
|
||||
return ginresp.Status(http.StatusNotFound)
|
||||
return ginext.Status(http.StatusNotFound)
|
||||
}
|
||||
|
||||
data := string(_data)
|
||||
@@ -141,7 +186,7 @@ func (h WebsiteHandler) serveAsset(g *gin.Context, fn string, repl bool) ginresp
|
||||
mime = "image/svg+xml"
|
||||
}
|
||||
|
||||
return ginresp.Data(http.StatusOK, mime, []byte(data))
|
||||
return ginext.Data(http.StatusOK, mime, []byte(data))
|
||||
}
|
||||
|
||||
func (h WebsiteHandler) getReplConfig(key string) (string, bool) {
|
||||
|
||||
Reference in New Issue
Block a user