Skip to content

Commit

Permalink
Merge pull request #26 from moneymanagerex/new_model_full
Browse files Browse the repository at this point in the history
new(#25): Models for Data and Full
  • Loading branch information
guanlisheng authored Sep 23, 2024
2 parents edb6202 + 2fd3df4 commit d5dc006
Show file tree
Hide file tree
Showing 44 changed files with 550 additions and 319 deletions.
61 changes: 42 additions & 19 deletions MMEX/Models/Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum AccountType: String, EnumCollateNoCase {
case shares = "Shares"
}

struct Account: ExportableEntity {
struct AccountData: ExportableEntity {
var id : Int64
var name : String
var type : AccountType
Expand All @@ -47,8 +47,6 @@ struct Account: ExportableEntity {
var paymentDueDate : String
var minimumPayment : Double

var currency: Currency?

init(
id : Int64 = 0,
name : String = "",
Expand All @@ -70,8 +68,7 @@ struct Account: ExportableEntity {
creditLimit : Double = 0.0,
interestRate : Double = 0.0,
paymentDueDate : String = "",
minimumPayment : Double = 0.0,
currency : Currency? = nil
minimumPayment : Double = 0.0
) {
self.id = id
self.name = name
Expand All @@ -94,19 +91,28 @@ struct Account: ExportableEntity {
self.interestRate = interestRate
self.paymentDueDate = paymentDueDate
self.minimumPayment = minimumPayment
self.currency = currency
}
}

extension Account: ModelProtocol {
extension AccountData: DataProtocol {
static let modelName = "Account"

func shortDesc() -> String {
"\(self.name)"
}
}

extension Account {
struct AccountFull: ExportableEntity, FullProtocol {
var data: AccountData
var currency: CurrencyData?
var id: Int64 { data.id }
init(data: AccountData = AccountData(), currency: CurrencyData? = nil) {
self.data = data
self.currency = currency
}
}

extension AccountData {
static let accountTypeToSFSymbol: [String: String] = [
"Cash" : "dollarsign.circle.fill",
"Checking" : "banknote.fill",
Expand All @@ -116,25 +122,42 @@ extension Account {
]
}

extension Account {
static let sampleData : [Account] = [
Account(
extension AccountData {
static let sampleData : [AccountData] = [
AccountData(
id: 1, name: "Account A", type: AccountType.cash,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 1,
currency: Currency.sampleData[0]
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 1
),
Account(
AccountData(
id: 2, name: "Account B", type: AccountType.cash,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2,
currency: Currency.sampleData[1]
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2
),
Account(
AccountData(
id: 3, name: "Investment Account", type: AccountType.investment,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2,
currency: Currency.sampleData[1]
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2
),
]
}

extension AccountFull {
static let sampleFull : [AccountFull] = [
AccountFull(data:AccountData(
id: 1, name: "Account A", type: AccountType.cash,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 1
), currency: CurrencyData.sampleData[0]),
AccountFull(data:AccountData(
id: 2, name: "Account B", type: AccountType.cash,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2
), currency: CurrencyData.sampleData[1]),
AccountFull(data:AccountData(
id: 3, name: "Investment Account", type: AccountType.investment,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2
), currency: CurrencyData.sampleData[1]),
]
}
17 changes: 11 additions & 6 deletions MMEX/Models/Asset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum AssetChangeMode: String, EnumCollateNoCase {
case linear = "Linear"
}

struct Asset: ExportableEntity {
struct AssetData: ExportableEntity {
var id : Int64
var type : AssetType
var status : AssetStatus
Expand Down Expand Up @@ -74,22 +74,27 @@ struct Asset: ExportableEntity {
}
}

extension Asset: ModelProtocol {
extension AssetData: DataProtocol {
static let modelName = "Asset"

func shortDesc() -> String {
"\(self.name), \(self.id)"
}
}

extension Asset {
static let sampleData: [Asset] = [
Asset(
struct AssetFull: FullProtocol {
var data: AssetData
var currency: CurrencyData?
}

extension AssetData {
static let sampleData: [AssetData] = [
AssetData(
id: 1, type: AssetType.property, status: AssetStatus.open, name: "House",
startDate: "2010-01-01", currencyId: 1, value: 100_000.0,
change: AssetChange.none, notes: "Address"
),
Asset(
AssetData(
id: 2, type: AssetType.automobile, status: AssetStatus.open, name: "Car",
startDate: "2020-01-01", currencyId: 1, value: 10_000.0,
change: AssetChange.depreciates,
Expand Down
20 changes: 12 additions & 8 deletions MMEX/Models/Category.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import SQLite

struct Category: ExportableEntity {
struct CategoryData: ExportableEntity {
var id : Int64
var name : String
var active : Bool
Expand All @@ -27,21 +27,25 @@ struct Category: ExportableEntity {
}
}

extension Category {
extension CategoryData {
var isRoot: Bool {
return parentId <= 0
}
}

extension Category: ModelProtocol {
extension CategoryData: DataProtocol {
static let modelName = "Category"

func shortDesc() -> String {
"\(self.name), \(self.id)"
}
}

extension Category {
struct CategoryFull: FullProtocol {
var data: CategoryData
}

extension CategoryData {
static let categoryToSFSymbol: [String: String] = [
"Unknown": "camera.metering.unknown",
"Auto": "car.fill",
Expand Down Expand Up @@ -101,9 +105,9 @@ extension Category {
]
}

extension Category {
static let sampleData: [Category] = [
Category(id: 1, name: "root cateogry", active: true, parentId: -1),
Category(id: 2, name: "non-root category", active: true, parentId: 1),
extension CategoryData {
static let sampleData: [CategoryData] = [
CategoryData(id: 1, name: "root cateogry", active: true, parentId: -1),
CategoryData(id: 2, name: "non-root category", active: true, parentId: 1),
]
}
20 changes: 12 additions & 8 deletions MMEX/Models/Currency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import SQLite

struct Currency: ExportableEntity {
struct CurrencyData: ExportableEntity {
var id : Int64
var name : String
var prefixSymbol : String
Expand Down Expand Up @@ -51,15 +51,19 @@ struct Currency: ExportableEntity {
}
}

extension Currency: ModelProtocol {
extension CurrencyData: DataProtocol {
static let modelName = "Currency"

func shortDesc() -> String {
"\(self.name)"
}
}

extension Currency {
struct CurrencyFull: FullProtocol {
var data: CurrencyData
}

extension CurrencyData {
/// A `NumberFormatter` configured specifically for the currency.
var formatter: NumberFormatter {
let nf = NumberFormatter()
Expand Down Expand Up @@ -90,19 +94,19 @@ extension Currency {
}
}

extension Currency {
static let sampleData: [Currency] = [
Currency(
extension CurrencyData {
static let sampleData: [CurrencyData] = [
CurrencyData(
id: 1, name: "US dollar", prefixSymbol: "$", suffixSymbol: "",
decimalPoint: ".", groupSeparator: ",", unitName: "Dollar", centName: "Cent",
scale: 100, baseConvRate: 1.0, symbol: "USD", type: "Fiat"
),
Currency(
CurrencyData(
id: 2, name: "Euro", prefixSymbol: "", suffixSymbol: "",
decimalPoint: ".", groupSeparator: " ", unitName: "", centName: "",
scale: 100, baseConvRate: 1.0, symbol: "EUR", type: "Fiat"
),
Currency(
CurrencyData(
id: 3, name: "British pound", prefixSymbol: "£", suffixSymbol: "",
decimalPoint: ".", groupSeparator: " ", unitName: "Pound", centName: "Pence",
scale: 100, baseConvRate: 1.0, symbol: "GBP", type: "Fiat"
Expand Down
14 changes: 9 additions & 5 deletions MMEX/Models/Infotable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum InfoKey: String {
var id: String { return rawValue }
}

struct Infotable: ExportableEntity {
struct InfotableData: ExportableEntity {
var id : Int64
var name : String
var value : String
Expand Down Expand Up @@ -51,16 +51,20 @@ struct Infotable: ExportableEntity {
}
}

extension Infotable: ModelProtocol {
extension InfotableData: DataProtocol {
static let modelName = "Infotable"

func shortDesc() -> String {
"\(self.name)"
}
}

extension Infotable {
static let sampleData: [Infotable] = [
Infotable(id: 1, name: "DATAVERSION", value: "3"),
struct InfotableFull: FullProtocol {
var data: InfotableData
}

extension InfotableData {
static let sampleData: [InfotableData] = [
InfotableData(id: 1, name: "DATAVERSION", value: "3"),
]
}
17 changes: 11 additions & 6 deletions MMEX/Models/Payee.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import SQLite

struct Payee: ExportableEntity {
struct PayeeData: ExportableEntity {
var id : Int64
var name : String
var categoryId : Int64
Expand Down Expand Up @@ -41,21 +41,26 @@ struct Payee: ExportableEntity {
}
}

extension Payee: ModelProtocol {
extension PayeeData: DataProtocol {
static let modelName = "Payee"

func shortDesc() -> String {
"\(self.name)"
}
}

extension Payee {
static let sampleData: [Payee] = [
Payee(
struct PayeeFull: FullProtocol {
var data: PayeeData
var category: CategoryFull?
}

extension PayeeData {
static let sampleData: [PayeeData] = [
PayeeData(
id: 1, name: "Payee A", categoryId: 1, number: "123456",
website: "www.payeeA.com", notes: "Frequent payee"
),
Payee(
PayeeData(
id: 2, name: "Payee B", categoryId: 2, number: "654321",
website: "www.payeeB.com", notes: "Rare payee", active: false
),
Expand Down
26 changes: 19 additions & 7 deletions MMEX/Models/Scheduled.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum RepeatType: Int, CaseIterable, Identifiable, Codable {
var name: String { Self.names[self.rawValue] }
}

struct Scheduled: ExportableEntity {
struct ScheduledData: ExportableEntity {
var id : Int64
var accountId : Int64
var toAccountId : Int64
Expand Down Expand Up @@ -125,27 +125,39 @@ struct Scheduled: ExportableEntity {
}
}

extension Scheduled: ModelProtocol {
extension ScheduledData: DataProtocol {
static let modelName = "Scheduled"

func shortDesc() -> String {
"\(self.id)"
}
}

extension Scheduled {
static let sampleData : [Scheduled] = [
Scheduled(
struct ScheduledFull: FullProtocol {
var data: ScheduledData
var accountName : String?
var accountCurrency : CurrencyData?
var toAccountName : String?
var toAccountCurrency : String?
var categoryName : String?
var payeeName : String?
//var tags : [TagData]
//var fields : [(FieldData, String?)]
}

extension ScheduledData {
static let sampleData : [ScheduledData] = [
ScheduledData(
id: 1, accountId: 1, payeeId: 1, transCode: Transcode.withdrawal,
transAmount: 10.01, status: TransactionStatus.none, categId: 1,
transDate: Date().ISO8601Format()
),
Scheduled(
ScheduledData(
id: 2, accountId: 2, payeeId: 2, transCode: Transcode.deposit,
transAmount: 20.02, status: TransactionStatus.none, categId: 1,
transDate: Date().ISO8601Format()
),
Scheduled(
ScheduledData(
id: 3, accountId: 3, payeeId: 3, transCode: Transcode.transfer,
transAmount: 30.03, status: TransactionStatus.none, categId: 1,
transDate: Date().ISO8601Format()
Expand Down
Loading

0 comments on commit d5dc006

Please sign in to comment.