From 6cfea2e8dcaba27d707c3beb5bf7b2ffa3b94bc0 Mon Sep 17 00:00:00 2001 From: schreifuchs Date: Fri, 7 Feb 2025 17:14:01 +0100 Subject: [PATCH] status after 3h & 30min --- app.go | 32 ++++- frontend/src/App.svelte | 30 ++-- frontend/src/routes/Home.svelte | 5 +- frontend/src/routes/Matches.svelte | 27 ++++ frontend/src/routes/Participants.svelte | 131 ++++++++++++++++++ frontend/src/routes/Tournament.svelte | 24 +++- ....timestamp-1738933826307-8335ffa455a2a.mjs | 10 ++ frontend/wailsjs/go/main/App.d.ts | 10 ++ frontend/wailsjs/go/main/App.js | 20 +++ frontend/wailsjs/go/models.ts | 6 +- model/model.go | 13 +- model/names.go | 65 +++++++++ tournament.db | Bin 49152 -> 49152 bytes 13 files changed, 337 insertions(+), 36 deletions(-) create mode 100644 frontend/src/routes/Matches.svelte create mode 100644 frontend/src/routes/Participants.svelte create mode 100644 frontend/vite.config.ts.timestamp-1738933826307-8335ffa455a2a.mjs create mode 100644 model/names.go diff --git a/app.go b/app.go index 04779b4..ceb2ced 100644 --- a/app.go +++ b/app.go @@ -38,10 +38,40 @@ func (a *App) GetTournaments() (ts []model.Tournament, err error) { } func (a *App) GetTournament(id int) (t model.Tournament, err error) { - err = a.db.Preload("Game").First(&t, id).Error + err = a.db.Preload("Game").Preload("Participants").First(&t, id).Error return } func (a *App) SaveTournament(t model.Tournament) error { err := a.db.Save(&t).Error return err } +func (a *App) FillRandom(t model.Tournament) { + for range t.Size - len(t.Participants) { + t.Participants = append(t.Participants, &model.Participant{ + Name: model.RandomName(), + IsTemporary: true, + IsTeam: true, + }) + } + a.db.Save(&t.Participants) + a.db.Save(&t) + +} + +func (a *App) GetParticipants() (ps []model.Participant, err error) { + err = a.db.Find(&ps).Error + return +} +func (a *App) SaveParticipant(p model.Participant) error { + return a.db.Save(&p).Error +} +func (a *App) DeleteParticipat(p model.Participant) { + a.db.Delete(&p) +} +func (a *App) RemoveParticipantFromTournament(p model.Participant, t model.Tournament) { + if p.IsTemporary { + a.db.Delete(&p) + return + } + a.db.Model(&t).Association("Participants").Delete(&p) +} diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 7da8399..39124e2 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -1,32 +1,26 @@
- - navigate("", { replace: true })}> - Tournamenter - - - + + + Tournaments + + +
- {#snippet children({ params })} - {/snippet} - + + +
diff --git a/frontend/src/routes/Home.svelte b/frontend/src/routes/Home.svelte index b3eb52e..5286e49 100644 --- a/frontend/src/routes/Home.svelte +++ b/frontend/src/routes/Home.svelte @@ -32,6 +32,7 @@ Title Game Winner + {#each thingsList as t} @@ -47,7 +48,9 @@ - Edit + Edit {/each} diff --git a/frontend/src/routes/Matches.svelte b/frontend/src/routes/Matches.svelte new file mode 100644 index 0000000..9a6a6dc --- /dev/null +++ b/frontend/src/routes/Matches.svelte @@ -0,0 +1,27 @@ + + +{#if tournament.TournamentState == 0} + +{:else}{/if} diff --git a/frontend/src/routes/Participants.svelte b/frontend/src/routes/Participants.svelte new file mode 100644 index 0000000..0f6b628 --- /dev/null +++ b/frontend/src/routes/Participants.svelte @@ -0,0 +1,131 @@ + + +{#if tournament} +
+

{tournament.Participants.length}

+

{tournament.Size}

+

Participants

+

Max Participants

+
+{/if} + + + Name + + + + + + {#each participants as p} + + + {p.Name} + + + {#if tournament.Participants.find((pa) => pa.ID == p.ID)} + + {:else} + + {/if} + + + + + + {/each} + +
+
+ + +
+ +
+ New Participant +
+ + +
+
+ + Single Player + Team +
+
+ + +
+ + +
+
diff --git a/frontend/src/routes/Tournament.svelte b/frontend/src/routes/Tournament.svelte index 37f3581..5383cbd 100644 --- a/frontend/src/routes/Tournament.svelte +++ b/frontend/src/routes/Tournament.svelte @@ -1,10 +1,13 @@ -
- Home -
+
{#if tournament} - {tournament.Title} +
+ {tournament.Title} + +
+ + + + + + + + {/if} diff --git a/frontend/vite.config.ts.timestamp-1738933826307-8335ffa455a2a.mjs b/frontend/vite.config.ts.timestamp-1738933826307-8335ffa455a2a.mjs new file mode 100644 index 0000000..7f83541 --- /dev/null +++ b/frontend/vite.config.ts.timestamp-1738933826307-8335ffa455a2a.mjs @@ -0,0 +1,10 @@ +// vite.config.ts +import { defineConfig } from "file:///home/schreifuchs/go/src/git.schreifuchs.ch/schreifuchs/regio-ue1/frontend/node_modules/.pnpm/vite@5.4.14_sass@1.83.4/node_modules/vite/dist/node/index.js"; +import { svelte } from "file:///home/schreifuchs/go/src/git.schreifuchs.ch/schreifuchs/regio-ue1/frontend/node_modules/.pnpm/@sveltejs+vite-plugin-svelte@4.0.4_svelte@5.19.9_vite@5.4.14_sass@1.83.4_/node_modules/@sveltejs/vite-plugin-svelte/src/index.js"; +var vite_config_default = defineConfig({ + plugins: [svelte()] +}); +export { + vite_config_default as default +}; +//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvaG9tZS9zY2hyZWlmdWNocy9nby9zcmMvZ2l0LnNjaHJlaWZ1Y2hzLmNoL3NjaHJlaWZ1Y2hzL3JlZ2lvLXVlMS9mcm9udGVuZFwiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9maWxlbmFtZSA9IFwiL2hvbWUvc2NocmVpZnVjaHMvZ28vc3JjL2dpdC5zY2hyZWlmdWNocy5jaC9zY2hyZWlmdWNocy9yZWdpby11ZTEvZnJvbnRlbmQvdml0ZS5jb25maWcudHNcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfaW1wb3J0X21ldGFfdXJsID0gXCJmaWxlOi8vL2hvbWUvc2NocmVpZnVjaHMvZ28vc3JjL2dpdC5zY2hyZWlmdWNocy5jaC9zY2hyZWlmdWNocy9yZWdpby11ZTEvZnJvbnRlbmQvdml0ZS5jb25maWcudHNcIjtpbXBvcnQge2RlZmluZUNvbmZpZ30gZnJvbSAndml0ZSdcbmltcG9ydCB7c3ZlbHRlfSBmcm9tICdAc3ZlbHRlanMvdml0ZS1wbHVnaW4tc3ZlbHRlJ1xuXG4vLyBodHRwczovL3ZpdGVqcy5kZXYvY29uZmlnL1xuZXhwb3J0IGRlZmF1bHQgZGVmaW5lQ29uZmlnKHtcbiAgcGx1Z2luczogW3N2ZWx0ZSgpXVxufSlcbiJdLAogICJtYXBwaW5ncyI6ICI7QUFBZ1osU0FBUSxvQkFBbUI7QUFDM2EsU0FBUSxjQUFhO0FBR3JCLElBQU8sc0JBQVEsYUFBYTtBQUFBLEVBQzFCLFNBQVMsQ0FBQyxPQUFPLENBQUM7QUFDcEIsQ0FBQzsiLAogICJuYW1lcyI6IFtdCn0K diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 4d3489f..af3c53d 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -2,10 +2,20 @@ // This file is automatically generated. DO NOT EDIT import {model} from '../models'; +export function DeleteParticipat(arg1:model.Participant):Promise; + +export function FillRandom(arg1:model.Tournament):Promise; + export function GetGames():Promise>; +export function GetParticipants():Promise>; + export function GetTournament(arg1:number):Promise; export function GetTournaments():Promise>; +export function RemoveParticipantFromTournament(arg1:model.Participant,arg2:model.Tournament):Promise; + +export function SaveParticipant(arg1:model.Participant):Promise; + export function SaveTournament(arg1:model.Tournament):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index 04be6e3..9dec93f 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -2,10 +2,22 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +export function DeleteParticipat(arg1) { + return window['go']['main']['App']['DeleteParticipat'](arg1); +} + +export function FillRandom(arg1) { + return window['go']['main']['App']['FillRandom'](arg1); +} + export function GetGames() { return window['go']['main']['App']['GetGames'](); } +export function GetParticipants() { + return window['go']['main']['App']['GetParticipants'](); +} + export function GetTournament(arg1) { return window['go']['main']['App']['GetTournament'](arg1); } @@ -14,6 +26,14 @@ export function GetTournaments() { return window['go']['main']['App']['GetTournaments'](); } +export function RemoveParticipantFromTournament(arg1, arg2) { + return window['go']['main']['App']['RemoveParticipantFromTournament'](arg1, arg2); +} + +export function SaveParticipant(arg1) { + return window['go']['main']['App']['SaveParticipant'](arg1); +} + export function SaveTournament(arg1) { return window['go']['main']['App']['SaveTournament'](arg1); } diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index a526dbe..2c01fcc 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -52,7 +52,7 @@ export namespace model { Title: string; GameID: number; Game: Game; - Size?: number; + Size: number; TournamentState: number; WinnierParticipantID: number; WinnierParticipant: Participant; @@ -105,7 +105,7 @@ export namespace model { // Go type: gorm DeletedAt: any; Name: string; - IsTemporary: boolean; + Size?: boolean; IsTeam: boolean; Tournaments: Tournament[]; @@ -120,7 +120,7 @@ export namespace model { this.UpdatedAt = this.convertValues(source["UpdatedAt"], null); this.DeletedAt = this.convertValues(source["DeletedAt"], null); this.Name = source["Name"]; - this.IsTemporary = source["IsTemporary"]; + this.Size = source["Size"]; this.IsTeam = source["IsTeam"]; this.Tournaments = this.convertValues(source["Tournaments"], Tournament); } diff --git a/model/model.go b/model/model.go index 6d87935..ea761ae 100644 --- a/model/model.go +++ b/model/model.go @@ -12,19 +12,18 @@ type Game struct { type Participant struct { gorm.Model Name string - IsTemporary bool // only for one tournament + IsTemporary bool `json:"Size,string,omitempty"` // only for one tournament IsTeam bool Tournaments []*Tournament `gorm:"many2many:partcipant_tournaments;"` } type Tournament struct { gorm.Model - Title string - GameID int - Game Game `gorm:"foreignKey:GameID"` - Size int `json:"Size,string,omitempty"` // number of prarticipants - TournamentState int - + Title string + GameID int + Game Game `gorm:"foreignKey:GameID"` + Size int // number of prarticipants + TournamentState int WinnierParticipantID int WinnierParticipant Participant `gorm:"foreignKey:WinnierParticipantID"` Participants []*Participant `gorm:"many2many:partcipant_tournaments;"` diff --git a/model/names.go b/model/names.go new file mode 100644 index 0000000..0defd68 --- /dev/null +++ b/model/names.go @@ -0,0 +1,65 @@ +package model + +import ( + "crypto/rand" + "math/big" +) + +var funnyNames = []string{ + "Captain Quirk", + "Giggle Muffin", + "Bubbles McFarty", + "Dapper Dingle", + "Wacky McWiggles", + "Sir Laughs-a-Lot", + "Chuckles the Chipmunk", + "Fuzzy Pickles", + "Snickerdoodle Sprout", + "Zany Zucchini", + "Professor Pudding", + "Bumbling Bumblebee", + "Cheeky Monkey", + "Silly Sausage", + "Wobble Bottom", + "Grinning Goblin", + "Fluffy Fiasco", + "Tickle Tortilla", + "Jolly Jester", + "Merry Marmalade", + "Wacky Wonka", + "Noodle Nugget", + "Bubblegum Bandit", + "Funky Ferret", + "Giggle Gopher", + "Happy Hiccup", + "Nifty Noodle", + "Dizzy Donut", + "Bouncy Biscuit", + "Frolic Fox", + "Whimsical Wombat", + "Peppy Pumpernickel", + "Loco Lobster", + "Sassy Sasquatch", + "Rambunctious Radish", + "Prankster Panda", + "Zippy Zebra", + "Giggling Giraffe", + "Funky Flamingo", + "Silly Sphinx", + "Guffawing Gopher", + "Cheerful Cucumber", + "Hapless Hedgehog", + "Jovial Jalapeño", + "Bubbly Banana", + "Quirky Quokka", + "Dandy Dodo", + "Laughing Llama", + "Zany Zephyr", +} + +func RandomName() string { + x := big.NewInt(int64(len(funnyNames) - 1)) + i, _ := rand.Int(rand.Reader, x) + + return funnyNames[i.Int64()] +} diff --git a/tournament.db b/tournament.db index 8e0276ff9f20b4864d6cc8e5bdc5095bc6a6e4dd..efeac48642ef13308a718515fbedf481cc4c72ea 100644 GIT binary patch literal 49152 zcmeI5U2Ggz6@X`Uc6Pn??q2_|9VhLimT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