Todo/pages/fragments.go

59 lines
1.4 KiB
Go
Raw Normal View History

2024-08-18 04:29:25 +00:00
package pages
import (
"net/http"
"github.com/Cameron-Reed1/todo-web/pages/templates"
)
func OverdueFragment(w http.ResponseWriter, r *http.Request) {
user_db, err := validateSessionAndGetUserDB(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}
defer user_db.Close()
items, err := user_db.GetOverdueTodos()
2024-08-18 04:29:25 +00:00
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
2024-08-19 22:20:55 +00:00
templates.TodoList("Nothing to do in the past", items).Render(r.Context(), w)
2024-08-18 04:29:25 +00:00
}
func TodayFragment(w http.ResponseWriter, r *http.Request) {
user_db, err := validateSessionAndGetUserDB(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}
defer user_db.Close()
items, err := user_db.GetTodayTodos()
2024-08-18 04:29:25 +00:00
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
2024-08-19 22:20:55 +00:00
templates.TodoList("Nothing to do today", items).Render(r.Context(), w)
2024-08-18 04:29:25 +00:00
}
func UpcomingFragment(w http.ResponseWriter, r *http.Request) {
user_db, err := validateSessionAndGetUserDB(r)
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
return
}
defer user_db.Close()
items, err := user_db.GetUpcomingTodos()
2024-08-18 04:29:25 +00:00
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
2024-08-19 22:20:55 +00:00
templates.TodoList("Nothing to do in the future", items).Render(r.Context(), w)
2024-08-18 04:29:25 +00:00
}