mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
feat(be): sql implementation of views
This commit is contained in:
parent
339dfa52ce
commit
793d74dac6
@ -26,7 +26,7 @@ func (d *BoltDb) DeleteView(projectID int, viewID int) error {
|
||||
}
|
||||
|
||||
func (d *BoltDb) SetViewPositions(projectID int, positions map[int]int) error {
|
||||
for position, id := range positions {
|
||||
for id, position := range positions {
|
||||
view, err := d.GetView(projectID, id)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -111,8 +111,8 @@ func TestSetViewPositions(t *testing.T) {
|
||||
}
|
||||
|
||||
err = store.SetViewPositions(proj1.ID, map[int]int{
|
||||
v1.ID: 1,
|
||||
v2.ID: 2,
|
||||
v1.ID: 3,
|
||||
v2.ID: 6,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@ -133,7 +133,7 @@ func TestSetViewPositions(t *testing.T) {
|
||||
return found[i].Position < found[j].Position
|
||||
})
|
||||
|
||||
if found[0].Position != 1 || found[1].Position != 2 {
|
||||
if found[0].Position != 3 || found[1].Position != 6 {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ func (d *SqlDb) CreateTemplate(template db.Template) (newTemplate db.Template, e
|
||||
"id",
|
||||
"insert into project__template (project_id, inventory_id, repository_id, environment_id, " +
|
||||
"alias, playbook, arguments, override_args, description, vault_key_id, `type`, start_version," +
|
||||
"build_template_id)" +
|
||||
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"build_template_id, view_id)" +
|
||||
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
template.ProjectID,
|
||||
template.InventoryID,
|
||||
template.RepositoryID,
|
||||
@ -25,7 +25,8 @@ func (d *SqlDb) CreateTemplate(template db.Template) (newTemplate db.Template, e
|
||||
template.VaultKeyID,
|
||||
template.Type,
|
||||
template.StartVersion,
|
||||
template.BuildTemplateID)
|
||||
template.BuildTemplateID,
|
||||
template.ViewID)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
@ -57,6 +58,7 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
|
||||
"`type`=?, " +
|
||||
"start_version=?," +
|
||||
"build_template_id=? " +
|
||||
"view_id=? " +
|
||||
"where removed = false and id=? and project_id=?",
|
||||
template.InventoryID,
|
||||
template.RepositoryID,
|
||||
@ -70,6 +72,7 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
|
||||
template.Type,
|
||||
template.StartVersion,
|
||||
template.BuildTemplateID,
|
||||
template.ViewID,
|
||||
template.ID,
|
||||
template.ProjectID,
|
||||
)
|
||||
|
@ -3,26 +3,56 @@ package sql
|
||||
import "github.com/ansible-semaphore/semaphore/db"
|
||||
|
||||
func (d *SqlDb) GetView(projectID int, viewID int) (view db.View, err error) {
|
||||
err = d.getObject(projectID, db.ViewProps, viewID, &view)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) GetViews(projectID int) (views []db.View, err error) {
|
||||
views = make([]db.View, 0)
|
||||
err = d.getObjects(projectID, db.ViewProps, db.RetrieveQueryParams{}, &views)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) UpdateView(view db.View) error {
|
||||
return nil
|
||||
_, err := d.exec(
|
||||
"update project__view set title=?, position=?, project_id=? where id=?",
|
||||
view.Title,
|
||||
view.Position,
|
||||
view.ProjectID,
|
||||
view.ID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *SqlDb) CreateView(view db.View) (newView db.View, err error) {
|
||||
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
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) DeleteView(projectID int, viewID int) error {
|
||||
return nil
|
||||
return d.deleteObject(projectID, db.ViewProps, viewID)
|
||||
}
|
||||
|
||||
func (d *SqlDb) SetViewPositions(projectID int, positions map[int]int) error {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user