diff --git a/.gitignore b/.gitignore index 8f9be7b..2d89407 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ *.dylib bin -database.txt db.sqlite3 *.png diff --git a/backend/Makefile b/backend/Makefile index 2547900..d005846 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -54,9 +54,6 @@ migrate: db.sqlite3: make migrate -dbdump: - sqlite3 $(DB_FILE) .dump > database.txt - backup: mkdir -p backups sqlite3 $(DB_FILE) .dump | gzip -9 > ./backups/BACKUP_$(DB_FILE)_$(shell date +"%Y-%m-%d_%H:%M:%S").sql.gz diff --git a/backend/internal/database/db.go b/backend/internal/database/db.go index 9e63395..5a88873 100644 --- a/backend/internal/database/db.go +++ b/backend/internal/database/db.go @@ -1,9 +1,7 @@ package database import ( - "database/sql" "embed" - "fmt" "os" "path/filepath" "time" @@ -27,8 +25,7 @@ type Database interface { // ChangeUserRole(username string, projectname string, role string) error // AddTimeReport(projectname string, start time.Time, end time.Time) error // AddUserToProject(username string, projectname string) error - ChangeUserRole(username string, projectname string, role string) error - GetProjectId(projectname string) (int, error) + // ChangeUserRole(username string, projectname string, role string) error } // This struct is a wrapper type that holds the database connection @@ -45,6 +42,7 @@ const projectInsert = "INSERT INTO projects (name, description, owner_user_id) S 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 +// const changeUserRole = "" // DbConnect connects to the database func DbConnect(dbpath string) Database { @@ -63,22 +61,6 @@ func DbConnect(dbpath string) Database { return &Db{db} } -func (d *Db) ChangeUserRole(username string, projectname string, role string) error { - userID, err := d.GetUserId(username) - if err != nil { - return err - } - - projectID, err := d.GetProjectId(projectname) - if err != nil { - return err - } - - // Update user role in the project using the correct table name - _, err = d.Exec("INSERT OR REPLACE INTO user_roles (user_id, project_id, p_role) VALUES (?, ?, ?)", userID, projectID, role) - return err -} - func (d *Db) AddTimeReport(projectname string, start time.Time, end time.Time, breakTime uint32) error { // WIP _, err := d.Exec(addTimeReport, projectname, 0, start, end, breakTime, false) return err @@ -128,16 +110,10 @@ func (d *Db) GetUserId(username string) (int, error) { return id, err } -func (d *Db) GetProjectId(projectname string) (int, error) { +func (d *Db) GetProjectId(projectname string) (int, error) { // WIP, denna kan vara goof var id int - err := d.Get(&id, "SELECT id FROM projects WHERE name = ?", projectname) - if err != nil { - if err == sql.ErrNoRows { - return 0, fmt.Errorf("project '%s' not found", projectname) - } - return 0, err - } - return id, nil + err := d.Get(&id, "SELECT id FROM project WHERE project_name = ?", projectname) + return id, err } // Creates a new project in the database, associated with a user diff --git a/backend/internal/database/db_test.go b/backend/internal/database/db_test.go index 08eee32..96eb9b7 100644 --- a/backend/internal/database/db_test.go +++ b/backend/internal/database/db_test.go @@ -92,32 +92,6 @@ func TestPromoteToAdmin(t *testing.T) { } } -func TestDbChangeUserRole(t *testing.T) { - // Set up the initial state - db, err := setupState() - if err != nil { - t.Error("setupState failed:", err) - } - - // Add a user - err = db.AddUser("test", "password") - if err != nil { - t.Error("AddUser failed:", err) - } - - // Add a project - err = db.AddProject("test_project", "project description", "test") - if err != nil { - t.Error("AddProject failed:", err) - } - - // Change user role - err = db.ChangeUserRole("test", "test_project", "project_manager") - if err != nil { - t.Error("ChangeUserRole failed:", err) - } -} - // func TestAddTimeReport(t *testing.T) { // } diff --git a/backend/internal/database/migrations/0049_project_role.sql b/backend/internal/database/migrations/0049_project_role.sql index f7e7151..8716800 100644 --- a/backend/internal/database/migrations/0049_project_role.sql +++ b/backend/internal/database/migrations/0049_project_role.sql @@ -5,5 +5,5 @@ CREATE TABLE IF NOT EXISTS project_role ( ); -- Insert the possible roles a user can have in a project. -INSERT OR IGNORE INTO project_role (p_role) VALUES ('project_manager'); +INSERT OR IGNORE INTO project_role (p_role) VALUES ('admin'); INSERT OR IGNORE INTO project_role (p_role) VALUES ('member'); diff --git a/backend/internal/database/migrations/0050_user_roles.sql b/backend/internal/database/migrations/0050_user_roles.sql index d3e614d..aad25f7 100644 --- a/backend/internal/database/migrations/0050_user_roles.sql +++ b/backend/internal/database/migrations/0050_user_roles.sql @@ -1,7 +1,7 @@ CREATE TABLE IF NOT EXISTS user_roles ( user_id INTEGER NOT NULL, project_id INTEGER NOT NULL, - p_role TEXT NOT NULL, -- 'project_manager' 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) diff --git a/backend/main.go b/backend/main.go index bba3fa6..1aaca45 100644 --- a/backend/main.go +++ b/backend/main.go @@ -71,7 +71,6 @@ func main() { server.Post("/api/loginrenew", gs.LoginRenew) server.Delete("/api/userdelete", gs.UserDelete) // Perhaps just use POST to avoid headaches - server.Post("/api/project", gs.CreateProject) // Announce the port we are listening on and start the server err = server.Listen(fmt.Sprintf(":%d", conf.Port)) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 24854c0..2dbd51e 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -1,4 +1,3 @@ -import { NewProject, Project } from "../Types/Project"; import { NewUser, User } from "../Types/Users"; // Defines all the methods that an instance of the API must implement @@ -7,8 +6,6 @@ interface API { registerUser(user: NewUser): Promise; /** Remove a user */ removeUser(username: string): Promise; - /** Create a project */ - createProject(project: NewProject): Promise; } // Export an instance of the API @@ -32,14 +29,4 @@ export const api: API = { body: JSON.stringify(username), }).then((res) => res.json() as Promise); }, - - async createProject(project: NewProject): Promise { - return fetch("/api/project", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(project), - }).then((res) => res.json() as Promise); - }, }; diff --git a/frontend/src/Types/Project.ts b/frontend/src/Types/Project.ts deleted file mode 100644 index bb4f8c7..0000000 --- a/frontend/src/Types/Project.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface Project { - id: number; - name: string; - description: string; - owner: string; - created: string; // This is a date -} - -export interface NewProject { - name: string; - description: string; - owner: string; -}