Compare commits

...

4 Commits

Author SHA1 Message Date
Thomas Williams 9ea200464d Merge pull request '2024-12-29-fixes' (#12) from 2024-12-29-fixes into main
Reviewed-on: #12
2024-12-29 20:43:32 +13:00
Teajey 8a1fef487a
fix: only trim group name 2024-12-29 20:42:59 +13:00
Teajey ffd3890584
fix: check if session exists for see other 2024-12-29 20:41:42 +13:00
Teajey dd952a1f39
fix: check if flash field exists 2024-12-29 20:41:21 +13:00
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 {