Skip to content

Commit

Permalink
refine sampleData and retrive user_version / schema version
Browse files Browse the repository at this point in the history
  • Loading branch information
guanlisheng committed Sep 25, 2024
1 parent 050a7b1 commit a167302
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
7 changes: 7 additions & 0 deletions MMEX/DatabaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class DataManager {
}
}

func getSchemaVersion() -> Int32? {
if let db {
return db.userVersion
}
return nil
}

func getRepository() -> Repository {
return Repository(db: db)
}
Expand Down
10 changes: 5 additions & 5 deletions MMEX/Models/AccountData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,19 @@ struct AccountWithCurrency: ExportableEntity {
extension AccountData {
static let sampleDataWithCurrency : [AccountWithCurrency] = [
AccountWithCurrency(data: AccountData(
id: 1, name: "Account A", type: AccountType.cash,
id: 1, name: "Cash Account", type: AccountType.cash,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 1
initialBal: 100.01, favoriteAcct: "TRUE", currencyId: 1
), currency: CurrencyData.sampleData[0]),
AccountWithCurrency(data: AccountData(
id: 2, name: "Account B", type: AccountType.cash,
id: 2, name: "Chcking Account", type: AccountType.checking,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2
initialBal: 200.02, favoriteAcct: "TRUE", currencyId: 2
), currency: CurrencyData.sampleData[1]),
AccountWithCurrency(data: AccountData(
id: 3, name: "Investment Account", type: AccountType.investment,
status: AccountStatus.open, notes:"",
initialBal: 0.0, favoriteAcct: "TRUE", currencyId: 2
initialBal: 300.03, favoriteAcct: "TRUE", currencyId: 2
), currency: CurrencyData.sampleData[1]),
]
}
4 changes: 2 additions & 2 deletions MMEX/Models/CategoryData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension CategoryData {

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),
CategoryData(id: 1, name: "Bills", active: true, parentId: -1),
CategoryData(id: 2, name: "Telephone", active: true, parentId: 1),
]
}
3 changes: 3 additions & 0 deletions MMEX/Models/InfotableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@ extension InfotableData {
extension InfotableData {
static let sampleData: [InfotableData] = [
InfotableData(id: 1, name: "DATAVERSION", value: "3"),
InfotableData(id: 2, name: InfoKey.createDate.id, value: Date().ISO8601Format()),
InfotableData(id: 3, name: InfoKey.baseCurrencyID.id, value: "1"),
InfotableData(id: 4, name: InfoKey.defaultAccountID.id, value: "1")
]
}
8 changes: 4 additions & 4 deletions MMEX/Models/TransactionData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ extension TransactionData {
TransactionData(
id: 1, accountId: 1, payeeId: 1, transCode: TransactionType.withdrawal,
transAmount: 10.01, status: TransactionStatus.none, categId: 1,
transDate: Date().ISO8601Format()
transDate: String(Date().ISO8601Format().dropLast())
),
TransactionData(
id: 2, accountId: 2, payeeId: 2, transCode: TransactionType.deposit,
transAmount: 20.02, status: TransactionStatus.none, categId: 1,
transDate: Date().ISO8601Format()
transDate: String(Date().ISO8601Format().dropLast())
),
TransactionData(
id: 3, accountId: 3, payeeId: 3, transCode: TransactionType.transfer,
id: 3, accountId: 3, payeeId: 2, transCode: TransactionType.transfer,
transAmount: 30.03, status: TransactionStatus.none, categId: 1,
transDate: Date().ISO8601Format()
transDate: String(Date().ISO8601Format().dropLast())
),
]
}
4 changes: 4 additions & 0 deletions MMEX/ViewModels/InfotableViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class InfotableViewModel: ObservableObject {
)
}
}

func getSchemaVersion() -> Int32 {
return self.dataManager.getSchemaVersion() ?? 0
}

// Set up individual bindings for each @Published property
private func setupBindings() {
Expand Down
3 changes: 1 addition & 2 deletions MMEX/Views/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct SettingsView: View {
@AppStorage("defaultPayeeSetting") private var defaultPayeeSetting: DefaultPayeeSetting = .none
@AppStorage("defaultStatus") private var defaultStatus = TransactionStatus.defaultValue

@State private var schemaVersion: Int32 = 19
@State private var dateFormat: String = "%Y-%m-%d"

var body: some View {
Expand Down Expand Up @@ -65,7 +64,7 @@ struct SettingsView: View {
HStack {
Text("Schema Version")
Spacer()
Text("\(schemaVersion)")
Text("\(viewModel.getSchemaVersion())")
}
HStack {
Text("Date Format")
Expand Down

0 comments on commit a167302

Please sign in to comment.