Added ChangeUserName in db
This commit is contained in:
parent
bb93cef1d3
commit
1919b7cb99
3 changed files with 51 additions and 0 deletions
|
@ -27,6 +27,7 @@ type Database interface {
|
|||
AddWeeklyReport(projectName string, userName string, week int, developmentTime int, meetingTime int, adminTime int, ownWorkTime int, studyTime int, testingTime int) error
|
||||
AddUserToProject(username string, projectname string, role string) error
|
||||
ChangeUserRole(username string, projectname string, role string) error
|
||||
ChangeUserName(username string, newname string) error
|
||||
GetAllUsersProject(projectname string) ([]UserProjectMember, error)
|
||||
GetAllUsersApplication() ([]string, error)
|
||||
GetProjectsForUser(username string) ([]types.Project, error)
|
||||
|
@ -67,6 +68,7 @@ const addWeeklyReport = `WITH UserLookup AS (SELECT id FROM users WHERE username
|
|||
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 user_roles SET p_role = ? WHERE user_id = ? AND project_id = ?"
|
||||
const changeUserName = "UPDATE user SET username = ? WHERE user_id = ?" // WIP
|
||||
|
||||
const getProjectsForUser = `SELECT p.id, p.name, p.description FROM projects p
|
||||
JOIN user_roles ur ON p.id = ur.project_id
|
||||
|
@ -169,6 +171,20 @@ func (d *Db) ChangeUserRole(username string, projectname string, role string) er
|
|||
return err3
|
||||
}
|
||||
|
||||
// ChangeUserRole changes the role of a user within a project.
|
||||
func (d *Db) ChangeUserName(username string, newname string) error {
|
||||
// Get the user ID
|
||||
var userid int
|
||||
userid, err := d.GetUserId(username)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Execute the SQL query to change the user's role
|
||||
_, err2 := d.Exec(changeUserName, username, userid)
|
||||
return err2
|
||||
}
|
||||
|
||||
// GetUserRole retrieves the role of a user within a project.
|
||||
func (d *Db) GetUserRole(username string, projectname string) (string, error) {
|
||||
var role string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue