removed cake categories

This commit is contained in:
bronku 2026-06-11 01:13:42 +02:00
parent b3a5c0b19e
commit d382de4236
10 changed files with 12 additions and 106 deletions

View file

@ -3,12 +3,10 @@ package models
import "time"
type Cake struct {
Name string
ID int
Price int // increments of 0.01
Amount int
Category string
Availability string
Name string
ID int
Price int // increments of 0.01
Amount int
}
type Order struct {

View file

@ -26,8 +26,6 @@ func (h *Server) postCake(r *http.Request) (any, int, error) {
if err != nil {
return nil, http.StatusBadRequest, err
}
n.Category = r.FormValue("category")
n.Availability = r.FormValue("availability")
n.ID, err = h.s.SaveCake(n)
fmt.Println(err)
return n, http.StatusAccepted, err

View file

@ -17,25 +17,9 @@ Ciasto {{if .ID}}#{{.ID}}{{else}}nowe{{end}}
<input class="form-input" type="text" name="name" value="{{.Name}}" placeholder="Nazwa ciasta">
</div>
<div class="form-group">
<label>Cena (gr) *</label>
<label>Cena</label>
<input class="form-input" type="number" name="price" min="0" value="{{.Price}}">
</div>
<div class="form-group">
<label>Kategoria</label>
<select class="form-input" name="category">
<option {{if eq .Category "common"}}selected{{end}} value="common">Zwykłe</option>
<option {{if eq .Category "christmas"}}selected{{end}} value="christmas">Bożonarodzeniowe</option>
<option {{if eq .Category "easter"}}selected{{end}} value="easter">Wielkanocne</option>
<option {{if eq .Category "donuts"}}selected{{end}} value="donuts">Pączki</option>
</select>
</div>
<div class="form-group">
<label>Dostępność</label>
<select class="form-input" name="availability">
<option {{if eq .Availability "available"}}selected{{end}} value="available">Dostępne</option>
<option {{if eq .Availability "unavailable"}}selected{{end}} value="unavailable">Niedostępne</option>
</select>
</div>
<div class="form-actions">
<a href="/cakes" class="btn btn-outline">Anuluj</a>
<button type="submit" class="btn btn-primary">

View file

@ -21,8 +21,6 @@ Katalog
<th>Nazwa</th>
<th>SKU</th>
<th class="right">Cena bazowa</th>
<th>Kategoria</th>
<th>Dostępność</th>
<th class="center"></th>
</tr>
</thead>
@ -37,16 +35,6 @@ Katalog
<td style="font-weight:500">{{.Name}}</td>
<td class="text-on-surface-variant">#{{.ID}}</td>
<td class="text-right">{{.Price}} PLN</td>
<td>
<span class="badge-pill {{if eq .Category "common"}}signature{{else}}seasonal{{end}}">
{{if eq .Category "common"}}Zwykłe
{{else if eq .Category "christmas"}}Bożonarodzeniowe
{{else if eq .Category "easter"}}Wielkanocne
{{else if eq .Category "donuts"}}Pączki
{{else}}{{.Category}}{{end}}
</span>
</td>
<td>{{if eq .Availability "available"}}Dostępne{{else}}Niedostępne{{end}}</td>
<td class="text-center">
<a href="/cake/{{.ID}}" class="action-btn">
<span class="material-symbols-outlined">edit</span>

View file

@ -21,24 +21,6 @@
<header class="topnav">
<div class="topnav-left">
<h1 class="topnav-title">{{template "title" .}}</h1>
<div class="topnav-search">
<span class="material-symbols-outlined">search</span>
<input type="text" placeholder="Szukaj zamówień..." />
</div>
</div>
<nav class="topnav-center">
<a class="topnav-period active" href="/orders">Dzisiaj</a>
<a class="topnav-period" href="/orders">Ten tydzień</a>
<a class="topnav-period" href="/orders">Miesiąc</a>
</nav>
<div class="topnav-right">
<a class="topnav-btn" href="/orders">
<span class="material-symbols-outlined">sync</span>
Sync
</a>
<a class="topnav-icon" href="#">
<span class="material-symbols-outlined">notifications</span>
</a>
</div>
</header>
<div class="main-content">

View file

@ -1,8 +1,4 @@
{{define "nav"}}
<div class="sidebar-brand">
<h1>Crumbs &amp; Co.</h1>
<p>Produkcja</p>
</div>
<a href="/order" class="sidebar-cta">
<span class="material-symbols-outlined">add</span>
<span>Nowe zamówienie</span>
@ -12,28 +8,9 @@
<span class="material-symbols-outlined">dashboard</span>
<span>Panel główny</span>
</a>
<a href="/order" class="sidebar-link">
<span class="material-symbols-outlined">shopping_cart</span>
<span>Zamówienia</span>
</a>
<a href="/cakes" class="sidebar-link">
<span class="material-symbols-outlined">inventory_2</span>
<span>Katalog</span>
</a>
</div>
<div class="sidebar-footer">
<a href="/logout" class="sidebar-link">
<span class="material-symbols-outlined">settings</span>
<span>Ustawienia</span>
</a>
<div class="sidebar-user">
<div class="sidebar-user-avatar">
<span class="material-symbols-outlined" style="font-size:18px">person</span>
</div>
<div class="sidebar-user-info">
<span class="sidebar-user-name">Menedżer</span>
<span class="sidebar-user-status">Aktywny</span>
</div>
</div>
</div>
{{end}}

View file

@ -43,13 +43,6 @@
<label>Data dostawy *</label>
<input class="form-input" type="date" name="date" value="{{.Date.Format "2006-01-02"}}">
</div>
<div class="form-group">
<label>Status</label>
<select class="form-input" name="status">
<option {{if eq .Status "accepted"}}selected{{end}} value="accepted">Przyjęte</option>
<option {{if eq .Status "done"}}selected{{end}} value="done">Gotowe</option>
</select>
</div>
<div class="form-group">
<label>Zaliczka</label>
<input class="form-input" type="number" name="paid" min="0" value="{{.Paid}}">

View file

@ -123,16 +123,4 @@ Panel główny
{{end}}
</tbody>
</table>
<div class="table-footer">
<span>Pokazuje 1-{{len .}} z {{len .}}</span>
<div class="pagination">
<button class="pagination-btn" disabled>
<span class="material-symbols-outlined">chevron_left</span>
</button>
<button class="pagination-btn active">1</button>
<button class="pagination-btn" disabled>
<span class="material-symbols-outlined">chevron_right</span>
</button>
</div>
</div>
{{end}}

View file

@ -22,7 +22,7 @@ func (s *Store) cakeCount() int {
func (s *Store) loadCakes() ([]models.Cake, error) {
out := make([]models.Cake, 0, s.cakeCount())
rows, err := s.db.Query("select id, name, price, category, availability from cake order by id;")
rows, err := s.db.Query("select id, name, price from cake order by id;")
if err != nil {
return out, err
}
@ -30,7 +30,7 @@ func (s *Store) loadCakes() ([]models.Cake, error) {
for rows.Next() {
var cake models.Cake
err = rows.Scan(&cake.ID, &cake.Name, &cake.Price, &cake.Category, &cake.Availability)
err = rows.Scan(&cake.ID, &cake.Name, &cake.Price)
if err != nil {
continue
}
@ -69,8 +69,8 @@ func (s *Store) GetCakes() ([]models.Cake, error) {
}
func (s *Store) updateCake(newCake models.Cake) error {
query := "update cake set name = ? , price = ?, category = ?, availability = ? where id = ?"
_, err := s.db.Exec(query, newCake.Name, newCake.Price, newCake.Category, newCake.Availability, newCake.ID)
query := "update cake set name = ? , price = ? where id = ?"
_, err := s.db.Exec(query, newCake.Name, newCake.Price, newCake.ID)
if err != nil {
return err
}
@ -88,8 +88,8 @@ func (s *Store) SaveCake(newCake models.Cake) (int, error) {
return newCake.ID, s.updateCake(newCake)
}
fmt.Println("adding a new cake", newCake)
query := "insert into cake(name, price, category, availability) values (?, ?, ?, ?);"
result, err := s.db.Exec(query, newCake.Name, newCake.Price, newCake.Category, newCake.Availability)
query := "insert into cake(name, price) values (?, ? );"
result, err := s.db.Exec(query, newCake.Name, newCake.Price)
if err != nil {
return 0, err
}

View file

@ -1,9 +1,7 @@
create table cake (
id integer primary key autoincrement,
name text not null unique,
price integer not null,
category text,
availability text
price integer not null
);
create table customer_order (