Show more data in webapp deliveries-table
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"blackforestbytes.com/simplecloudnotifier/api/apierr"
|
||||
"blackforestbytes.com/simplecloudnotifier/api/ginresp"
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
"blackforestbytes.com/simplecloudnotifier/models"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/ginext"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetUserPreview swaggerdoc
|
||||
@@ -52,7 +53,7 @@ func (h APIHandler) GetUserPreview(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query user", err)
|
||||
}
|
||||
|
||||
return finishSuccess(ginext.JSON(http.StatusOK, user.JSONPreview()))
|
||||
return finishSuccess(ginext.JSON(http.StatusOK, user.Preview()))
|
||||
|
||||
})
|
||||
}
|
||||
@@ -175,3 +176,65 @@ func (h APIHandler) GetUserKeyPreview(pctx ginext.PreContext) ginext.HTTPRespons
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
// GetClientPreview swaggerdoc
|
||||
//
|
||||
// @Summary Get a client (similar to api-clients-get, but can be called from anyone and only returns a subset of fields)
|
||||
// @ID api-clients-get-preview
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param cid path string true "ClientID"
|
||||
//
|
||||
// @Success 200 {object} handler.GetClientPreview.response
|
||||
//
|
||||
// @Failure 400 {object} ginresp.apiError "supplied values/parameters cannot be parsed / are invalid"
|
||||
// @Failure 401 {object} ginresp.apiError "user is not authorized / has missing permissions"
|
||||
// @Failure 404 {object} ginresp.apiError "client not found"
|
||||
// @Failure 500 {object} ginresp.apiError "internal server error"
|
||||
//
|
||||
// @Router /api/v2/preview/clients/{cid} [GET]
|
||||
func (h APIHandler) GetClientPreview(pctx ginext.PreContext) ginext.HTTPResponse {
|
||||
type uri struct {
|
||||
ClientID models.ClientID `uri:"cid" binding:"entityid"`
|
||||
}
|
||||
type response struct {
|
||||
Client models.ClientPreview `json:"client"`
|
||||
User models.UserPreview `json:"user"`
|
||||
}
|
||||
|
||||
var u uri
|
||||
ctx, g, errResp := pctx.URI(&u).Start()
|
||||
if errResp != nil {
|
||||
return *errResp
|
||||
}
|
||||
defer ctx.Cancel()
|
||||
|
||||
return h.app.DoRequest(ctx, g, models.TLockRead, func(ctx *logic.AppContext, finishSuccess func(r ginext.HTTPResponse) ginext.HTTPResponse) ginext.HTTPResponse {
|
||||
|
||||
if permResp := ctx.CheckPermissionAny(); permResp != nil {
|
||||
return *permResp
|
||||
}
|
||||
|
||||
client, err := h.database.GetClientByID(ctx, u.ClientID)
|
||||
if client == nil {
|
||||
return ginresp.APIError(g, 404, apierr.CLIENT_NOT_FOUND, "Client not found", err)
|
||||
}
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query client", err)
|
||||
}
|
||||
|
||||
user, err := h.database.GetUser(ctx, client.UserID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return ginresp.APIError(g, 404, apierr.USER_NOT_FOUND, "User not found", err)
|
||||
}
|
||||
if err != nil {
|
||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query user", err)
|
||||
}
|
||||
|
||||
return finishSuccess(ginext.JSON(http.StatusOK, response{
|
||||
Client: client.Preview(),
|
||||
User: user.Preview(),
|
||||
}))
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func (h ExternalHandler) UptimeKuma(pctx ginext.PreContext) ginext.HTTPResponse
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.Shoutrrr.query false " "
|
||||
// @Param post_body body handler.Shoutrrr.body false " "
|
||||
// @Param post_body body handler.Shoutrrr.body false " "
|
||||
//
|
||||
// @Success 200 {object} handler.Shoutrrr.response
|
||||
// @Failure 400 {object} ginresp.apiError
|
||||
|
||||
@@ -171,6 +171,7 @@ func (r *Router) Init(e *ginext.GinWrapper) error {
|
||||
apiv2.GET("/preview/users/:uid").Handle(r.apiHandler.GetUserPreview)
|
||||
apiv2.GET("/preview/keys/:kid").Handle(r.apiHandler.GetUserKeyPreview)
|
||||
apiv2.GET("/preview/channels/:cid").Handle(r.apiHandler.GetChannelPreview)
|
||||
apiv2.GET("/preview/clients/:cid").Handle(r.apiHandler.GetClientPreview)
|
||||
}
|
||||
|
||||
// ================ Send API (unversioned) ================
|
||||
|
||||
Reference in New Issue
Block a user