Implemented adding/renaming of areas and sections

This commit is contained in:
Magnus Åhall 2024-05-01 21:02:45 +02:00
parent d935eb282b
commit 62405c3138
13 changed files with 175 additions and 13 deletions

20
area.go
View file

@ -10,13 +10,13 @@ import (
)
type Area struct {
ID int
ID int
Name string
Sections []Section
}
func AreaRetrieve() (areas []Area, err error) {// {{{
func AreaRetrieve() (areas []Area, err error) { // {{{
areas = []Area{}
row := service.Db.Conn.QueryRow(`
SELECT
@ -32,7 +32,7 @@ func AreaRetrieve() (areas []Area, err error) {// {{{
)
) AS sections
FROM area a
INNER JOIN section s ON s.area_id = a.id
LEFT JOIN section s ON s.area_id = a.id
GROUP BY
a.id, a.name
) jsonsections`,
@ -51,12 +51,20 @@ func AreaRetrieve() (areas []Area, err error) {// {{{
return
}
return
} // }}}
func AreaCreate(name string) (err error) {// {{{
_, err = service.Db.Conn.Exec(`INSERT INTO area(name) VALUES($1)`, name)
return
}// }}}
func AreaRename(id int, name string) (err error) {// {{{
_, err = service.Db.Conn.Exec(`UPDATE area SET name=$2 WHERE id=$1`, id, name)
return
}// }}}
func (a Area) SortedSections() []Section {// {{{
sort.SliceStable(a.Sections, func (i, j int) bool {
func (a Area) SortedSections() []Section { // {{{
sort.SliceStable(a.Sections, func(i, j int) bool {
return a.Sections[i].Name < a.Sections[j].Name
})
return a.Sections
}// }}}
} // }}}