diff --git a/backend/internal/database/db.go b/backend/internal/database/db.go index 2b3cced..6bb113b 100644 --- a/backend/internal/database/db.go +++ b/backend/internal/database/db.go @@ -4,7 +4,6 @@ import ( "embed" "os" "path/filepath" - "time" "github.com/jmoiron/sqlx" _ "github.com/mattn/go-sqlite3" @@ -21,9 +20,6 @@ type Database interface { // AddTimeReport(projectname string, start time.Time, end time.Time) error // AddUserToProject(username string, projectname string) error // ChangeUserRole(username string, projectname string, role 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 @@ -38,8 +34,9 @@ var scripts embed.FS const userInsert = "INSERT INTO users (username, password) VALUES (?, ?)" const projectInsert = "INSERT INTO projects (name, description, owner_user_id) SELECT ?, ?, id FROM users WHERE username = ?" const promoteToAdmin = "INSERT INTO site_admin (admin_id) SELECT id FROM users WHERE username = ?" -const addTimeReport = "INSERT INTO activity (report_id, activity_nbr, start_time, end_time, break, comment) VALUES (?, ?, ?, ?, ?, ?)" // WIP -const addUserToProject = "INSERT INTO project_member (project_id, user_id, role) VALUES (?, ?, ?)" // WIP + +// const addTimeReport = "" +// const addUserToProject = "" // const changeUserRole = "" // DbConnect connects to the database @@ -59,27 +56,13 @@ func DbConnect(dbpath string) Database { return &Db{db} } -func (d *Db) AddTimeReport(projectname string, start time.Time, end time.Time, breakTime uint32) error { // WIP - _, err := d.Exec(addTimeReport, projectname, 0, start, end, breakTime, false) - return err -} +// func (d *Db) AddTimeReport(projectname string, start time.Time, end time.Time) error { -func (d *Db) AddUserToProject(username string, projectname string, role string) error { // WIP - var userid int - userid, err := d.GetUserId(username) - if err != nil { - panic(err) - } +// } - var projectid int - projectid, err2 := d.GetProjectId(projectname) - if err2 != nil { - panic(err2) - } +// func (d *Db) AddUserToProject(username string, projectname string) error { - _, err3 := d.Exec(addUserToProject, projectid, userid, role) - return err3 -} +// } // func (d *Db) ChangeUserRole(username string, projectname string, role string) error { @@ -104,13 +87,7 @@ func (d *Db) PromoteToAdmin(username string) error { func (d *Db) GetUserId(username string) (int, error) { var id int - err := d.Get(&id, "SELECT id FROM users WHERE username = ?", username) // Borde det inte vara "user" i singular - return id, err -} - -func (d *Db) GetProjectId(projectname string) (int, error) { // WIP, denna kan vara goof - var id int - err := d.Get(&id, "SELECT id FROM project WHERE project_name = ?", projectname) + err := d.Get(&id, "SELECT id FROM users WHERE username = ?", username) return id, err } diff --git a/backend/internal/model/timereport.go b/backend/internal/model/timereport.go deleted file mode 100644 index d48c5fb..0000000 --- a/backend/internal/model/timereport.go +++ /dev/null @@ -1,19 +0,0 @@ -package model - -type TimeReport struct { - reportId string - projectName string - userName string - userRole string - reportDate string - timeWorked uint64 - isSigned bool - reportStatus string // Example "draft", "signed", "unsigned" -} - -type Project struct { - timeReports []TimeReport - projectName string - projectmembers map[string]User - projectRoles map[string]User -} diff --git a/backend/internal/model/user.go b/backend/internal/model/user.go deleted file mode 100644 index c125a60..0000000 --- a/backend/internal/model/user.go +++ /dev/null @@ -1,139 +0,0 @@ -package model - -import ( - "errors" -) - -type Account struct { - fullName string - userName string -} - -type Administrator struct { - projects map[string]Project - Account - ProjectMember // comp -} - -// Administrator reciever functions -func (administrator Administrator) addUser(project *Project, user *User) error { - // WIP - return errors.New("WIP") -} - -func (administrator Administrator) removerUser(project *Project, user *User) error { - // WIP - return errors.New("WIP") -} - -func (administrator Administrator) deleteProject(project *Project) error { - // WIP - return errors.New("WIP") -} - -func (administrator Administrator) changeUserRole(project *Project, user *User) error { - // WIP - return errors.New("WIP") -} - -func (administrator *Administrator) login() error { - // WIP - return errors.New("WIP") -} - -func (administrator *Administrator) logout() error { - // WIP - return errors.New("WIP") -} - -type ProjectManager struct { - managedProjects map[string]Project // projekt som förvaltas av projektledaren - totalTime uint64 // total totalt tid arbetat av projektledaren - Account - ProjectMember // comp -} - -// ProjectManager reciever functions -func (projectManager ProjectManager) signReport(timeReport *TimeReport, user User) error { - // WIP - return errors.New("WIP") -} - -func (projectManager ProjectManager) unsignReport(timeReport *TimeReport, user User) error { - // WIP - return errors.New("WIP") -} - -func (projectManager ProjectManager) getAllReports(project *Project) ([]TimeReport, error) { - // WIP - return project.timeReports, errors.New("WIP") -} - -func (projectManager ProjectManager) assignRole(user *User, project *Project, newRole string) error { - // WIP - return errors.New("WIP") -} - -func (projectManager ProjectManager) removeMember(project *Project, user *User) error { - // WIP - return errors.New("WIP") -} - -func (projectManager ProjectManager) getTotalTime(project *Project) (uint64, error) { - // WIP - return 0, errors.New("WIP") -} - -func (projectManager *ProjectManager) login() error { - // WIP - return errors.New("WIP") -} - -func (projectManager *ProjectManager) logout() error { - // WIP - return errors.New("WIP") -} - -type ProjectMember struct { - timereports []TimeReport - role string // ????? - Account // comp -} - -// User reciever functions - -// function used to create a time report, returning a *TimeReport is questionable -func (ProjectMember *ProjectMember) createTimeReport(Project *Project) (*TimeReport, error) { - // WIP - return &TimeReport{}, errors.New("WIP") -} - -func (ProjectMember ProjectMember) getTimeReport(timereports *[]TimeReport) (*TimeReport, error) { - // WIP - return &TimeReport{}, errors.New("WIP") -} - -func (ProjectMember *ProjectMember) editTimeReport(timereport *TimeReport) { - // timereport.editReport() - // WIP -} - -func (projectUser ProjectMember) deleteTimeReport(timeReport *TimeReport) error { // Ska bara project manager kunna göra detta? fråga ledarna! - // WIP - return errors.New("WIP") -} - -func (projectUser *ProjectMember) login() error { - // WIP - return errors.New("WIP") -} - -func (projectUser *ProjectMember) logout() error { - // WIP - return errors.New("WIP") -} - -type User interface { - login() - logout() -} diff --git a/go.work.sum b/go.work.sum deleted file mode 100644 index a58340b..0000000 --- a/go.work.sum +++ /dev/null @@ -1,15 +0,0 @@ -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= -golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=