umstellung auf Service und Repository Verwendung - WIP
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"kontor-api-gin/pkg/globals"
|
||||
"kontor-api-gin/pkg/helpers"
|
||||
"kontor-api-gin/pkg/schema"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/sessions"
|
||||
@@ -11,6 +12,34 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type LoginInput struct {
|
||||
Email string `json:"email" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
|
||||
func LoginHandler(c *gin.Context) {
|
||||
var input LoginInput
|
||||
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
profile := schema.Profile{}
|
||||
|
||||
profile.Email = input.Email
|
||||
profile.Password = input.Password
|
||||
|
||||
token, err := schema.LoginCheck(profile.Email, profile.Password)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "username or password is incorrect."})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"token": token})
|
||||
}
|
||||
|
||||
func LoginGetHandler(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
user := session.Get(globals.UserKey)
|
||||
|
||||
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"kontor-api-gin/pkg/globals"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -11,5 +12,6 @@ func HealthGetHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "healthy",
|
||||
"version": globals.Version,
|
||||
"time": time.Now().UTC().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@ func ListMediaFiles(c *gin.Context) {
|
||||
// result := query.Find(&files)
|
||||
result := schema.DB.Find(&files)
|
||||
logger.Info("ListMediaFiles", "count", result.RowsAffected)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "All MediaFiles",
|
||||
"files": files,
|
||||
})
|
||||
c.JSON(http.StatusOK, files)
|
||||
}
|
||||
|
||||
func ListMediaLoFis(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user