code simplification
This commit is contained in:
parent
be80307bde
commit
cf2e217030
7 changed files with 47 additions and 73 deletions
|
|
@ -13,7 +13,7 @@ import (
|
|||
"git.bronku.xyz/bronku/cake-order-tracker/server/templates"
|
||||
)
|
||||
|
||||
func weekInterval(t time.Time) (firstDay, lastDay time.Time) {
|
||||
func weekInterval(t time.Time) (time.Time, time.Time) {
|
||||
monday := t.AddDate(0, 0, -((int(t.Weekday()) + 6) % 7))
|
||||
sunday := monday.AddDate(0, 0, 6)
|
||||
return monday, sunday
|
||||
|
|
@ -154,14 +154,6 @@ func (h *Server) blocked(r *http.Request) (templ.Component, int, error) {
|
|||
return templates.BlockedPage(dates), http.StatusOK, nil
|
||||
}
|
||||
|
||||
func loadBlockedDates(h *Server) []models.BlockedDate {
|
||||
dates, err := h.s.GetBlockedDates()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return dates
|
||||
}
|
||||
|
||||
func (h *Server) order(r *http.Request) (templ.Component, int, error) {
|
||||
catalogue, err := h.s.GetCakes()
|
||||
if err != nil {
|
||||
|
|
@ -171,7 +163,10 @@ func (h *Server) order(r *http.Request) (templ.Component, int, error) {
|
|||
if err != nil {
|
||||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
blockedDates := loadBlockedDates(h)
|
||||
blockedDates, err := h.s.GetBlockedDates()
|
||||
if err != nil {
|
||||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
url := strings.Split(r.URL.Path, "/")
|
||||
if len(url) < 3 || url[2] == "" {
|
||||
|
|
|
|||
|
|
@ -22,21 +22,6 @@ func OrderTitle(order models.Order) string {
|
|||
return "Nowe zamówienie"
|
||||
}
|
||||
|
||||
func specialCakeDetail(sc models.SpecialCake) string {
|
||||
return sc.Detail()
|
||||
}
|
||||
|
||||
func cakeItemsDesc(cakes []models.Cake) string {
|
||||
desc := ""
|
||||
for i, c := range cakes {
|
||||
if i > 0 {
|
||||
desc += ", "
|
||||
}
|
||||
desc += c.Name + " (x" + strconv.Itoa(c.Amount) + ")"
|
||||
}
|
||||
return desc
|
||||
}
|
||||
|
||||
func cakeHasTag(tags []models.Tag, id int) bool {
|
||||
for _, t := range tags {
|
||||
if t.ID == id {
|
||||
|
|
@ -63,7 +48,13 @@ func tagNames(tags []models.Tag) string {
|
|||
}
|
||||
|
||||
func orderItemsDesc(order models.Order) string {
|
||||
desc := cakeItemsDesc(order.Cakes)
|
||||
desc := ""
|
||||
for i, c := range order.Cakes {
|
||||
if i > 0 {
|
||||
desc += ", "
|
||||
}
|
||||
desc += c.Name + " (x" + strconv.Itoa(c.Amount) + ")"
|
||||
}
|
||||
for _, s := range order.SpecialCakes {
|
||||
if desc != "" {
|
||||
desc += ", "
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
|
|||
<li data-special-id={ strconv.Itoa(s.ID) }>
|
||||
<div class="basket-item-body">
|
||||
<div class="name">{ s.Name }</div>
|
||||
<div class="detail">{ specialCakeDetail(s) }</div>
|
||||
<div class="detail">{ s.Detail() }</div>
|
||||
if len(s.Tags) > 0 {
|
||||
<div class="basket-item-tags">
|
||||
for _, t := range s.Tags {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue