Completed db rewrite

This commit is contained in:
Manuel Forcén Muñoz 2025-04-16 23:24:23 +02:00
parent 54d7d14ef9
commit cf4b8e0119
19 changed files with 481 additions and 276 deletions

View file

@ -1,24 +1,22 @@
package apis
import (
"github.com/gin-gonic/gin"
"gorm.io/gorm"
"database/sql"
"net/http"
"planner/core"
"github.com/gin-gonic/gin"
)
func extractUser(orm *gorm.DB, c *gin.Context) *core.User {
func extractUser(orm *sql.DB, c *gin.Context) *core.User {
username, _, ok := c.Request.BasicAuth()
if !ok {
c.Status(http.StatusUnauthorized)
return nil
}
u := core.User{
Username: username,
}
result := orm.Take(&u)
if result.Error != nil {
u, err := core.UserGet(db, username)
if err != nil {
c.String(http.StatusNotFound, "Unable to find user "+username)
return nil
}