Semaphore/db/sql/view.go

59 lines
1.3 KiB
Go
Raw Normal View History

2021-10-26 20:19:12 +02:00
package sql
import "github.com/ansible-semaphore/semaphore/db"
func (d *SqlDb) GetView(projectID int, viewID int) (view db.View, err error) {
2021-10-27 14:15:36 +02:00
err = d.getObject(projectID, db.ViewProps, viewID, &view)
2021-10-26 20:19:12 +02:00
return
}
func (d *SqlDb) GetViews(projectID int) (views []db.View, err error) {
2024-07-02 19:23:45 +02:00
err = d.getObjects(projectID, db.ViewProps, db.RetrieveQueryParams{}, &views)
2021-10-26 20:19:12 +02:00
return
}
func (d *SqlDb) UpdateView(view db.View) error {
2021-10-27 14:15:36 +02:00
_, err := d.exec(
"update project__view set title=?, position=?, project_id=? where id=?",
view.Title,
view.Position,
view.ProjectID,
view.ID)
return err
2021-10-26 20:19:12 +02:00
}
func (d *SqlDb) CreateView(view db.View) (newView db.View, err error) {
2021-10-27 14:15:36 +02:00
insertID, err := d.insert(
"id",
"insert into project__view (project_id, title, position) values (?, ?, ?)",
view.ProjectID,
view.Title,
view.Position)
if err != nil {
return
}
newView = view
newView.ID = insertID
2021-10-26 20:19:12 +02:00
return
}
func (d *SqlDb) DeleteView(projectID int, viewID int) error {
2021-10-27 14:15:36 +02:00
return d.deleteObject(projectID, db.ViewProps, viewID)
}
func (d *SqlDb) SetViewPositions(projectID int, positions map[int]int) error {
2021-10-27 14:15:36 +02:00
for id, position := range positions {
_, err := d.exec("update project__view set position=? where project_id=? and id=?",
position,
projectID,
id)
if err != nil {
return err
}
}
return nil
}