Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
This commit is contained in:
commit
f8277617a9
12 changed files with 261 additions and 21 deletions
|
@ -2,7 +2,6 @@ package database
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
@ -37,7 +36,7 @@ type Db struct {
|
|||
var scripts embed.FS
|
||||
|
||||
const userInsert = "INSERT INTO users (username, password) VALUES (?, ?)"
|
||||
const projectInsert = "INSERT INTO projects (name, description, user_id) SELECT ?, ?, id FROM users WHERE username = ?"
|
||||
const projectInsert = "INSERT INTO projects (name, description, owner_user_id) SELECT ?, ?, id FROM users WHERE username = ?"
|
||||
const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?"
|
||||
const addTimeReport = "INSERT INTO activity (report_id, activity_nbr, start_time, end_time, break, comment) VALUES (?, ?, ?, ?, ?, ?)" // WIP
|
||||
const addUserToProject = "INSERT INTO project_member (project_id, user_id, role) VALUES (?, ?, ?)" // WIP
|
||||
|
@ -154,7 +153,6 @@ func (d *Db) Migrate(dirname string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Println("Executed SQL file:", file.Name())
|
||||
}
|
||||
|
||||
if tr.Commit() != nil {
|
||||
|
|
|
@ -3,9 +3,9 @@ CREATE TABLE IF NOT EXISTS projects (
|
|||
projectId TEXT DEFAULT (HEX(RANDOMBLOB(4))) NOT NULL UNIQUE,
|
||||
name VARCHAR(255) NOT NULL UNIQUE,
|
||||
description TEXT NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||
owner_user_id INTEGER NOT NULL,
|
||||
FOREIGN KEY (owner_user_id) REFERENCES users (id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS projects_projectId_index ON projects (projectId);
|
||||
CREATE INDEX IF NOT EXISTS projects_user_id_index ON projects (user_id);
|
||||
CREATE INDEX IF NOT EXISTS projects_user_id_index ON projects (owner_user_id);
|
|
@ -0,0 +1,9 @@
|
|||
-- This table represents the possible role a user can have in a project.
|
||||
-- It has nothing to do with the site admin table.
|
||||
CREATE TABLE IF NOT EXISTS project_role (
|
||||
p_role TEXT PRIMARY KEY
|
||||
);
|
||||
|
||||
-- Insert the possible roles a user can have in a project.
|
||||
INSERT OR IGNORE INTO project_role (p_role) VALUES ('admin');
|
||||
INSERT OR IGNORE INTO project_role (p_role) VALUES ('member');
|
|
@ -1,16 +1,9 @@
|
|||
CREATE TABLE IF NOT EXISTS user_roles (
|
||||
user_id INTEGER NOT NULL,
|
||||
project_id INTEGER NOT NULL,
|
||||
role STRING NOT NULL, -- 'admin' or 'member'
|
||||
p_role TEXT NOT NULL, -- 'admin' or 'member'
|
||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||
FOREIGN KEY (project_id) REFERENCES projects (id)
|
||||
FOREIGN KEY (p_role) REFERENCES project_role (p_role)
|
||||
PRIMARY KEY (user_id, project_id)
|
||||
);
|
||||
|
||||
-- Make sure that the role is either 'admin' or 'member'
|
||||
CREATE TRIGGER IF NOT EXISTS user_role_admin_or_member
|
||||
BEFORE INSERT ON user_roles
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
SELECT RAISE(ABORT, 'Invalid role') WHERE NEW.role NOT IN ('admin', 'member');
|
||||
END;
|
||||
);
|
|
@ -46,6 +46,17 @@ type GState struct {
|
|||
ButtonCount int
|
||||
}
|
||||
|
||||
// Register is a simple handler that registers a new user
|
||||
//
|
||||
// @Summary Register a new user
|
||||
// @Description Register a new user
|
||||
// @Tags User
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {string} string "User added"
|
||||
// @Failure 400 {string} string "Bad request"
|
||||
// @Failure 500 {string} string "Internal server error"
|
||||
// @Router /api/register [post]
|
||||
func (gs *GState) Register(c *fiber.Ctx) error {
|
||||
u := new(types.User)
|
||||
if err := c.BodyParser(u); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue