2021-05-09 22:08:10 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
2024-10-26 14:56:17 +02:00
|
|
|
"github.com/semaphoreui/semaphore/db"
|
2021-05-09 22:08:10 +02:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (d *BoltDb) CreateProject(project db.Project) (db.Project, error) {
|
|
|
|
project.Created = time.Now()
|
|
|
|
|
2021-05-13 21:45:54 +02:00
|
|
|
newProject, err := d.createObject(0, db.ProjectProps, project)
|
2021-05-09 22:08:10 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return db.Project{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return newProject.(db.Project), nil
|
|
|
|
}
|
|
|
|
|
2023-09-17 16:15:44 +02:00
|
|
|
func (d *BoltDb) GetAllProjects() (projects []db.Project, err error) {
|
|
|
|
err = d.getObjects(0, db.ProjectProps, db.RetrieveQueryParams{}, nil, &projects)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-09 22:08:10 +02:00
|
|
|
func (d *BoltDb) GetProjects(userID int) (projects []db.Project, err error) {
|
2021-06-24 21:58:39 +02:00
|
|
|
projects = make([]db.Project, 0)
|
2021-05-14 00:37:45 +02:00
|
|
|
|
2021-05-09 22:08:10 +02:00
|
|
|
var allProjects []db.Project
|
|
|
|
|
2021-05-13 21:45:54 +02:00
|
|
|
err = d.getObjects(0, db.ProjectProps, db.RetrieveQueryParams{}, nil, &allProjects)
|
2021-05-09 22:08:10 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range allProjects {
|
|
|
|
_, err2 := d.GetProjectUser(v.ID, userID)
|
|
|
|
if err2 == nil {
|
|
|
|
projects = append(projects, v)
|
|
|
|
} else if err2 != db.ErrNotFound {
|
|
|
|
err = err2
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) GetProject(projectID int) (project db.Project, err error) {
|
2021-05-13 21:45:54 +02:00
|
|
|
err = d.getObject(0, db.ProjectProps, intObjectID(projectID), &project)
|
2021-05-09 22:08:10 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteProject(projectID int) error {
|
2022-01-31 23:16:00 +01:00
|
|
|
return d.deleteObject(0, db.ProjectProps, intObjectID(projectID), nil)
|
2021-05-09 22:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) UpdateProject(project db.Project) error {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.updateObject(0, db.ProjectProps, project)
|
2021-05-09 22:08:10 +02:00
|
|
|
}
|