Merge pull request '2024-12-29-fixes' (#12) from 2024-12-29-fixes into main

Reviewed-on: #12
This commit is contained in:
Thomas Williams 2024-12-29 20:43:32 +13:00
commit 9ea200464d
3 changed files with 13 additions and 7 deletions

View File

@ -80,7 +80,7 @@ func GetAllGroups() ([]Group, error) {
}
func CreateGroup(name string, reference string) (*Group, error) {
name = normalize.Name(name)
name = normalize.Trim(name)
stmt := "INSERT INTO [group] (name, reference) VALUES (?, ?)"
result, err := database.Exec(stmt, name, reference)
if err != nil {

View File

@ -29,6 +29,7 @@ func (res *Response) Write(w http.ResponseWriter, r *http.Request) error {
if res.SeeOther != "" {
http.Redirect(w, r, res.SeeOther, http.StatusSeeOther)
if res.Session != nil {
flash := res.Session.FlashPeek()
if flash != nil {
err := json.NewEncoder(w).Encode(flash)
@ -36,6 +37,7 @@ func (res *Response) Write(w http.ResponseWriter, r *http.Request) error {
return err
}
}
}
return nil
}

View File

@ -18,7 +18,11 @@ func (s *Session) FlashGet() any {
}
func (s *Session) FlashPeek() any {
list, _ := s.inner.Values["_flash"].([]any)
flash, ok := s.inner.Values["_flash"]
if !ok {
return nil
}
list := flash.([]any)
if len(list) < 1 {
return nil
} else {