small improvements
This commit is contained in:
parent
bb32802324
commit
5f2d6f00bc
10 changed files with 117 additions and 178 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/a-h/templ"
|
||||
|
||||
"git.bronku.xyz/bronku/cake-order-tracker/config"
|
||||
"git.bronku.xyz/bronku/cake-order-tracker/models"
|
||||
"git.bronku.xyz/bronku/cake-order-tracker/server/templates"
|
||||
)
|
||||
|
|
@ -26,15 +27,15 @@ func (h *Server) orders(_ *http.Request) (templ.Component, int, error) {
|
|||
y, m, _ = time.Now().Date()
|
||||
first, last := monthInterval(y, m)
|
||||
orders, err := h.s.GetOrders(first, last)
|
||||
return templates.OrdersPage(first.Format("2006-01-02"), last.Format("2006-01-02"), orders), http.StatusOK, err
|
||||
return templates.OrdersPage(first.Format(config.DateFormat), last.Format(config.DateFormat), orders), http.StatusOK, err
|
||||
}
|
||||
|
||||
func (h *Server) ordersSearch(r *http.Request) (templ.Component, int, error) {
|
||||
from, err := time.Parse("2006-01-02", r.URL.Query().Get("from"))
|
||||
from, err := time.Parse(config.DateFormat, r.URL.Query().Get("from"))
|
||||
if err != nil {
|
||||
from = time.Time{}
|
||||
}
|
||||
to, err := time.Parse("2006-01-02", r.URL.Query().Get("to"))
|
||||
to, err := time.Parse(config.DateFormat, r.URL.Query().Get("to"))
|
||||
if err != nil {
|
||||
to = time.Time{}
|
||||
}
|
||||
|
|
@ -48,7 +49,7 @@ func (h *Server) cakes(_ *http.Request) (templ.Component, int, error) {
|
|||
}
|
||||
|
||||
func (h *Server) cake(r *http.Request) (templ.Component, int, error) {
|
||||
url := strings.Split(r.URL.String(), "/")
|
||||
url := strings.Split(r.URL.Path, "/")
|
||||
if len(url) < 3 || url[2] == "" {
|
||||
return templates.CakePage(models.Cake{}), http.StatusOK, nil
|
||||
}
|
||||
|
|
@ -73,7 +74,7 @@ func (h *Server) order(r *http.Request) (templ.Component, int, error) {
|
|||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
url := strings.Split(r.URL.String(), "/")
|
||||
url := strings.Split(r.URL.Path, "/")
|
||||
if len(url) < 3 || url[2] == "" {
|
||||
return templates.OrderPage(models.Order{Date: time.Now()}, catalogue), http.StatusOK, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue