tags/grouping for API

This commit is contained in:
2022-11-23 19:32:23 +01:00
parent 03c35d6446
commit 1bc847cdc9
16 changed files with 1789 additions and 1442 deletions

View File

@@ -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 ================",
})
}