before svelte upgrade

This commit is contained in:
schreifuchs 2025-02-07 13:33:43 +01:00
parent 57cf5e617a
commit 0501c11c49
17 changed files with 396 additions and 88 deletions

32
app.go
View File

@ -2,17 +2,22 @@ package main
import ( import (
"context" "context"
"fmt" "gegio-ue1/model"
"gorm.io/gorm"
) )
// App struct // App struct
type App struct { type App struct {
ctx context.Context ctx context.Context
db *gorm.DB
} }
// NewApp creates a new App application struct // NewApp creates a new App application struct
func NewApp() *App { func NewApp(db *gorm.DB) *App {
return &App{} return &App{
db: db,
}
} }
// startup is called when the app starts. The context is saved // startup is called when the app starts. The context is saved
@ -21,7 +26,22 @@ func (a *App) startup(ctx context.Context) {
a.ctx = ctx a.ctx = ctx
} }
// Greet returns a greeting for the given name func (a *App) GetGames() (gs []model.Game, err error) {
func (a *App) Greet(name string) string { err = a.db.Find(&gs).Error
return fmt.Sprintf("Hello %s, It's show time!", name) return
}
func (a *App) GetTournaments() (ts []model.Tournament, err error) {
err = a.db.Preload("Game").Find(&ts).Error
return
}
func (a *App) GetTournament(id int) (t model.Tournament, err error) {
err = a.db.Preload("Game").First(&t, id).Error
return
}
func (a *App) SaveTournament(t model.Tournament) error {
err := a.db.Save(&t).Error
return err
} }

View File

@ -1,22 +1,26 @@
<script lang="ts"> <script lang="ts">
import "./app.css"; import "./app.css";
import { Navbar, NavBrand, DarkMode } from "flowbite-svelte"; import { Navbar, NavBrand, DarkMode } from "flowbite-svelte";
import { Router, Route } from "svelte-routing"; import { Router, Route, Link, navigate } from "svelte-routing";
import Home from "./routes/Home.svelte"; import Home from "./routes/Home.svelte";
import "./app.css"; import "./app.css";
import Tournament from "./routes/Tournament.svelte";
export let url = ""; export let url = "";
</script> </script>
<main class="flex-col h-screen items-center bg-gray-50 dark:bg-gray-800"> <main class="flex-col h-screen items-center bg-gray-50 dark:bg-gray-800">
<Navbar> <Navbar>
<NavBrand> <NavBrand on:click={() => navigate("", { replace: true })}>
<span>Wails</span> <span>Tournamenter</span>
</NavBrand> </NavBrand>
<DarkMode /> <DarkMode />
</Navbar> </Navbar>
<Router {url}> <Router bind:url>
<div> <div>
<Route path="/"><Home /></Route> <Route path="/"><Home /></Route>
<Route path="/tournament/:id" let:params
><Tournament id={params.id} /></Route
>
</div> </div>
</Router> </Router>
</main> </main>

View File

