diff --git a/app.go b/app.go index 4b43295..e11596c 100644 --- a/app.go +++ b/app.go @@ -56,4 +56,12 @@ func (a *App) SetPaid(billid int64, month time.Time) WailsPayment { res.Success = true res.Data = payment return res +} + +// These exist only so that wails generates models for Bill and Payment +func (a *App) EmptyBill() Bill { + return Bill{} +} +func (a *App) EmptyPayment() Payment { + return Payment{} } \ No newline at end of file diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index e8c8b18..415ec2c 100644 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -3,6 +3,10 @@ import {main} from '../models'; import {time} from '../models'; +export function EmptyBill():Promise; + +export function EmptyPayment():Promise; + export function GetBills():Promise; export function GetPaymentsForMonth(arg1:time.Time):Promise; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index a48e285..8f37e52 100644 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -2,6 +2,14 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +export function EmptyBill() { + return window['go']['main']['App']['EmptyBill'](); +} + +export function EmptyPayment() { + return window['go']['main']['App']['EmptyPayment'](); +} + export function GetBills() { return window['go']['main']['App']['GetBills'](); } diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index 5c21f51..f5e1bff 100644 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -1,7 +1,59 @@ export namespace main { - export class WailsBills { + export class Bill { + id: number; + name: string; + static createFrom(source: any = {}) { + return new Bill(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.id = source["id"]; + this.name = source["name"]; + } + } + export class Payment { + id: number; + billId: number; + monthFor: time.Time; + paymentDate: time.Time; + + static createFrom(source: any = {}) { + return new Payment(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.id = source["id"]; + this.billId = source["billId"]; + this.monthFor = this.convertValues(source["monthFor"], time.Time); + this.paymentDate = this.convertValues(source["paymentDate"], time.Time); + } + + 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 WailsBills { + data: Bill[]; + success: boolean; + error: string; static createFrom(source: any = {}) { return new WailsBills(source); @@ -9,11 +61,33 @@ export namespace main { constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); - + this.data = this.convertValues(source["data"], Bill); + this.success = source["success"]; + this.error = source["error"]; } + + 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 WailsPayment { - + data: Payment; + success: boolean; + error: string; static createFrom(source: any = {}) { return new WailsPayment(source); @@ -21,11 +95,33 @@ export namespace main { constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); - + this.data = this.convertValues(source["data"], Payment); + this.success = source["success"]; + this.error = source["error"]; } + + 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 WailsPayments { - + data: Payment[]; + success: boolean; + error: string; static createFrom(source: any = {}) { return new WailsPayments(source); @@ -33,8 +129,28 @@ export namespace main { constructor(source: any = {}) { if ('string' === typeof source) source = JSON.parse(source); - + this.data = this.convertValues(source["data"], Payment); + this.success = source["success"]; + this.error = source["error"]; } + + 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/types.go b/types.go index 8b9d8d1..4f183ee 100644 --- a/types.go +++ b/types.go @@ -4,29 +4,29 @@ import "time" type ( Bill struct { - Id int64 - Name string + Id int64 `json:"id"` + Name string `json:"name"` } Payment struct { - Id int64 - BillId int64 - MonthFor time.Time - PaymentDate time.Time + Id int64 `json:"id"` + BillId int64 `json:"billId"` + MonthFor time.Time `json:"monthFor" time_format:"2006-01-02"` + PaymentDate time.Time `json:"paymentDate" time_format:"2006-01-02T15:04:05"` } WailsBills struct { - Data []Bill - Success bool - Error string + Data []Bill `json:"data"` + Success bool `json:"success"` + Error string `json:"error"` } WailsPayments struct { - Data []Payment - Success bool - Error string + Data []Payment `json:"data"` + Success bool `json:"success"` + Error string `json:"error"` } WailsPayment struct { - Data Payment - Success bool - Error string + Data Payment `json:"data"` + Success bool `json:"success"` + Error string `json:"error"` } )