github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/db/models.go (about) 1 package db 2 3 import ( 4 "time" 5 6 "github.com/ShoshinNikita/budget-manager/internal/pkg/money" 7 ) 8 9 // MonthOverview contains basic month data 10 type MonthOverview struct { 11 ID uint `json:"id"` 12 13 Year int `json:"year"` 14 Month time.Month `json:"month" swaggertype:"integer"` 15 16 // DailyBudget is a (TotalIncome - Cost of Monthly Payments) / Number of Days 17 DailyBudget money.Money `json:"daily_budget" swaggertype:"number"` 18 19 TotalIncome money.Money `json:"total_income" swaggertype:"number"` 20 // TotalSpend is a cost of all Monthly Payments and Spends 21 TotalSpend money.Money `json:"total_spend" swaggertype:"number"` 22 // Result is TotalIncome - TotalSpend 23 Result money.Money `json:"result" swaggertype:"number"` 24 } 25 26 // Month contains detailed month data: list of incomes, monthly payments and days 27 type Month struct { 28 MonthOverview 29 30 Incomes []Income `json:"incomes"` 31 MonthlyPayments []MonthlyPayment `json:"monthly_payments"` 32 Days []Day `json:"days"` 33 } 34 35 type Day struct { 36 ID uint `json:"id"` 37 38 Year int `json:"year"` 39 Month time.Month `json:"month" swaggertype:"integer"` 40 41 Day int `json:"day"` 42 // Saldo is DailyBudget - Cost of all Spends. It can be negative 43 Saldo money.Money `json:"saldo" swaggertype:"number"` 44 Spends []Spend `json:"spends"` 45 } 46 47 // Income contains information about incomes (salary, gifts and etc.) 48 type Income struct { 49 ID uint `json:"id"` 50 51 Year int `json:"year"` 52 Month time.Month `json:"month" swaggertype:"integer"` 53 54 Title string `json:"title"` 55 Notes string `json:"notes,omitempty"` 56 Income money.Money `json:"income" swaggertype:"number"` 57 } 58 59 // MonthlyPayment contains information about monthly payments (rent, Patreon and etc.) 60 type MonthlyPayment struct { 61 ID uint `json:"id"` 62 63 Year int `json:"year"` 64 Month time.Month `json:"month" swaggertype:"integer"` 65 66 Title string `json:"title"` 67 Type *SpendType `json:"type,omitempty"` 68 Notes string `json:"notes,omitempty"` 69 Cost money.Money `json:"cost" swaggertype:"number"` 70 } 71 72 // Spend contains information about spends 73 type Spend struct { 74 ID uint `json:"id"` 75 76 Year int `json:"year"` 77 Month time.Month `json:"month" swaggertype:"integer"` 78 Day int `json:"day"` 79 80 Title string `json:"title"` 81 Type *SpendType `json:"type,omitempty"` 82 Notes string `json:"notes,omitempty"` 83 Cost money.Money `json:"cost" swaggertype:"number"` 84 } 85 86 // SpendType contains information about spend type 87 type SpendType struct { 88 ID uint `json:"id"` 89 Name string `json:"name"` 90 ParentID uint `json:"parent_id"` 91 }