@ -1,14 +1,8 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte"; import { onMount } from "svelte";
import { GetTournaments } from "../../wailsjs/go/main/App";
import { model } from "../../wailsjs/go/models";
import { import {
GetThings,
DeleteThing,
NewThing,
} from "../../wailsjs/go/things/Service";
import { things } from "../../wailsjs/go/models";
import {
Label,
Input,
Button, Button,
Table, Table,
TableHead, TableHead,
@ -16,60 +10,58 @@
TableBody, TableBody,
TableBodyRow, TableBodyRow,
TableBodyCell, TableBodyCell,
Modal,
} from "flowbite-svelte"; } from "flowbite-svelte";
import TourCreator from "./TourCreator.svelte";
import { Link } from "svelte-routing";
let name: string; let thingsList: model.Tournament[] = [];
let thingsList: things.Thing[] = []; let newThing: boolean = false;
function update() { function update() {
GetThings().then((ts) => { GetTournaments().then((ts) => {
thingsList = ts; thingsList = ts;
}); });
} }
function submit(e: Event) {
e.preventDefault();
NewThing(name).then(update);
name = "";
}
function deleteEvent(id: number) {
DeleteThing(id).then(update);
}
onMount(update); onMount(update);
</script> </script>
<form class="max-w-96 m-5 grid-cols-1 gap-10" on:submit={submit}>
<div class="m-5">
<Label for="first_name" class="mb-2">First name</Label>
<Input type="text" placeholder="John" bind:value={name} required />
</div>
<div class="m-5">
<Button type="submit">Submit</Button>
</div>
</form>
<Table> <Table>
<TableHead> <TableHead>
<TableHeadCell>ID</TableHeadCell> <TableHeadCell>Title</TableHeadCell>
<TableHeadCell>Name</TableHeadCell> <TableHeadCell>Game</TableHeadCell>
<TableHeadCell>Winner</TableHeadCell>
<TableHeadCell>Delete</TableHeadCell>
</TableHead> </TableHead>
<TableBody> <TableBody>
{#each thingsList as t} {#each thingsList as t}
<TableBodyRow> <TableBodyRow>
<TableBodyCell> <TableBodyCell>
{t.ID} {t.Title}
</TableBodyCell>
<TableBodyCell>
{t.Game.Name}
</TableBodyCell>
<TableBodyCell>
{t.WinnierParticipant.Name}
</TableBodyCell> </TableBodyCell>
<TableBodyCell> <TableBodyCell>
{t.Name} <Link to={`/tournament/${t.ID}`}>Edit</Link>
</TableBodyCell>
<TableBodyCell>
<Button on:click={(_) => deleteEvent(t.ID)}>Delete</Button>
</TableBodyCell> </TableBodyCell>
</TableBodyRow> </TableBodyRow>
{/each} {/each}
</TableBody> </TableBody>
<div class="flex-row justify-evenly p-5">
<Button>View</Button>
<Button on:click={(_) => (newThing = true)}>New Tournament</Button>
</div>
<Modal bind:open={newThing}>
<TourCreator
onCreated={() => {
update();
newThing = false;
}}
/>
</Modal>
</Table> </Table>

View File

@ -0,0 +1,44 @@
<script lang="ts">
import { Button, Input, Label, Select } from "flowbite-svelte";
import { model } from "../../wailsjs/go/models";
import { GetGames, SaveTournament } from "../../wailsjs/go/main/App";
import { onMount } from "svelte";
let tournament = new model.Tournament();
let games: model.Game[] = [];
export let onCreated: (t: model.Tournament) => void = (_) => {};
function submit(e: Event) {
e.preventDefault();
SaveTournament(tournament).then(() => {
onCreated(tournament);
});
}
onMount(() => {
GetGames().then((gs) => {
games = gs;
});
});
</script>
<form on:submit={submit}>
<div>
<Label>Title</Label>
<Input type="text" bind:value={tournament.Title} />
</div>
<div>
e
<Label>Game</Label>
<Select
items={games.map((g) => {
return { value: g.ID, name: g.Name };
})}
bind:value={tournament.GameID}
/>
</div>
<div>
<Label>Size</Label>
<Input type="number" step="1" min="1" bind:value={tournament.Size} />
</div>
<Button type="submit">Save</Button>
</form>

View File

@ -0,0 +1,28 @@
<script lang="ts">
import { Link } from "svelte-routing";
import { GetTournament } from "../../wailsjs/go/main/App";
import { model } from "../../wailsjs/go/models";
import { onMount } from "svelte";
export let id: number | null = null;
let tournament: model.Tournament;
function update() {
GetTournament(id).then((t) => {
console.log(t);
tournament = t;
});
}
$: {
id = id;
update();
}
onMount(update);
</script>
<div>
<Link to="/" replace="true">Home</Link>
</div>
{#if tournament}
{tournament.Title}
{/if}

View File

@ -1,4 +1,11 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
import {model} from '../models';
export function Greet(arg1:string):Promise<string>; export function GetGames():Promise<Array<model.Game>>;
export function GetTournament(arg1:number):Promise<model.Tournament>;
export function GetTournaments():Promise<Array<model.Tournament>>;
export function SaveTournament(arg1:model.Tournament):Promise<void>;

View File

@ -2,6 +2,18 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
export function Greet(arg1) { export function GetGames() {
return window['go']['main']['App']['Greet'](arg1); return window['go']['main']['App']['GetGames']();
}
export function GetTournament(arg1) {
return window['go']['main']['App']['GetTournament'](arg1);
}
export function GetTournaments() {
return window['go']['main']['App']['GetTournaments']();
}
export function SaveTournament(arg1) {
return window['go']['main']['App']['SaveTournament'](arg1);
} }

View File

@ -1,18 +1,147 @@
export namespace things { export namespace model {
export class Thing { export class Game {
ID: number; ID: number;
// Go type: time
CreatedAt: any;
// Go type: time
UpdatedAt: any;
// Go type: gorm
DeletedAt: any;
Name: string; Name: string;
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
return new Thing(source); return new Game(source);
} }
constructor(source: any = {}) { constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source); if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"]; this.ID = source["ID"];
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
this.Name = source["Name"]; this.Name = source["Name"];
} }
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class Tournament {
ID: number;
// Go type: time
CreatedAt: any;
// Go type: time
UpdatedAt: any;
// Go type: gorm
DeletedAt: any;
Title: string;
GameID: number;
Game: Game;
Size?: number;
TournamentState: number;
WinnierParticipantID: number;
WinnierParticipant: Participant;
Participants: Participant[];
static createFrom(source: any = {}) {
return new Tournament(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
this.Title = source["Title"];
this.GameID = source["GameID"];
this.Game = this.convertValues(source["Game"], Game);
this.Size = source["Size"];
this.TournamentState = source["TournamentState"];
this.WinnierParticipantID = source["WinnierParticipantID"];
this.WinnierParticipant = this.convertValues(source["WinnierParticipant"], Participant);
this.Participants = this.convertValues(source["Participants"], Participant);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
}
export class Participant {
ID: number;
// Go type: time
CreatedAt: any;
// Go type: time
UpdatedAt: any;
// Go type: gorm
DeletedAt: any;
Name: string;
IsTemporary: boolean;
IsTeam: boolean;
Tournaments: Tournament[];
static createFrom(source: any = {}) {
return new Participant(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ID = source["ID"];
this.CreatedAt = this.convertValues(source["CreatedAt"], null);
this.UpdatedAt = this.convertValues(source["UpdatedAt"], null);
this.DeletedAt = this.convertValues(source["DeletedAt"], null);
this.Name = source["Name"];
this.IsTemporary = source["IsTemporary"];
this.IsTeam = source["IsTeam"];
this.Tournaments = this.convertValues(source["Tournaments"], Tournament);
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
if (!a) {
return a;
}
if (a.slice && a.map) {
return (a as any[]).map(elem => this.convertValues(elem, classs));
} else if ("object" === typeof a) {
if (asMap) {
for (const key of Object.keys(a)) {
a[key] = new classs(a[key]);
}
return a;
}
return new classs(a);
}
return a;
}
} }
} }

View File

@ -1,9 +0,0 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {things} from '../models';
export function DeleteThing(arg1:number):Promise<void>;
export function GetThings():Promise<Array<things.Thing>>;
export function NewThing(arg1:string):Promise<void>;

View File

@ -1,15 +0,0 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function DeleteThing(arg1) {
return window['go']['things']['Service']['DeleteThing'](arg1);
}
export function GetThings() {
return window['go']['things']['Service']['GetThings']();
}
export function NewThing(arg1) {
return window['go']['things']['Service']['NewThing'](arg1);
}

13
go.mod
View File

@ -1,8 +1,12 @@
module wails-svelte-tailwind-ts module gegio-ue1
go 1.23 go 1.23
require github.com/wailsapp/wails/v2 v2.9.2 require (
github.com/wailsapp/wails/v2 v2.9.2
gorm.io/driver/sqlite v1.5.7
gorm.io/gorm v1.25.12
)
require ( require (
github.com/bep/debounce v1.2.1 // indirect github.com/bep/debounce v1.2.1 // indirect
@ -10,6 +14,8 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect github.com/google/uuid v1.3.0 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect github.com/labstack/gommon v0.4.0 // indirect
github.com/leaanthony/go-ansi-parser v1.6.0 // indirect github.com/leaanthony/go-ansi-parser v1.6.0 // indirect
@ -18,6 +24,7 @@ require (
github.com/leaanthony/u v1.1.0 // indirect github.com/leaanthony/u v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect github.com/rivo/uniseg v0.4.4 // indirect
@ -31,7 +38,7 @@ require (
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.25.0 // indirect golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect golang.org/x/text v0.22.0 // indirect
) )
// replace github.com/wailsapp/wails/v2 v2.9.2 => /Users/u80864958/go/pkg/mod // replace github.com/wailsapp/wails/v2 v2.9.2 => /Users/u80864958/go/pkg/mod

14
go.sum
View File

@ -11,6 +11,10 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs= github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M= github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN2M=
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k= github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8= github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
@ -35,6 +39,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@ -84,11 +90,15 @@ golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=

View File

@ -2,7 +2,7 @@ package main
import ( import (
"embed" "embed"
"wails-svelte-tailwind-ts/things" "gegio-ue1/model"
"github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options"
@ -14,8 +14,8 @@ var assets embed.FS
func main() { func main() {
// Create an instance of the app structure // Create an instance of the app structure
app := NewApp() db := model.InitDB()
things := things.NewThingsService() app := NewApp(db)
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{
@ -29,7 +29,6 @@ func main() {
OnStartup: app.startup, OnStartup: app.startup,
Bind: []interface{}{ Bind: []interface{}{
app, app,
things,
}, },
}) })

36
model/init.go Normal file
View File

@ -0,0 +1,36 @@
package model
import (
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func InitDB() *gorm.DB {
db, err := gorm.Open(sqlite.Open("tournament.db"))
if err != nil {
log.Panic(err)
}
db.AutoMigrate(&Game{}, &Participant{}, &Tournament{}, &Match{})
db.Save(&Game{
Model: gorm.Model{
ID: 1,
},
Name: "CS:GO",
})
db.Save(&Game{
Model: gorm.Model{
ID: 2,
},
Name: "Overwatch",
})
db.Save(&Game{
Model: gorm.Model{
ID: 3,
},
Name: "Minecraft",
})
return db
}

44
model/model.go Normal file
View File

@ -0,0 +1,44 @@
package model
import (
"gorm.io/gorm"
)
type Game struct {
gorm.Model
Name string
}
type Participant struct {
gorm.Model
Name string
IsTemporary bool // 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
WinnierParticipantID int
WinnierParticipant Participant `gorm:"foreignKey:WinnierParticipantID"`
Participants []*Participant `gorm:"many2many:partcipant_tournaments;"`
}
type Match struct {
gorm.Model
TournamentID int
Stage int
Order int
Participant1ID int
Participant1 Participant `gorm:"foreignKey:Participant1ID"`
Participant2ID int
Participant2 Participant `gorm:"foreignKey:Participant2ID"`
WinnierParticipantID int
WinnierParticipant Participant `gorm:"foreignKey:WinnierParticipantID"`
}

0
things.db Normal file
View File

BIN
tournament.db Normal file

Binary file not shown.