Added template for various new functions in db.go and corresponding tests in db_test.go

This commit is contained in:
dDogge 2024-03-07 14:25:28 +01:00
parent 9b9f6dd962
commit bd434c3da7
2 changed files with 31 additions and 0 deletions

View file

@ -18,6 +18,9 @@ type Database interface {
GetUserId(username string) (int, error)
AddProject(name string, description string, username string) error
Migrate(dirname 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
}
// This struct is a wrapper type that holds the database connection
@ -33,6 +36,10 @@ const userInsert = "INSERT INTO users (username, password) VALUES (?, ?)"
const projectInsert = "INSERT INTO projects (name, description, user_id) SELECT ?, ?, id FROM users WHERE username = ?"
const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?"
// const addTimeReport = ""
// const addUserToProject = ""
// const changeUserRole = ""
// DbConnect connects to the database
func DbConnect(dbpath string) Database {
// Open the database
@ -50,6 +57,18 @@ func DbConnect(dbpath string) Database {
return &Db{db}
}
// func (d *Db) AddTimeReport(projectname string, start time.Time, end time.Time) error {
// }
// func (d *Db) AddUserToProject(username string, projectname string) error {
// }
// func (d *Db) ChangeUserRole(username string, projectname string, role string) error {
// }
// AddUser adds a user to the database
func (d *Db) AddUser(username string, password string) error {
_, err := d.Exec(userInsert, username, password)

View file

@ -91,3 +91,15 @@ func TestPromoteToAdmin(t *testing.T) {
t.Error("PromoteToAdmin failed:", err)
}
}
// func TestAddTimeReport(t *testing.T) {
// }
// func TestAddUserToProject(t *testing.T) {
// }
// func TestChangeUserRole(t *testing.T) {
// }