Files
bill-manager/app.go

72 lines
1.4 KiB
Go

package main
import (
"context"
"time"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) Close() {
runtime.Quit(a.ctx)
}
func (a *App) GetBills() WailsBills {
res := WailsBills{}
bills, err := service.GetAllBills()
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = bills
return res
}
func (a *App) GetPaymentsForMonth(month time.Time) WailsPayments {
res := WailsPayments{}
payments, err := service.GetPaymentsForDate(month)
if err != nil {
res.Success = false
res.Error = err.Error()
return res
}
res.Success = true
res.Data = payments
return res
}
func (a *App) SetPaid(billid int64, month time.Time) WailsPayment {
res := WailsPayment{}
payment, err := service.MarkPaid(billid, month, time.Now())
if err!= nil {
res.Success = false
res.Error = err.Error()
return res
}
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{}
}