Add data models

This commit is contained in:
2025-10-15 11:14:56 +02:00
parent 2433b865da
commit 8f034d6309
11 changed files with 393 additions and 116 deletions

79
internal/models/models.go Normal file
View File

@@ -0,0 +1,79 @@
package models
import "time"
// Player represents a participant in the drinking game.
type Player struct {
ID int `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Game represents a Dark Souls game variant.
type Game struct {
ID int `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Boss represents a boss in a Dark Souls game.
type Boss struct {
ID int `json:"id"`
Name string `json:"name"`
GameID int `json:"game_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Drink represents a type of alcoholic beverage.
type Drink struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"` // e.g., "beer", "shot", "cocktail"
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// EventType represents the type of event that occurred during a session.
type EventType string
const (
EventTypeStart EventType = "start"
EventTypeEnd EventType = "end"
EventTypeBossDefeated EventType = "boss_defeated"
EventTypeDeath EventType = "death"
)
// Session represents a game session with multiple players.
type Session struct {
ID int `json:"id"`
GameID int `json:"game_id"`
StartedAt time.Time `json:"started_at"`
EndedAt *time.Time `json:"ended_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Event represents an event that occurred during a session.
type Event struct {
ID int `json:"id"`
SessionID int `json:"session_id"`
EventType EventType `json:"event_type"`
PlayerID int `json:"player_id"`
BossID *int `json:"boss_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
Notes string `json:"notes,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// PenaltyDrink represents a drink consumed as a penalty.
type PenaltyDrink struct {
ID int `json:"id"`
EventID int `json:"event_id"`
PlayerID int `json:"player_id"`
DrinkID int `json:"drink_id"`
CreatedAt time.Time `json:"created_at"`
}

View File

@@ -111,6 +111,30 @@ func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) {
data := AdminMenuBar()
data.Title = "Admin Panel"
s.renderTemplate(w, http.StatusOK, "admin.html", data)
case "/players":
data := DefaultMenuBar()
data.Title = "Players"
s.renderTemplate(w, http.StatusOK, "players.html", data)
case "/games":
data := DefaultMenuBar()
data.Title = "Games"
s.renderTemplate(w, http.StatusOK, "games.html", data)
case "/bosses":
data := DefaultMenuBar()
data.Title = "Bosses"
s.renderTemplate(w, http.StatusOK, "bosses.html", data)
case "/sessions":
data := DefaultMenuBar()
data.Title = "Sessions"
s.renderTemplate(w, http.StatusOK, "sessions.html", data)
case "/statistics":
data := DefaultMenuBar()
data.Title = "Statistics"
s.renderTemplate(w, http.StatusOK, "statistics.html", data)
case "/drinks":
data := DefaultMenuBar()
data.Title = "Drinks"
s.renderTemplate(w, http.StatusOK, "drinks.html", data)
case "/counter":
s.handleCounter(w, r)
case "/time":

View File

@@ -40,22 +40,22 @@ func DefaultMenuBar() PageData {
ShowClock: true,
MenuGroups: []MenuGroup{
{
Label: "File",
Label: "Game",
Items: []MenuItem{
{Label: "New", URL: "#!"},
{Label: "Open", URL: "#!"},
{Label: "Save", URL: "#!"},
{Label: "Save As", URL: "#!"},
{Label: "Home", URL: "/"},
{Label: "Sessions", URL: "/sessions"},
{Label: "Statistics", URL: "/statistics"},
{IsDivider: true},
{Label: "Exit", URL: "#!"},
},
},
{
Label: "Edit",
Label: "Manage",
Items: []MenuItem{
{Label: "Cut", URL: "#!"},
{Label: "Copy", URL: "#!"},
{Label: "Paste", URL: "#!"},
{Label: "Players", URL: "/players"},
{Label: "Games", URL: "/games"},
{Label: "Bosses", URL: "/bosses"},
{Label: "Drinks", URL: "/drinks"},
},
},
{