From 5bedea53121fd1f2ec841312f69ad79bd61996b8 Mon Sep 17 00:00:00 2001 From: schreifuchs Date: Fri, 7 Mar 2025 11:51:21 +0100 Subject: [PATCH] management of library --- .timer.toml | 3 + README.md | 10 +- app.go | 101 +++++++++- frontend/.timer.toml | 3 + frontend/src/App.svelte | 30 ++- frontend/src/components/AuthorEditor.svelte | 24 +++ frontend/src/components/BookEditor.svelte | 73 +++++++ frontend/src/components/ClientEditor.svelte | 30 +++ frontend/src/components/LendingEditor.svelte | 73 +++++++ frontend/src/components/TimeInput.svelte | 2 +- frontend/src/routes/AuthorEditor.svelte | 24 +++ frontend/src/routes/Books.svelte | 118 ++++++++++++ frontend/src/routes/Clients.svelte | 107 +++++++++++ frontend/src/routes/Home.svelte | 74 -------- frontend/src/routes/Lendings.svelte | 188 +++++++++++++++++++ frontend/wailsjs/go/main/App.d.ts | 35 ++++ frontend/wailsjs/go/main/App.js | 68 +++++++ frontend/wailsjs/go/models.ts | 181 ++++++++++++++++-- frontend/wailsjs/go/things/Service.d.ts | 15 -- frontend/wailsjs/go/things/Service.js | 27 --- go.mod | 2 +- main.go | 9 +- model/model.go | 43 ++++- things/resource.go | 54 ------ utils.go | 8 + wails.json | 4 +- 26 files changed, 1078 insertions(+), 228 deletions(-) create mode 100644 .timer.toml create mode 100644 frontend/.timer.toml create mode 100644 frontend/src/components/AuthorEditor.svelte create mode 100644 frontend/src/components/BookEditor.svelte create mode 100644 frontend/src/components/ClientEditor.svelte create mode 100644 frontend/src/components/LendingEditor.svelte create mode 100644 frontend/src/routes/AuthorEditor.svelte create mode 100644 frontend/src/routes/Books.svelte create mode 100644 frontend/src/routes/Clients.svelte delete mode 100644 frontend/src/routes/Home.svelte create mode 100644 frontend/src/routes/Lendings.svelte delete mode 100755 frontend/wailsjs/go/things/Service.d.ts delete mode 100755 frontend/wailsjs/go/things/Service.js delete mode 100644 things/resource.go create mode 100644 utils.go diff --git a/.timer.toml b/.timer.toml new file mode 100644 index 0000000..9dd5e6b --- /dev/null +++ b/.timer.toml @@ -0,0 +1,3 @@ +## dates and their corresponding seconds been here :) +[25-03-07] +schreifuchs_at_archibald = 407 diff --git a/README.md b/README.md index fabc1d2..3f7f45d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ -# wails template -This is my wails-template i am using for the *ICT-Regiomeisterschaften 2025*. -It uses vanilla svelte with vite in the Frontend. For styling i use Flowbyte and TailwindCSS. I have setup a pipeline to build windows and linux binaries. For windows i have a working installer. - -Feel free to use this template on your own. To set it up just run ```setup.sh```. If you're not using gitea you will have to rename the ```.gitea``` folder to ```.github```, to use the pipelines. - -Enjoy :) +# Library Manager +übung für ICT-Regios 2025 +zeit: 4h 15min ## Links diff --git a/app.go b/app.go index 3df4052..a9a7851 100644 --- a/app.go +++ b/app.go @@ -3,19 +3,22 @@ package main import ( "context" "fmt" + "library-manager/model" "github.com/gen2brain/beeep" + "gorm.io/gorm" ) // App struct type App struct { ctx context.Context + db *gorm.DB } // 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 @@ -33,3 +36,97 @@ func (a *App) startup(ctx context.Context) { func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) } + +// Authors CRIUD +func (a *App) SaveAuthor(au *model.Author) { + a.db.Save(au) +} + +func (a *App) DeleteAuthor(au *model.Author) { + a.db.Delete(au) +} + +func (a *App) GetAuthors() (authors []model.Author) { + a.db.Find(&authors) + return +} + +func (a *App) SaveBook(au *model.Book) { + a.db.Save(au) +} + +func (a *App) DeleteBook(au *model.Book) { + a.db.Delete(au) +} + +func (a *App) GetBooks() (authors []model.Book) { + a.db.Preload("Author").Preload("Lendings").Find(&authors) + return +} +func (a *App) GetAvailableBooks() (books []model.Book) { + var bs []model.Book + a.db.Preload("Author").Preload("Lendings").Find(&bs) + books = make([]model.Book, 0, len(bs)) + + for _, b := range bs { + if !a.BookLended(b.ID) { + books = append(books, b) + } + } + + return +} + +func (a *App) BookLended(bId uint) bool { + var lendings []model.Lending + a.db.Where("book_id = ?", bId).Where("returned = FALSE").Find(&lendings) + + fmt.Println(lendings) + + return len(lendings) != 0 +} + +func (a *App) SaveClient(au *model.Client) { + a.db.Save(au) +} + +func (a *App) DeleteClient(au *model.Client) { + a.db.Delete(au) +} + +func (a *App) GetClients() (authors []model.Client) { + a.db.Preload("Lendings").Find(&authors) + return +} + +func (a *App) SaveLending(au *model.Lending) string { + if a.BookLended(Greater(au.BookID, au.Book.ID)) { + return "Book is not available" + } + a.db.Save(au) + + return "" +} + +func (a *App) ReturnLending(l *model.Lending) { + l.Returned = true + a.db.Save(l) + +} + +func (a *App) DeleteLending(au *model.Lending) { + a.db.Delete(au) +} + +func (a *App) GetLendings() (lendings []model.Lending) { + a.db.Preload("Client").Preload("Book").Where("returned = FALSE").Find(&lendings) + return +} +func (a *App) GetReturnedLendings() (lendings []model.Lending) { + a.db.Preload("Client").Preload("Book").Where("returned = TRUE").Find(&lendings) + return +} +func (a *App) GetAllLendings() (lendings []model.Lending) { + a.db.Preload("Client").Preload("Book").Find(&lendings) + return +} diff --git a/frontend/.timer.toml b/frontend/.timer.toml new file mode 100644 index 0000000..a1c3b28 --- /dev/null +++ b/frontend/.timer.toml @@ -0,0 +1,3 @@ +## dates and their corresponding seconds been here :) +[25-03-07] +schreifuchs_at_archibald = 15333 diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 090cc5d..b21cd5c 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -1,25 +1,37 @@
- +
+ + Clients + Books +
- + + + + + + +
diff --git a/frontend/src/components/AuthorEditor.svelte b/frontend/src/components/AuthorEditor.svelte new file mode 100644 index 0000000..1177d3b --- /dev/null +++ b/frontend/src/components/AuthorEditor.svelte @@ -0,0 +1,24 @@ + + +
+
+ + +
+
+ +
+
diff --git a/frontend/src/components/BookEditor.svelte b/frontend/src/components/BookEditor.svelte new file mode 100644 index 0000000..d3e1154 --- /dev/null +++ b/frontend/src/components/BookEditor.svelte @@ -0,0 +1,73 @@ + + + + { + SaveAuthor(a).then(update); + modal = false; + }} + /> + + +
+
+ + +
+ +
+ + +
+
+ +
+ +
+ +
+ + +
+ +
+ +
+ diff --git a/frontend/src/components/LendingEditor.svelte b/frontend/src/components/LendingEditor.svelte new file mode 100644 index 0000000..9ac2fbb --- /dev/null +++ b/frontend/src/components/LendingEditor.svelte @@ -0,0 +1,73 @@ + + +
+
+ + { + return { value: c.ID, name: `${c.Email} ~ ${c.Name}` }; + })} + bind:value={lending.ClientID} + /> +
+
+ + +
+
+ Returned +
+
+ +
+
diff --git a/frontend/src/components/TimeInput.svelte b/frontend/src/components/TimeInput.svelte index f3fc2e5..0736c54 100644 --- a/frontend/src/components/TimeInput.svelte +++ b/frontend/src/components/TimeInput.svelte @@ -1,7 +1,7 @@ + +
+
+ + +
+
+ +
+
diff --git a/frontend/src/routes/Books.svelte b/frontend/src/routes/Books.svelte new file mode 100644 index 0000000..4b81896 --- /dev/null +++ b/frontend/src/routes/Books.svelte @@ -0,0 +1,118 @@ + + +{#if book} + + { + SaveBook(b).then(update); + modal = false; + book = null; + }} + /> + +{:else if lending} + + { + SaveLending(l).then(update); + modal = false; + lending = null; + }} + /> + +{/if} + + + + Title + Author + ISBN + Status + + + + + + {#each books as b} + + {b.Title} + {b.Author.Name} + {b.ISBN} + {#await BookLended(b.ID)} + + {:then lended} + {#if lended} + Lended + {:else} + Available + {/if} + {/await} + + + {#await BookLended(b.ID) then lended} + {#if !lended} + + {/if} + {/await} + + + + {/each} + +
diff --git a/frontend/src/routes/Clients.svelte b/frontend/src/routes/Clients.svelte new file mode 100644 index 0000000..b68611c --- /dev/null +++ b/frontend/src/routes/Clients.svelte @@ -0,0 +1,107 @@ + + +{#if client} + + { + SaveClient(c).then(update); + modal = false; + }} + /> + {:else if lending} + + { + SaveLending(l).then(update); + modal = false; + lending = null; + }} + /> + +{/if} + + + Name + Email + Active Lendings + Overdue Lendings + + + + + {#each clients as c} + + {c.Name} + {c.Email} + {c.Lendings.filter((l) => { + return !l.Returned; + }).length} + + + {c.Lendings.filter((l) => { + return new Date(l.DueDate).getTime() > Date.now(); + }).length} + + + + + + + + {/each} + +
diff --git a/frontend/src/routes/Home.svelte b/frontend/src/routes/Home.svelte deleted file mode 100644 index e0c3d9d..0000000 --- a/frontend/src/routes/Home.svelte +++ /dev/null @@ -1,74 +0,0 @@ - - -
-
- - -
-
- -
-
- - - ID - Name - Delete - - - {#each thingsList as t} - - - {t.ID} - - - - {t.Name} - - - - - - {/each} - -
diff --git a/frontend/src/routes/Lendings.svelte b/frontend/src/routes/Lendings.svelte new file mode 100644 index 0000000..aa7194e --- /dev/null +++ b/frontend/src/routes/Lendings.svelte @@ -0,0 +1,188 @@ + + + + { + SaveLending(l).then(update); + modal = false; + lending = null; + }} + /> + + +
+ Lendings + +
+ +
+ Overdue + {#if lendings.filter((l) => { + return new Date(l.DueDate).getTime() < Date.now(); + }).length == 0} +

No Entries

+ {/if} + + {#each lendings.filter((l) => { + return new Date(l.DueDate).getTime() < Date.now(); + }) as l} + +

+ The book "{l.Book.Title}" (ISBN: {l.Book.ISBN}) is lended to {l.Client + .Name} () +

+
+ + +
+
+ {/each} +
+
+
+ Active + {#if lendings.filter((l) => { + return new Date(l.DueDate).getTime() > Date.now(); + }).length == 0} +

No Entries

+ {/if} + + + {#each lendings.filter((l) => { + return new Date(l.DueDate).getTime() > Date.now(); + }) as l} + +

+ The book "{l.Book.Title}" (ISBN: {l.Book.ISBN}) is lended to {l.Client + .Name} () +

+
+ + +
+
+ {/each} +
+
+
+ Returned + {#if returnedLendings.length == 0} +

No Entries

+ {/if} + + {#each returnedLendings as l} + +

+ The book "{l.Book.Title}" (ISBN: {l.Book.ISBN}) was lended to {l + .Client.Name} () +

+
+ +
+
+ {/each} +
+
diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 02a3bb9..d80a006 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -1,4 +1,39 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +import {model} from '../models'; + +export function BookLended(arg1:number):Promise; + +export function DeleteAuthor(arg1:model.Author):Promise; + +export function DeleteBook(arg1:model.Book):Promise; + +export function DeleteClient(arg1:model.Client):Promise; + +export function DeleteLending(arg1:model.Lending):Promise; + +export function GetAllLendings():Promise>; + +export function GetAuthors():Promise>; + +export function GetAvailableBooks():Promise>; + +export function GetBooks():Promise>; + +export function GetClients():Promise>; + +export function GetLendings():Promise>; + +export function GetReturnedLendings():Promise>; export function Greet(arg1:string):Promise; + +export function ReturnLending(arg1:model.Lending):Promise; + +export function SaveAuthor(arg1:model.Author):Promise; + +export function SaveBook(arg1:model.Book):Promise; + +export function SaveClient(arg1:model.Client):Promise; + +export function SaveLending(arg1:model.Lending):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index c71ae77..eb081e8 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -2,6 +2,74 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +export function BookLended(arg1) { + return window['go']['main']['App']['BookLended'](arg1); +} + +export function DeleteAuthor(arg1) { + return window['go']['main']['App']['DeleteAuthor'](arg1); +} + +export function DeleteBook(arg1) { + return window['go']['main']['App']['DeleteBook'](arg1); +} + +export function DeleteClient(arg1) { + return window['go']['main']['App']['DeleteClient'](arg1); +} + +export function DeleteLending(arg1) { + return window['go']['main']['App']['DeleteLending'](arg1); +} + +export function GetAllLendings() { + return window['go']['main']['App']['GetAllLendings'](); +} + +export function GetAuthors() { + return window['go']['main']['App']['GetAuthors'](); +} + +export function GetAvailableBooks() { + return window['go']['main']['App']['GetAvailableBooks'](); +} + +export function GetBooks() { + return window['go']['main']['App']['GetBooks'](); +} + +export function GetClients() { + return window['go']['main']['App']['GetClients'](); +} + +export function GetLendings() { + return window['go']['main']['App']['GetLendings'](); +} + +export function GetReturnedLendings() { + return window['go']['main']['App']['GetReturnedLendings'](); +} + export function Greet(arg1) { return window['go']['main']['App']['Greet'](arg1); } + +export function ReturnLending(arg1) { + return window['go']['main']['App']['ReturnLending'](arg1); +} + +export function SaveAuthor(arg1) { + return window['go']['main']['App']['SaveAuthor'](arg1); +} + +export function SaveBook(arg1) { + return window['go']['main']['App']['SaveBook'](arg1); +} + +export function SaveClient(arg1) { + return window['go']['main']['App']['SaveClient'](arg1); +} + +export function SaveLending(arg1) { + return window['go']['main']['App']['SaveLending'](arg1); +} diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index 9c6ec9c..8d691fa 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -1,35 +1,30 @@ export namespace model { - export class SubThing { + export class Client { ID: number; - ThingID: number; + // Go type: time + CreatedAt: any; + // Go type: time + UpdatedAt: any; + // Go type: gorm + DeletedAt: any; Name: string; + Email: string; + Lendings: Lending[]; static createFrom(source: any = {}) { - return new SubThing(source); + return new Client(source); } constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); this.ID = source["ID"]; - this.ThingID = source["ThingID"]; + 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"]; - } - } - export class Thing { - ID: number; - Name: string; - Subthings: SubThing[]; - - static createFrom(source: any = {}) { - return new Thing(source); - } - - constructor(source: any = {}) { - if ('string' === typeof source) source = JSON.parse(source); - this.ID = source["ID"]; - this.Name = source["Name"]; - this.Subthings = this.convertValues(source["Subthings"], SubThing); + this.Email = source["Email"]; + this.Lendings = this.convertValues(source["Lendings"], Lending); } convertValues(a: any, classs: any, asMap: boolean = false): any { @@ -50,6 +45,152 @@ export namespace model { return a; } } + export class Lending { + ID: number; + // Go type: time + CreatedAt: any; + // Go type: time + UpdatedAt: any; + // Go type: gorm + DeletedAt: any; + // Go type: time + DueDate: any; + Returned: boolean; + ClientID: number; + Client: Client; + BookID: number; + Book: Book; + + static createFrom(source: any = {}) { + return new Lending(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.DueDate = this.convertValues(source["DueDate"], null); + this.Returned = source["Returned"]; + this.ClientID = source["ClientID"]; + this.Client = this.convertValues(source["Client"], Client); + this.BookID = source["BookID"]; + this.Book = this.convertValues(source["Book"], Book); + } + + 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 Book { + ID: number; + // Go type: time + CreatedAt: any; + // Go type: time + UpdatedAt: any; + // Go type: gorm + DeletedAt: any; + Title: string; + ISBN: string; + AuthorID: number; + Author: Author; + Lendings: Lending[]; + + static createFrom(source: any = {}) { + return new Book(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.ISBN = source["ISBN"]; + this.AuthorID = source["AuthorID"]; + this.Author = this.convertValues(source["Author"], Author); + this.Lendings = this.convertValues(source["Lendings"], Lending); + } + + 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 Author { + ID: number; + // Go type: time + CreatedAt: any; + // Go type: time + UpdatedAt: any; + // Go type: gorm + DeletedAt: any; + Name: string; + Books: Book[]; + + static createFrom(source: any = {}) { + return new Author(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.Books = this.convertValues(source["Books"], Book); + } + + 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; + } + } + + } diff --git a/frontend/wailsjs/go/things/Service.d.ts b/frontend/wailsjs/go/things/Service.d.ts deleted file mode 100755 index c7a67f1..0000000 --- a/frontend/wailsjs/go/things/Service.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT -import {model} from '../models'; - -export function AddSubThing(arg1:number,arg2:string):Promise; - -export function DeleteSubThing(arg1:number):Promise; - -export function DeleteThing(arg1:number):Promise; - -export function GetSubThings(arg1:number):Promise>; - -export function GetThings():Promise>; - -export function NewThing(arg1:string):Promise; diff --git a/frontend/wailsjs/go/things/Service.js b/frontend/wailsjs/go/things/Service.js deleted file mode 100755 index 5c167cb..0000000 --- a/frontend/wailsjs/go/things/Service.js +++ /dev/null @@ -1,27 +0,0 @@ -// @ts-check -// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL -// This file is automatically generated. DO NOT EDIT - -export function AddSubThing(arg1, arg2) { - return window['go']['things']['Service']['AddSubThing'](arg1, arg2); -} - -export function DeleteSubThing(arg1) { - return window['go']['things']['Service']['DeleteSubThing'](arg1); -} - -export function DeleteThing(arg1) { - return window['go']['things']['Service']['DeleteThing'](arg1); -} - -export function GetSubThings(arg1) { - return window['go']['things']['Service']['GetSubThings'](arg1); -} - -export function GetThings() { - return window['go']['things']['Service']['GetThings'](); -} - -export function NewThing(arg1) { - return window['go']['things']['Service']['NewThing'](arg1); -} diff --git a/go.mod b/go.mod index 2d47b1d..9f20f9d 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module wails-template +module library-manager go 1.24.0 diff --git a/main.go b/main.go index d937fb4..642eae1 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,7 @@ package main import ( "embed" - "wails-template/model" - "wails-template/things" + "library-manager/model" "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" @@ -15,13 +14,12 @@ var assets embed.FS func main() { // Create an instance of the app structure - app := NewApp() db := model.InitDB() - things := &things.Service{DB: db} + app := NewApp(db) // Create application with options err := wails.Run(&options.App{ - Title: "wails-template", + Title: "library-manager", Width: 1024, Height: 768, AssetServer: &assetserver.Options{ @@ -31,7 +29,6 @@ func main() { OnStartup: app.startup, Bind: []interface{}{ app, - things, }, }) diff --git a/model/model.go b/model/model.go index b80ca50..5c16c72 100644 --- a/model/model.go +++ b/model/model.go @@ -4,21 +4,44 @@ import ( "log" "os" "path" + "time" "gorm.io/driver/sqlite" "gorm.io/gorm" ) -type Thing struct { - ID int - Name string - Subthings []SubThing +type Author struct { + gorm.Model + Name string + Books []Book } -type SubThing struct { - ID int - ThingID int - Name string +type Book struct { + gorm.Model + Title string + ISBN string + AuthorID uint + Author Author `gorm:"foreignKey:AuthorID"` + Lendings []Lending `gorm:"foreignKey:BookID"` +} + +type Client struct { + gorm.Model + Name string + Email string + Lendings []Lending `gorm:"foreignKey:ClientID"` +} + +type Lending struct { + gorm.Model + DueDate time.Time + Returned bool + + ClientID uint + Client Client `gorm:"foreignKey:ClientID"` + + BookID uint + Book Book `gorm:"foreignKey:BookID"` } func InitDB() *gorm.DB { @@ -26,10 +49,10 @@ func InitDB() *gorm.DB { if err != nil { panic(err) } - db, err := gorm.Open(sqlite.Open(path.Join(home, "things.db"))) + db, err := gorm.Open(sqlite.Open(path.Join(home, "library.db"))) if err != nil { log.Panic(err) } - db.AutoMigrate(&Thing{}, &SubThing{}) + db.AutoMigrate(&Author{}, &Book{}, &Client{}, &Lending{}) return db } diff --git a/things/resource.go b/things/resource.go deleted file mode 100644 index 8afaece..0000000 --- a/things/resource.go +++ /dev/null @@ -1,54 +0,0 @@ -package things - -import ( - "log" - "wails-template/model" - - "gorm.io/gorm" -) - -type Service struct { - DB *gorm.DB -} - -func (s *Service) NewThing(name string) { - if err := s.DB.Save(&model.Thing{Name: name}).Error; err != nil { - log.Fatal(err) - } - - print(name) -} - -func (s *Service) GetThings() (things []model.Thing) { - if err := s.DB.Find(&things).Error; err != nil { - log.Fatal(err) - } - return things -} - -func (s *Service) DeleteThing(id int) { - if err := s.DB.Delete(model.Thing{}, id).Error; err != nil { - log.Fatal(err) - } -} - -func (s *Service) GetSubThings(thingID int) (subthings []model.SubThing) { - if err := s.DB.Where("thing_id = ?", thingID).Find(&subthings).Error; err != nil { - log.Fatal(err) - } - return -} -func (s *Service) AddSubThing(thingID int, name string) { - if err := s.DB.Save(&model.SubThing{ - ThingID: thingID, - Name: name, - }).Error; err != nil { - log.Fatal(err) - } -} - -func (s *Service) DeleteSubThing(id int) { - if err := s.DB.Delete(model.SubThing{}, id).Error; err != nil { - log.Fatal(err) - } -} diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..5b4cbe5 --- /dev/null +++ b/utils.go @@ -0,0 +1,8 @@ +package main + +func Greater(a, b uint) uint { + if a > b { + return a + } + return b +} diff --git a/wails.json b/wails.json index ce57698..e9cf460 100644 --- a/wails.json +++ b/wails.json @@ -1,7 +1,7 @@ { "$schema": "https://wails.io/schemas/config.v2.json", - "name": "wails-template", - "outputfilename": "wails-template", + "name": "library-manager", + "outputfilename": "library-manager", "frontend:install": "pnpm install", "frontend:build": "pnpm run build", "frontend:dev:watcher": "pnpm run dev",