Added area deletion

This commit is contained in:
Magnus Åhall 2024-06-02 09:17:50 +02:00
parent 72f23b9c4d
commit b83adad7c8
10 changed files with 379 additions and 21 deletions

View file

@ -1,6 +1,9 @@
package main
import (
// External
werr "git.gibonuddevalla.se/go/wrappederror"
// Standard
"sort"
)
@ -22,11 +25,23 @@ func (s *Section) SortedTriggers() []Trigger {
return s.Triggers
}
func SectionCreate(areaID int, name string) (err error) {// {{{
func SectionCreate(areaID int, name string) (err error) { // {{{
_, err = service.Db.Conn.Exec(`INSERT INTO section(area_id, name) VALUES($1, $2)`, areaID, name)
return
}// }}}
func SectionRename(id int, name string) (err error) {// {{{
} // }}}
func SectionRename(id int, name string) (err error) { // {{{
_, err = service.Db.Conn.Exec(`UPDATE section SET name=$2 WHERE id=$1`, id, name)
return
}// }}}
} // }}}
func SectionDelete(id int) (err error) { // {{{
_, err = service.Db.Conn.Exec(`DELETE FROM public.trigger WHERE section_id = $1`, id)
if err != nil {
return werr.Wrap(err).WithData(id)
}
_, err = service.Db.Conn.Exec(`DELETE FROM public.section WHERE id = $1`, id)
if err != nil {
return werr.Wrap(err).WithData(id)
}
return
} // }}}