tags/grouping for API
This commit is contained in:
@@ -34,14 +34,15 @@ func NewAPIHandler(app *logic.Application) APIHandler {
|
||||
//
|
||||
// @Summary Create a new user
|
||||
// @ID api-user-create
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param post_body body handler.CreateUser.body false " "
|
||||
//
|
||||
// @Success 200 {object} models.UserJSON
|
||||
// @Success 200 {object} handler.sendMessageInternal.response
|
||||
// @Failure 400 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/ [POST]
|
||||
// @Router /api/users/ [POST]
|
||||
func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
type body struct {
|
||||
FCMToken string `json:"fcm_token" binding:"required"`
|
||||
@@ -117,6 +118,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Get a user
|
||||
// @ID api-user-get
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
//
|
||||
@@ -126,7 +128,7 @@ func (h APIHandler) CreateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid} [GET]
|
||||
// @Router /api/users/{uid} [GET]
|
||||
func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -159,6 +161,7 @@ func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Summary (Partially) update a user
|
||||
// @Description The body-values are optional, only send the ones you want to update
|
||||
// @ID api-user-update
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
//
|
||||
@@ -174,7 +177,7 @@ func (h APIHandler) GetUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid} [PATCH]
|
||||
// @Router /api/users/{uid} [PATCH]
|
||||
func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -271,6 +274,7 @@ func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary List all clients
|
||||
// @ID api-clients-list
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
//
|
||||
@@ -280,7 +284,7 @@ func (h APIHandler) UpdateUser(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/clients [GET]
|
||||
// @Router /api/users/{uid}/clients [GET]
|
||||
func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -314,6 +318,7 @@ func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Get a single clients
|
||||
// @ID api-clients-get
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param cid path int true "ClientID"
|
||||
@@ -324,7 +329,7 @@ func (h APIHandler) ListClients(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/clients/{cid} [GET]
|
||||
// @Router /api/users/{uid}/clients/{cid} [GET]
|
||||
func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -357,6 +362,7 @@ func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Add a new clients
|
||||
// @ID api-clients-create
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
//
|
||||
@@ -368,7 +374,7 @@ func (h APIHandler) GetClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/clients [POST]
|
||||
// @Router /api/users/{uid}/clients [POST]
|
||||
func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -413,6 +419,7 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Delete a client
|
||||
// @ID api-clients-delete
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param cid path int true "ClientID"
|
||||
@@ -423,7 +430,7 @@ func (h APIHandler) AddClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/clients [POST]
|
||||
// @Router /api/users/{uid}/clients [POST]
|
||||
func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -467,6 +474,7 @@ func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Description - "subscribed_any" Return all channels that the user is subscribing to (even unconfirmed)
|
||||
// @Description - "all_any" Return channels that the user owns or is subscribing (even unconfirmed)
|
||||
// @ID api-channels-list
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param selector query string true "Filter channels (default: owned)" Enums(owned, subscribed, all, subscribed_any, all_any)
|
||||
@@ -477,7 +485,7 @@ func (h APIHandler) DeleteClient(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/channels [GET]
|
||||
// @Router /api/users/{uid}/channels [GET]
|
||||
func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -546,6 +554,7 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary List all channels of a user
|
||||
// @ID api-channels-get
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param cid path int true "ChannelID"
|
||||
@@ -556,7 +565,7 @@ func (h APIHandler) ListChannels(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/channels/{cid} [GET]
|
||||
// @Router /api/users/{uid}/channels/{cid} [GET]
|
||||
func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -589,6 +598,7 @@ func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary (Partially) update a channel
|
||||
// @ID api-channels-update
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param cid path int true "ChannelID"
|
||||
@@ -602,7 +612,7 @@ func (h APIHandler) GetChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/channels/{cid} [PATCH]
|
||||
// @Router /api/users/{uid}/channels/{cid} [PATCH]
|
||||
func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -667,6 +677,7 @@ func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Description If there are no more entries the token "@end" will be returned
|
||||
// @Description By default we return long messages with a trimmed body, if trimmed=false is supplied we return full messages (this reduces the max page_size)
|
||||
// @ID api-channel-messages
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param query_data query handler.ListChannelMessages.query false " "
|
||||
//
|
||||
@@ -676,7 +687,7 @@ func (h APIHandler) UpdateChannel(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/channels/{cid}/messages [GET]
|
||||
// @Router /api/users/{uid}/channels/{cid}/messages [GET]
|
||||
func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
ChannelUserID models.UserID `uri:"uid"`
|
||||
@@ -757,6 +768,7 @@ func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary List all channels of a user
|
||||
// @ID api-user-subscriptions-list
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
//
|
||||
@@ -766,7 +778,7 @@ func (h APIHandler) ListChannelMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/subscriptions [GET]
|
||||
// @Router /api/users/{uid}/subscriptions [GET]
|
||||
func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -800,6 +812,7 @@ func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary List all subscriptions of a channel
|
||||
// @ID api-chan-subscriptions-list
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param cid path int true "ChannelID"
|
||||
@@ -810,7 +823,7 @@ func (h APIHandler) ListUserSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/channels/{cid}/subscriptions [GET]
|
||||
// @Router /api/users/{uid}/channels/{cid}/subscriptions [GET]
|
||||
func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -853,6 +866,7 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
||||
//
|
||||
// @Summary Get a single subscription
|
||||
// @ID api-subscriptions-get
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param sid path int true "SubscriptionID"
|
||||
@@ -863,7 +877,7 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/subscriptions/{sid} [GET]
|
||||
// @Router /api/users/{uid}/subscriptions/{sid} [GET]
|
||||
func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -900,6 +914,7 @@ func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Cancel (delete) subscription
|
||||
// @ID api-subscriptions-delete
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param sid path int true "SubscriptionID"
|
||||
@@ -910,7 +925,7 @@ func (h APIHandler) GetSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/subscriptions/{sid} [DELETE]
|
||||
// @Router /api/users/{uid}/subscriptions/{sid} [DELETE]
|
||||
func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -952,6 +967,7 @@ func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Creare/Request a subscription
|
||||
// @ID api-subscriptions-create
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param query_data query handler.CreateSubscription.query false " "
|
||||
@@ -963,7 +979,7 @@ func (h APIHandler) CancelSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/subscriptions [POST]
|
||||
// @Router /api/users/{uid}/subscriptions [POST]
|
||||
func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -1013,6 +1029,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Update a subscription (e.g. confirm)
|
||||
// @ID api-subscriptions-update
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param uid path int true "UserID"
|
||||
// @Param sid path int true "SubscriptionID"
|
||||
@@ -1023,7 +1040,7 @@ func (h APIHandler) CreateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/users/{uid}/subscriptions/{sid} [PATCH]
|
||||
// @Router /api/users/{uid}/subscriptions/{sid} [PATCH]
|
||||
func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
UserID models.UserID `uri:"uid"`
|
||||
@@ -1080,6 +1097,7 @@ func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Description If there are no more entries the token "@end" will be returned
|
||||
// @Description By default we return long messages with a trimmed body, if trimmed=false is supplied we return full messages (this reduces the max page_size)
|
||||
// @ID api-messages-list
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param query_data query handler.ListMessages.query false " "
|
||||
//
|
||||
@@ -1089,7 +1107,7 @@ func (h APIHandler) UpdateSubscription(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/messages [GET]
|
||||
// @Router /api/messages [GET]
|
||||
func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
type query struct {
|
||||
PageSize *int `form:"page_size"`
|
||||
@@ -1154,6 +1172,7 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Description Or the user must subscribe to the corresponding channel (and be confirmed) and request the resource with the READ or ADMIN Key
|
||||
// @Description The returned message is never trimmed
|
||||
// @ID api-messages-get
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param mid path int true "SCNMessageID"
|
||||
//
|
||||
@@ -1163,7 +1182,7 @@ func (h APIHandler) ListMessages(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/messages/{mid} [PATCH]
|
||||
// @Router /api/messages/{mid} [PATCH]
|
||||
func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
MessageID models.SCNMessageID `uri:"mid"`
|
||||
@@ -1223,6 +1242,7 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Summary Delete a single message
|
||||
// @Description The user must own the message and request the resource with the ADMIN Key
|
||||
// @ID api-messages-delete
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param mid path int true "SCNMessageID"
|
||||
//
|
||||
@@ -1232,7 +1252,7 @@ func (h APIHandler) GetMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/messages/{mid} [PATCH]
|
||||
// @Router /api/messages/{mid} [PATCH]
|
||||
func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
type uri struct {
|
||||
MessageID models.SCNMessageID `uri:"mid"`
|
||||
@@ -1280,6 +1300,7 @@ func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Description This is similar to the main route `POST -> https://scn.blackfrestbytes.com/`
|
||||
// @Description But this route can change in the future, for long-living scripts etc. it's better to use the normal POST route
|
||||
// @ID api-messages-create
|
||||
// @Tags API-v2
|
||||
//
|
||||
// @Param post_data query handler.CreateMessage.body false " "
|
||||
//
|
||||
@@ -1289,7 +1310,7 @@ func (h APIHandler) DeleteMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
// @Failure 404 {object} ginresp.apiError
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
//
|
||||
// @Router /api-v2/messages [POST]
|
||||
// @Router /api/messages [POST]
|
||||
func (h APIHandler) CreateMessage(g *gin.Context) ginresp.HTTPResponse {
|
||||
type body struct {
|
||||
Channel *string `json:"channel"`
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"blackforestbytes.com/simplecloudnotifier/common/ginresp"
|
||||
"blackforestbytes.com/simplecloudnotifier/logic"
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
sqlite3 "github.com/mattn/go-sqlite3"
|
||||
"net/http"
|
||||
@@ -33,13 +34,18 @@ type pingResponseInfo struct {
|
||||
|
||||
// Ping swaggerdoc
|
||||
//
|
||||
// @Summary Simple endpoint to test connection (any http method)
|
||||
// @ID api-common-ping
|
||||
// @Tags Common
|
||||
//
|
||||
// @Success 200 {object} pingResponse
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
// @Router /ping [get]
|
||||
// @Router /ping [post]
|
||||
// @Router /ping [put]
|
||||
// @Router /ping [delete]
|
||||
// @Router /ping [patch]
|
||||
//
|
||||
// @Router /api/ping [get]
|
||||
// @Router /api/ping [post]
|
||||
// @Router /api/ping [put]
|
||||
// @Router /api/ping [delete]
|
||||
// @Router /api/ping [patch]
|
||||
func (h CommonHandler) Ping(g *gin.Context) ginresp.HTTPResponse {
|
||||
buf := new(bytes.Buffer)
|
||||
_, _ = buf.ReadFrom(g.Request.Body)
|
||||
@@ -59,9 +65,14 @@ func (h CommonHandler) Ping(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
// DatabaseTest swaggerdoc
|
||||
//
|
||||
// @Summary Check for a wroking database connection
|
||||
// @ID api-common-dbtest
|
||||
// @Tags Common
|
||||
//
|
||||
// @Success 200 {object} handler.DatabaseTest.response
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
// @Router /db-test [get]
|
||||
//
|
||||
// @Router /api/db-test [get]
|
||||
func (h CommonHandler) DatabaseTest(g *gin.Context) ginresp.HTTPResponse {
|
||||
type response struct {
|
||||
Success bool `json:"success"`
|
||||
@@ -87,23 +98,42 @@ func (h CommonHandler) DatabaseTest(g *gin.Context) ginresp.HTTPResponse {
|
||||
|
||||
// Health swaggerdoc
|
||||
//
|
||||
// @Summary Server Health-checks
|
||||
// @ID api-common-health
|
||||
// @Tags Common
|
||||
//
|
||||
// @Success 200 {object} handler.Health.response
|
||||
// @Failure 500 {object} ginresp.apiError
|
||||
// @Router /health [get]
|
||||
//
|
||||
// @Router /api/health [get]
|
||||
func (h CommonHandler) Health(*gin.Context) ginresp.HTTPResponse {
|
||||
type response struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
_, libVersionNumber, _ := sqlite3.Version()
|
||||
|
||||
if libVersionNumber < 3039000 {
|
||||
ginresp.InternalError(errors.New("sqlite version too low"))
|
||||
}
|
||||
|
||||
err := h.app.Database.Ping()
|
||||
if err != nil {
|
||||
return ginresp.InternalError(err)
|
||||
}
|
||||
|
||||
return ginresp.JSON(http.StatusOK, response{Status: "ok"})
|
||||
}
|
||||
|
||||
func (h CommonHandler) NoRoute(g *gin.Context) ginresp.HTTPResponse {
|
||||
return ginresp.JSON(http.StatusNotFound, gin.H{
|
||||
"": "================ ROUTE NOT FOUND ================",
|
||||
"FullPath": g.FullPath(),
|
||||
"Method": g.Request.Method,
|
||||
"URL": g.Request.URL.String(),
|
||||
"RequestURI": g.Request.RequestURI,
|
||||
"Proto": g.Request.Proto,
|
||||
"Header": g.Request.Header,
|
||||
"~": "================ ROUTE NOT FOUND ================",
|
||||
})
|
||||
}
|
||||
|
@@ -28,6 +28,8 @@ func NewCompatHandler(app *logic.Application) CompatHandler {
|
||||
//
|
||||
// @Summary Register a new account
|
||||
// @ID compat-register
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param fcm_token query string true "the (android) fcm token"
|
||||
@@ -134,6 +136,8 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Get information about the current user
|
||||
// @ID compat-info
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param user_id query string true "the user_id"
|
||||
@@ -216,6 +220,8 @@ func (h CompatHandler) Info(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Acknowledge that a message was received
|
||||
// @ID compat-ack
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param user_id query string true "the user_id"
|
||||
@@ -287,6 +293,8 @@ func (h CompatHandler) Ack(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Return all not-acknowledged messages
|
||||
// @ID compat-requery
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param user_id query string true "the user_id"
|
||||
@@ -352,6 +360,8 @@ func (h CompatHandler) Requery(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Set the fcm-token (android)
|
||||
// @ID compat-update
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param user_id query string true "the user_id"
|
||||
@@ -463,6 +473,8 @@ func (h CompatHandler) Update(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Get a whole (potentially truncated) message
|
||||
// @ID compat-expand
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param user_id query string true "The user_id"
|
||||
@@ -548,6 +560,8 @@ func (h CompatHandler) Expand(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Upgrade a free account to a paid account
|
||||
// @ID compat-upgrade
|
||||
// @Tags API-v1
|
||||
//
|
||||
// @Deprecated
|
||||
//
|
||||
// @Param user_id query string true "the user_id"
|
||||
|
@@ -36,6 +36,7 @@ func NewMessageHandler(app *logic.Application) MessageHandler {
|
||||
//
|
||||
// @Summary Send a new message (compatibility)
|
||||
// @Description All parameter can be set via query-parameter or form-data body. Only UserID, UserKey and Title are required
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.SendMessageCompat.query false " "
|
||||
// @Param form_data formData handler.SendMessageCompat.form false " "
|
||||
@@ -85,6 +86,7 @@ func (h MessageHandler) SendMessageCompat(g *gin.Context) ginresp.HTTPResponse {
|
||||
//
|
||||
// @Summary Send a new message
|
||||
// @Description All parameter can be set via query-parameter or the json body. Only UserID, UserKey and Title are required
|
||||
// @Tags External
|
||||
//
|
||||
// @Param query_data query handler.SendMessage.query false " "
|
||||
// @Param post_body body handler.SendMessage.body false " "
|
||||
|
@@ -32,49 +32,65 @@ func NewRouter(app *logic.Application) *Router {
|
||||
}
|
||||
|
||||
// Init swaggerdocs
|
||||
//
|
||||
// @title SimpleCloudNotifier API
|
||||
// @version 2.0
|
||||
// @description API for SCN
|
||||
// @host scn.blackforestbytes.com
|
||||
//
|
||||
// @tag.name Common
|
||||
// @tag.name External
|
||||
// @tag.name API-v1
|
||||
// @tag.name API-v2
|
||||
//
|
||||
// @BasePath /
|
||||
func (r *Router) Init(e *gin.Engine) {
|
||||
|
||||
// ================ General ================
|
||||
|
||||
e.Any("/api/common/ping", ginresp.Wrap(r.commonHandler.Ping))
|
||||
e.POST("/api/common/db-test", ginresp.Wrap(r.commonHandler.DatabaseTest))
|
||||
e.GET("/api/common/health", ginresp.Wrap(r.commonHandler.Health))
|
||||
commonAPI := e.Group("/api")
|
||||
{
|
||||
commonAPI.Any("/ping", ginresp.Wrap(r.commonHandler.Ping))
|
||||
commonAPI.POST("/db-test", ginresp.Wrap(r.commonHandler.DatabaseTest))
|
||||
commonAPI.GET("/health", ginresp.Wrap(r.commonHandler.Health))
|
||||
}
|
||||
|
||||
// ================ Swagger ================
|
||||
|
||||
e.GET("/documentation/swagger", ginext.RedirectTemporary("/documentation/swagger/"))
|
||||
e.GET("/documentation/swagger/", ginresp.Wrap(swagger.Handle))
|
||||
e.GET("/documentation/swagger/:fn", ginresp.Wrap(swagger.Handle))
|
||||
docs := e.Group("/documentation")
|
||||
{
|
||||
docs.GET("/swagger", ginext.RedirectTemporary("/documentation/swagger/"))
|
||||
docs.GET("/swagger/", ginresp.Wrap(swagger.Handle))
|
||||
docs.GET("/swagger/:fn", ginresp.Wrap(swagger.Handle))
|
||||
}
|
||||
|
||||
// ================ Website ================
|
||||
|
||||
e.GET("/", ginresp.Wrap(r.websiteHandler.Index))
|
||||
e.GET("/index.php", ginresp.Wrap(r.websiteHandler.Index))
|
||||
e.GET("/index.html", ginresp.Wrap(r.websiteHandler.Index))
|
||||
e.GET("/index", ginresp.Wrap(r.websiteHandler.Index))
|
||||
frontend := e.Group("")
|
||||
{
|
||||
frontend.GET("/", ginresp.Wrap(r.websiteHandler.Index))
|
||||
frontend.GET("/index.php", ginresp.Wrap(r.websiteHandler.Index))
|
||||
frontend.GET("/index.html", ginresp.Wrap(r.websiteHandler.Index))
|
||||
frontend.GET("/index", ginresp.Wrap(r.websiteHandler.Index))
|
||||
|
||||
e.GET("/api", ginresp.Wrap(r.websiteHandler.APIDocs))
|
||||
e.GET("/api.php", ginresp.Wrap(r.websiteHandler.APIDocs))
|
||||
e.GET("/api.html", ginresp.Wrap(r.websiteHandler.APIDocs))
|
||||
frontend.GET("/api", ginresp.Wrap(r.websiteHandler.APIDocs))
|
||||
frontend.GET("/api.php", ginresp.Wrap(r.websiteHandler.APIDocs))
|
||||
frontend.GET("/api.html", ginresp.Wrap(r.websiteHandler.APIDocs))
|
||||
|
||||
e.GET("/api_more", ginresp.Wrap(r.websiteHandler.APIDocsMore))
|
||||
e.GET("/api_more.php", ginresp.Wrap(r.websiteHandler.APIDocsMore))
|
||||
e.GET("/api_more.html", ginresp.Wrap(r.websiteHandler.APIDocsMore))
|
||||
frontend.GET("/api_more", ginresp.Wrap(r.websiteHandler.APIDocsMore))
|
||||
frontend.GET("/api_more.php", ginresp.Wrap(r.websiteHandler.APIDocsMore))
|
||||
frontend.GET("/api_more.html", ginresp.Wrap(r.websiteHandler.APIDocsMore))
|
||||
|
||||
e.GET("/message_sent", ginresp.Wrap(r.websiteHandler.MessageSent))
|
||||
e.GET("/message_sent.php", ginresp.Wrap(r.websiteHandler.MessageSent))
|
||||
e.GET("/message_sent.html", ginresp.Wrap(r.websiteHandler.MessageSent))
|
||||
frontend.GET("/message_sent", ginresp.Wrap(r.websiteHandler.MessageSent))
|
||||
frontend.GET("/message_sent.php", ginresp.Wrap(r.websiteHandler.MessageSent))
|
||||
frontend.GET("/message_sent.html", ginresp.Wrap(r.websiteHandler.MessageSent))
|
||||
|
||||
e.GET("/favicon.ico", ginresp.Wrap(r.websiteHandler.FaviconIco))
|
||||
e.GET("/favicon.png", ginresp.Wrap(r.websiteHandler.FaviconPNG))
|
||||
frontend.GET("/favicon.ico", ginresp.Wrap(r.websiteHandler.FaviconIco))
|
||||
frontend.GET("/favicon.png", ginresp.Wrap(r.websiteHandler.FaviconPNG))
|
||||
|
||||
e.GET("/js/:fn", ginresp.Wrap(r.websiteHandler.Javascript))
|
||||
e.GET("/css/:fn", ginresp.Wrap(r.websiteHandler.CSS))
|
||||
frontend.GET("/js/:fn", ginresp.Wrap(r.websiteHandler.Javascript))
|
||||
frontend.GET("/css/:fn", ginresp.Wrap(r.websiteHandler.CSS))
|
||||
}
|
||||
|
||||
// ================ Compat (v1) ================
|
||||
|
||||
@@ -91,7 +107,7 @@ func (r *Router) Init(e *gin.Engine) {
|
||||
|
||||
// ================ Manage API ================
|
||||
|
||||
apiv2 := e.Group("/api-v2/")
|
||||
apiv2 := e.Group("/api/")
|
||||
{
|
||||
|
||||
apiv2.POST("/users", ginresp.Wrap(r.apiHandler.CreateUser))
|
||||
|
Reference in New Issue
Block a user