Activity type database changes with interface changes in go
This commit is contained in:
parent
fe91f798ba
commit
47d7d9fe3c
4 changed files with 19 additions and 7 deletions
|
@ -21,7 +21,7 @@ type Database interface {
|
|||
AddProject(name string, description string, username string) error
|
||||
Migrate(dirname string) error
|
||||
GetProjectId(projectname string) (int, error)
|
||||
AddTimeReport(projectName string, userName string, start time.Time, end time.Time) error
|
||||
AddTimeReport(projectName string, userName string, activityType string, start time.Time, end time.Time) error
|
||||
AddUserToProject(username string, projectname string, role string) error
|
||||
ChangeUserRole(username string, projectname string, role string) error
|
||||
GetAllUsersProject(projectname string) ([]UserProjectMember, error)
|
||||
|
@ -51,8 +51,8 @@ const projectInsert = "INSERT INTO projects (name, description, owner_user_id) S
|
|||
const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?"
|
||||
const addTimeReport = `WITH UserLookup AS (SELECT id FROM users WHERE username = ?),
|
||||
ProjectLookup AS (SELECT id FROM projects WHERE name = ?)
|
||||
INSERT INTO time_reports (project_id, user_id, start, end)
|
||||
VALUES ((SELECT id FROM ProjectLookup), (SELECT id FROM UserLookup), ?, ?);`
|
||||
INSERT INTO time_reports (project_id, user_id, activity_type, 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 user_roles SET p_role = ? WHERE user_id = ? AND project_id = ?"
|
||||
|
||||
|
@ -100,8 +100,8 @@ func (d *Db) GetAllProjects() ([]types.Project, error) {
|
|||
return projects, err
|
||||
}
|
||||
|
||||
func (d *Db) AddTimeReport(projectName string, userName string, start time.Time, end time.Time) error { // WIP
|
||||
_, err := d.Exec(addTimeReport, userName, projectName, start, end)
|
||||
func (d *Db) AddTimeReport(projectName string, userName string, activityType string, start time.Time, end time.Time) error { // WIP
|
||||
_, err := d.Exec(addTimeReport, userName, projectName, activityType, start, end)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ func TestAddTimeReport(t *testing.T) {
|
|||
var now = time.Now()
|
||||
var then = now.Add(time.Hour)
|
||||
|
||||
err = db.AddTimeReport("testproject", "testuser", now, then)
|
||||
err = db.AddTimeReport("testproject", "testuser", "activity", now, then)
|
||||
if err != nil {
|
||||
t.Error("AddTimeReport failed:", err)
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ func TestAddUserToProject(t *testing.T) {
|
|||
var now = time.Now()
|
||||
var then = now.Add(time.Hour)
|
||||
|
||||
err = db.AddTimeReport("testproject", "testuser", now, then)
|
||||
err = db.AddTimeReport("testproject", "testuser", "activity", now, then)
|
||||
if err != nil {
|
||||
t.Error("AddTimeReport failed:", err)
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ CREATE TABLE IF NOT EXISTS time_reports (
|
|||
id INTEGER PRIMARY KEY,
|
||||
project_id INTEGER NOT NULL,
|
||||
user_id INTEGER NOT NULL,
|
||||
activity_type TEXT NOT NULL,
|
||||
start DATETIME NOT NULL,
|
||||
end DATETIME NOT NULL,
|
||||
FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE
|
||||
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
FOREIGN KEY (activity_type) REFERENCES activity_types (name) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS time_reports_start_before_end
|
||||
|
|
10
backend/internal/database/migrations/0080_activity_types.sql
Normal file
10
backend/internal/database/migrations/0080_activity_types.sql
Normal file
|
@ -0,0 +1,10 @@
|
|||
CREATE TABLE IF NOT EXISTS activity_types (
|
||||
name TEXT PRIMARY KEY
|
||||
);
|
||||
|
||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Development');
|
||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Meeting');
|
||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Administration');
|
||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Own Work');
|
||||
INSERT OR IGNORE INTO activity_types (name) VALUES ('Studies');
|
||||
INSErt OR IGNORE INTO activity_types (name) VALUES ('Testing');
|
Loading…
Reference in a new issue