ADD: added initial page with login

This commit is contained in:
hwinkel
2025-05-20 22:58:31 +02:00
parent 214ab55ad2
commit a330291456
25 changed files with 1064 additions and 35 deletions

View File

@@ -0,0 +1,49 @@
package common
import (
"net/http"
"github.com/gin-gonic/gin"
)
// APIResponse strukturiert alle erfolgreichen Antworten
type APIResponse struct {
Data interface{} `json:"data,omitempty"`
Message string `json:"message,omitempty"`
}
// APIError strukturiert Fehlerantworten
type APIError struct {
Error string `json:"error"`
Details string `json:"details,omitempty"`
}
// RespondSuccess sendet 200 OK mit Daten
func RespondSuccess(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, APIResponse{
Data: data,
})
}
// RespondMessage sendet 200 OK mit einer Nachricht
func RespondMessage(c *gin.Context, message string) {
c.JSON(http.StatusOK, APIResponse{
Message: message,
})
}
// RespondCreated sendet 201 Created mit Daten
func RespondCreated(c *gin.Context, data interface{}) {
c.JSON(http.StatusCreated, APIResponse{
Data: data,
})
}
// RespondError sendet einen Fehler mit Statuscode und Nachricht
func RespondError(c *gin.Context, code int, message string, details ...string) {
errResp := APIError{Error: message}
if len(details) > 0 {
errResp.Details = details[0]
}
c.AbortWithStatusJSON(code, errResp)
}