Added comments to various functions
This commit is contained in:
parent
976ce5900c
commit
04e17a1721
1 changed files with 10 additions and 0 deletions
|
@ -89,29 +89,34 @@ func DbConnect(dbpath string) Database {
|
|||
return &Db{db}
|
||||
}
|
||||
|
||||
// GetProjectsForUser retrieves all projects associated with a specific user.
|
||||
func (d *Db) GetProjectsForUser(username string) ([]types.Project, error) {
|
||||
var projects []types.Project
|
||||
err := d.Select(&projects, getProjectsForUser, username)
|
||||
return projects, err
|
||||
}
|
||||
|
||||
// GetAllProjects retrieves all projects from the database.
|
||||
func (d *Db) GetAllProjects() ([]types.Project, error) {
|
||||
var projects []types.Project
|
||||
err := d.Select(&projects, "SELECT * FROM projects")
|
||||
return projects, err
|
||||
}
|
||||
|
||||
// GetProject retrieves a specific project by its ID.
|
||||
func (d *Db) GetProject(projectId int) (types.Project, error) {
|
||||
var project types.Project
|
||||
err := d.Select(&project, "SELECT * FROM projects WHERE id = ?")
|
||||
return project, err
|
||||
}
|
||||
|
||||
// AddTimeReport adds a time report for a specific project and user.
|
||||
func (d *Db) AddTimeReport(projectName string, userName string, start time.Time, end time.Time) error { // WIP
|
||||
_, err := d.Exec(addTimeReport, userName, projectName, start, end)
|
||||
return err
|
||||
}
|
||||
|
||||
// AddUserToProject adds a user to a project with a specified role.
|
||||
func (d *Db) AddUserToProject(username string, projectname string, role string) error { // WIP
|
||||
var userid int
|
||||
userid, err := d.GetUserId(username)
|
||||
|
@ -129,23 +134,28 @@ func (d *Db) AddUserToProject(username string, projectname string, role string)
|
|||
return err3
|
||||
}
|
||||
|
||||
// ChangeUserRole changes the role of a user within a project.
|
||||
func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
|
||||
// Get the user ID
|
||||
var userid int
|
||||
userid, err := d.GetUserId(username)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Get the project ID
|
||||
var projectid int
|
||||
projectid, err2 := d.GetProjectId(projectname)
|
||||
if err2 != nil {
|
||||
panic(err2)
|
||||
}
|
||||
|
||||
// Execute the SQL query to change the user's role
|
||||
_, err3 := d.Exec(changeUserRole, role, userid, projectid)
|
||||
return err3
|
||||
}
|
||||
|
||||
// GetUserRole retrieves the role of a user within a project.
|
||||
func (d *Db) GetUserRole(username string, projectname string) (string, error) {
|
||||
var role string
|
||||
err := d.Get(&role, "SELECT p_role FROM user_roles WHERE user_id = (SELECT id FROM users WHERE username = ?) AND project_id = (SELECT id FROM projects WHERE name = ?)", username, projectname)
|
||||
|
|
Loading…
Reference in a new issue