diff --git a/backend/internal/database/db.go b/backend/internal/database/db.go index ce329af..820c1f2 100644 --- a/backend/internal/database/db.go +++ b/backend/internal/database/db.go @@ -14,7 +14,6 @@ import ( type Database interface { // Insert a new user into the database, password should be hashed before calling AddUser(username string, password string) error - RemoveUser(username string) error PromoteToAdmin(username string) error GetUserId(username string) (int, error) @@ -22,10 +21,7 @@ type Database interface { Migrate(dirname string) error AddTimeReport(projectName string, userName string, start time.Time, end time.Time) error AddUserToProject(username string, projectname string, role string) error - // 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 + ChangeUserRole(username string, projectname string, role string) error } // This struct is a wrapper type that holds the database connection @@ -46,7 +42,7 @@ const addTimeReport = `WITH UserLookup AS (SELECT id FROM users WHERE username = INSERT INTO time_reports (project_id, user_id, start, end) VALUES ((SELECT id FROM ProjectLookup), (SELECT id FROM UserLookup), ?, ?);` const addUserToProject = "INSERT INTO user_roles (user_id, project_id, p_role) VALUES (?, ?, ?)" // WIP -const changeUserRole = "UPDATE project_member SET role = ? WHERE user_id = ? AND project_id = ?" +const changeUserRole = "UPDATE user_roles SET p_role = ? WHERE user_id = ? AND project_id = ?" // DbConnect connects to the database func DbConnect(dbpath string) Database { diff --git a/backend/internal/database/db_test.go b/backend/internal/database/db_test.go index 7d431b9..0be4f34 100644 --- a/backend/internal/database/db_test.go +++ b/backend/internal/database/db_test.go @@ -152,6 +152,29 @@ func TestAddUserToProject(t *testing.T) { // } -// func TestChangeUserRole(t *testing.T) { +func TestChangeUserRole(t *testing.T) { + db, err := setupState() + if err != nil { + t.Error("setupState failed:", err) + } -// } + err = db.AddUser("testuser", "password") + if err != nil { + t.Error("AddUser failed:", err) + } + + err = db.AddProject("testproject", "description", "testuser") + if err != nil { + t.Error("AddProject failed:", err) + } + + err = db.AddUserToProject("testuser", "testproject", "user") + if err != nil { + t.Error("AddUserToProject failed:", err) + } + + err = db.ChangeUserRole("testuser", "testproject", "admin") + if err != nil { + t.Error("ChangeUserRole failed:", err) + } +}