Refactor server to go-sqlite and ginext [WIP]
This commit is contained in:
@@ -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()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user