2021-05-09 22:08:10 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) GetProjects(userID int) (projects []db.Project, err error) {
|
2021-05-14 00:37:45 +02:00
|
|
|
projects = make([]db.Project, 0, 0)
|
|
|
|
|
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 {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.deleteObject(0, db.ProjectProps, intObjectID(projectID))
|
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
|
|
|
}
|