Add json tags to types

This commit is contained in:
2024-08-19 10:51:31 +02:00
parent de7c2cc82c
commit c17e25c358
5 changed files with 157 additions and 21 deletions

8
app.go
View File

@@ -57,3 +57,11 @@ func (a *App) SetPaid(billid int64, month time.Time) WailsPayment {
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{}
}

View File

@@ -3,6 +3,10 @@
import {main} from '../models';
import {time} from '../models';
export function EmptyBill():Promise<main.Bill>;
export function EmptyPayment():Promise<main.Payment>;
export function GetBills():Promise<main.WailsBills>;
export function GetPaymentsForMonth(arg1:time.Time):Promise<main.WailsPayments>;

View File

@@ -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']();
}

View File

@@ -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,7 +129,27 @@ 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;
}
}

View File

@@ -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"`
}
)