DeleteProject added in db.go, untested
This commit is contained in:
parent
a468b896db
commit
cd74758b2f
1 changed files with 19 additions and 0 deletions
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"ttime/internal/types"
|
"ttime/internal/types"
|
||||||
|
|
||||||
|
@ -19,6 +20,7 @@ type Database interface {
|
||||||
PromoteToAdmin(username string) error
|
PromoteToAdmin(username string) error
|
||||||
GetUserId(username string) (int, error)
|
GetUserId(username string) (int, error)
|
||||||
AddProject(name string, description string, username string) error
|
AddProject(name string, description string, username string) error
|
||||||
|
// DeleteProject(name string, username string) error
|
||||||
Migrate() error
|
Migrate() error
|
||||||
MigrateSampleData() error
|
MigrateSampleData() error
|
||||||
GetProjectId(projectname string) (int, error)
|
GetProjectId(projectname string) (int, error)
|
||||||
|
@ -70,6 +72,8 @@ const getProjectsForUser = `SELECT p.id, p.name, p.description FROM projects p
|
||||||
JOIN user_roles ur ON p.id = ur.project_id
|
JOIN user_roles ur ON p.id = ur.project_id
|
||||||
JOIN users u ON ur.user_id = u.id
|
JOIN users u ON ur.user_id = u.id
|
||||||
WHERE u.username = ?`
|
WHERE u.username = ?`
|
||||||
|
const deleteProject = `DELETE FROM projects
|
||||||
|
WHERE id = ? AND owner_username = ?`
|
||||||
|
|
||||||
// DbConnect connects to the database
|
// DbConnect connects to the database
|
||||||
func DbConnect(dbpath string) Database {
|
func DbConnect(dbpath string) Database {
|
||||||
|
@ -225,6 +229,21 @@ func (d *Db) AddProject(name string, description string, username string) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Db) DeleteProject(projectID string, username string) error {
|
||||||
|
tx := d.MustBegin()
|
||||||
|
|
||||||
|
_, err := tx.Exec(deleteProject, projectID, username)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if rollbackErr := tx.Rollback(); rollbackErr != nil {
|
||||||
|
return fmt.Errorf("error rolling back transaction: %v, delete error: %v", rollbackErr, err)
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Db) GetAllUsersProject(projectname string) ([]UserProjectMember, error) {
|
func (d *Db) GetAllUsersProject(projectname string) ([]UserProjectMember, error) {
|
||||||
// Define the SQL query to fetch users and their roles for a given project
|
// Define the SQL query to fetch users and their roles for a given project
|
||||||
query := `
|
query := `
|
||||||
|
|
Loading…
Reference in a new issue