2021-10-26 20:19:12 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import "github.com/ansible-semaphore/semaphore/db"
|
|
|
|
|
|
|
|
func (d *BoltDb) GetView(projectID int, viewID int) (view db.View, err error) {
|
2021-10-27 13:43:04 +02:00
|
|
|
err = d.getObject(projectID, db.ViewProps, intObjectID(viewID), &view)
|
2021-10-26 20:19:12 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) GetViews(projectID int) (views []db.View, err error) {
|
2021-10-27 13:43:04 +02:00
|
|
|
err = d.getObjects(projectID, db.ViewProps, db.RetrieveQueryParams{}, nil, &views)
|
2021-10-26 20:19:12 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) UpdateView(view db.View) error {
|
2021-10-27 13:43:04 +02:00
|
|
|
return d.updateObject(view.ProjectID, db.ViewProps, view)
|
2021-10-26 20:19:12 +02:00
|
|
|
}
|
|
|
|
|
2021-10-27 13:43:04 +02:00
|
|
|
func (d *BoltDb) CreateView(view db.View) (db.View, error) {
|
|
|
|
newView, err := d.createObject(view.ProjectID, db.ViewProps, view)
|
|
|
|
return newView.(db.View), err
|
2021-10-26 20:19:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteView(projectID int, viewID int) error {
|
2022-01-31 23:16:00 +01:00
|
|
|
return d.deleteObject(projectID, db.ViewProps, intObjectID(viewID), nil)
|
2021-10-27 13:43:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) SetViewPositions(projectID int, positions map[int]int) error {
|
2021-10-27 14:15:36 +02:00
|
|
|
for id, position := range positions {
|
2021-10-27 13:58:45 +02:00
|
|
|
view, err := d.GetView(projectID, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
view.Position = position
|
|
|
|
err = d.UpdateView(view)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2021-10-26 20:19:12 +02:00
|
|
|
return nil
|
2021-10-27 13:43:04 +02:00
|
|
|
}
|