add new lights, add login and role to it, add services page

This commit is contained in:
Adrian Zuercher
2025-08-09 18:00:36 +02:00
parent 7d2ab814da
commit 1697a4dcfd
56 changed files with 1337 additions and 290 deletions

View File

@@ -1,6 +1,7 @@
package dbRequest
import (
"backend/models"
"fmt"
"net/http"
@@ -10,25 +11,22 @@ import (
var DBCreate string = `CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
role TEXT NOT NULL,
password TEXT NOT NULL
);`
var DBNewUser string = `INSERT INTO users (username, password) VALUES (?, ?)`
var DBQueryPassword string = `SELECT password FROM users WHERE username = ?`
var DBNewUser string = `INSERT INTO users (username, role, password) VALUES (?, ?, ?)`
var DBQueryPassword string = `SELECT role, password FROM users WHERE username = ?`
var DBUserLookup string = `SELECT EXISTS(SELECT 1 FROM users WHERE username = ?)`
var DBRemoveUser string = `DELETE FROM users WHERE username = $1`
func CheckDBError(c *gin.Context, username string, err error) bool {
if err != nil {
if err.Error() == "sql: no rows in result set" {
c.JSON(http.StatusBadRequest, gin.H{
"error": fmt.Sprintf("no user '%s' found", username),
})
c.JSON(http.StatusBadRequest, models.NewJsonErrorMessageResponse(fmt.Sprintf("no user '%s' found", username)))
return true
}
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
})
c.JSON(http.StatusBadRequest, models.NewJsonErrorResponse(err))
return true
}
return false