Skip to content

Commit

Permalink
Add expense
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-amisha-i authored Mar 29, 2024
1 parent 9b58e1a commit 66e3525
Show file tree
Hide file tree
Showing 44 changed files with 1,111 additions and 471 deletions.
8 changes: 4 additions & 4 deletions BaseStyle/BaseStyle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -663,7 +663,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -693,7 +693,7 @@
INFOPLIST_FILE = BaseStyle/Info.plist;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -731,7 +731,7 @@
INFOPLIST_FILE = BaseStyle/Info.plist;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
34 changes: 17 additions & 17 deletions Data/Data.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
7EF3A291581F7EA20CB1042D /* Pods_Data.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E91B3E23688435064A60C0C4 /* Pods_Data.framework */; };
D83B15052B9996C0004A5F4F /* Groups.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83B15042B9996C0004A5F4F /* Groups.swift */; };
D83B15092B999789004A5F4F /* GroupRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83B15082B999789004A5F4F /* GroupRepository.swift */; };
D85E86DE2BAB0292002EDF76 /* Expense.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85E86DD2BAB0292002EDF76 /* Expense.swift */; };
D85E86E52BAB088F002EDF76 /* ExpenseRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85E86E42BAB088F002EDF76 /* ExpenseRepository.swift */; };
D88721432B99F133009DC5BE /* StorageManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D88721422B99F133009DC5BE /* StorageManager.swift */; };
D8910E382BB6D1D300877CE0 /* ExpenseStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8910E372BB6D1D300877CE0 /* ExpenseStore.swift */; };
D89DBE1D2B872F0B00E5F1BD /* NonceGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89DBE1C2B872F0B00E5F1BD /* NonceGenerator.swift */; };
D89DBE282B88802800E5F1BD /* Country.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89DBE272B88802800E5F1BD /* Country.swift */; };
D89DBE2B2B88817E00E5F1BD /* JSONUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89DBE2A2B88817E00E5F1BD /* JSONUtils.swift */; };
Expand All @@ -22,7 +25,6 @@
D89DBE532B8DC9F700E5F1BD /* AppRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89DBE522B8DC9F700E5F1BD /* AppRoute.swift */; };
D8A7CA752BA5AB670014EC67 /* UserStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A7CA742BA5AB670014EC67 /* UserStore.swift */; };
D8A7CA772BA5AB800014EC67 /* GroupStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A7CA762BA5AB800014EC67 /* GroupStore.swift */; };
D8A7CA792BA5AB920014EC67 /* MemberStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A7CA782BA5AB920014EC67 /* MemberStore.swift */; };
D8A7CA7B2BA5B6AC0014EC67 /* ShareCodeStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A7CA7A2BA5B6AC0014EC67 /* ShareCodeStore.swift */; };
D8A7CA802BA867F80014EC67 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A7CA7F2BA867F80014EC67 /* String+Extension.swift */; };
D8AC25BB2B7F327A00CEAAD3 /* SplitoPreference.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AC25BA2B7F327A00CEAAD3 /* SplitoPreference.swift */; };
Expand All @@ -31,8 +33,6 @@
D8AC25C32B7F390B00CEAAD3 /* AppAssembly.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8AC25C22B7F390B00CEAAD3 /* AppAssembly.swift */; };
D8D14A522BA0917D00F45FF2 /* SharedCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D14A512BA0917D00F45FF2 /* SharedCode.swift */; };
D8D14A542BA092F500F45FF2 /* ShareCodeRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D14A532BA092F400F45FF2 /* ShareCodeRepository.swift */; };
D8D14A5A2BA1E6E400F45FF2 /* MemberRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D14A592BA1E6E400F45FF2 /* MemberRepository.swift */; };
D8D14A5C2BA1E73600F45FF2 /* Member.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D14A5B2BA1E73600F45FF2 /* Member.swift */; };
D8D42AA92B872726009B345D /* DDLogProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D42AA82B872726009B345D /* DDLogProvider.swift */; };
D8DF8BBF2B7A315100165138 /* Data.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8DF8BB62B7A315000165138 /* Data.framework */; };
D8DF8BC42B7A315100165138 /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8DF8BC32B7A315100165138 /* DataTests.swift */; };
Expand All @@ -56,7 +56,10 @@
BED6C37AA3F8FD2A6350DE1C /* Pods-Data.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Data.debug.xcconfig"; path = "Target Support Files/Pods-Data/Pods-Data.debug.xcconfig"; sourceTree = "<group>"; };
D83B15042B9996C0004A5F4F /* Groups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Groups.swift; sourceTree = "<group>"; };
D83B15082B999789004A5F4F /* GroupRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupRepository.swift; sourceTree = "<group>"; };
D85E86DD2BAB0292002EDF76 /* Expense.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Expense.swift; sourceTree = "<group>"; };
D85E86E42BAB088F002EDF76 /* ExpenseRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpenseRepository.swift; sourceTree = "<group>"; };
D88721422B99F133009DC5BE /* StorageManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageManager.swift; sourceTree = "<group>"; };
D8910E372BB6D1D300877CE0 /* ExpenseStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpenseStore.swift; sourceTree = "<group>"; };
D89DBE1C2B872F0B00E5F1BD /* NonceGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonceGenerator.swift; sourceTree = "<group>"; };
D89DBE272B88802800E5F1BD /* Country.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Country.swift; sourceTree = "<group>"; };
D89DBE2A2B88817E00E5F1BD /* JSONUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONUtils.swift; sourceTree = "<group>"; };
Expand All @@ -67,7 +70,6 @@
D89DBE522B8DC9F700E5F1BD /* AppRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppRoute.swift; sourceTree = "<group>"; };
D8A7CA742BA5AB670014EC67 /* UserStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserStore.swift; sourceTree = "<group>"; };
D8A7CA762BA5AB800014EC67 /* GroupStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupStore.swift; sourceTree = "<group>"; };
D8A7CA782BA5AB920014EC67 /* MemberStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberStore.swift; sourceTree = "<group>"; };
D8A7CA7A2BA5B6AC0014EC67 /* ShareCodeStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareCodeStore.swift; sourceTree = "<group>"; };
D8A7CA7F2BA867F80014EC67 /* String+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
D8AC25BA2B7F327A00CEAAD3 /* SplitoPreference.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplitoPreference.swift; sourceTree = "<group>"; };
Expand All @@ -76,8 +78,6 @@
D8AC25C22B7F390B00CEAAD3 /* AppAssembly.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppAssembly.swift; sourceTree = "<group>"; };
D8D14A512BA0917D00F45FF2 /* SharedCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedCode.swift; sourceTree = "<group>"; };
D8D14A532BA092F400F45FF2 /* ShareCodeRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareCodeRepository.swift; sourceTree = "<group>"; };
D8D14A592BA1E6E400F45FF2 /* MemberRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemberRepository.swift; sourceTree = "<group>"; };
D8D14A5B2BA1E73600F45FF2 /* Member.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Member.swift; sourceTree = "<group>"; };
D8D42A9E2B870BBA009B345D /* BaseStyle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BaseStyle.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D8D42AA82B872726009B345D /* DDLogProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DDLogProvider.swift; sourceTree = "<group>"; };
D8DF8BB62B7A315000165138 /* Data.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Data.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -136,7 +136,7 @@
children = (
D89DBE452B8CBE0F00E5F1BD /* UserRepository.swift */,
D83B15082B999789004A5F4F /* GroupRepository.swift */,
D8D14A592BA1E6E400F45FF2 /* MemberRepository.swift */,
D85E86E42BAB088F002EDF76 /* ExpenseRepository.swift */,
D8D14A532BA092F400F45FF2 /* ShareCodeRepository.swift */,
);
path = Repository;
Expand All @@ -148,7 +148,7 @@
D89DBE272B88802800E5F1BD /* Country.swift */,
D89DBE472B8CBE4C00E5F1BD /* AppUser.swift */,
D83B15042B9996C0004A5F4F /* Groups.swift */,
D8D14A5B2BA1E73600F45FF2 /* Member.swift */,
D85E86DD2BAB0292002EDF76 /* Expense.swift */,
D8D14A512BA0917D00F45FF2 /* SharedCode.swift */,
);
path = Model;
Expand Down Expand Up @@ -193,7 +193,7 @@
D8AC25BA2B7F327A00CEAAD3 /* SplitoPreference.swift */,
D8A7CA742BA5AB670014EC67 /* UserStore.swift */,
D8A7CA762BA5AB800014EC67 /* GroupStore.swift */,
D8A7CA782BA5AB920014EC67 /* MemberStore.swift */,
D8910E372BB6D1D300877CE0 /* ExpenseStore.swift */,
D8A7CA7A2BA5B6AC0014EC67 /* ShareCodeStore.swift */,
);
path = Store;
Expand Down Expand Up @@ -262,8 +262,8 @@
D89DBE512B8DC4ED00E5F1BD /* Router */,
D8AC25BF2B7F38C800CEAAD3 /* DI */,
D89DBE292B88817200E5F1BD /* Utils */,
D8AC25B92B7F326B00CEAAD3 /* Store */,
D89DBE262B88801F00E5F1BD /* Model */,
D8AC25B92B7F326B00CEAAD3 /* Store */,
D83B15072B99976F004A5F4F /* Repository */,
D8A7CA7E2BA867C80014EC67 /* Extension */,
D89DBE4B2B8CBEB500E5F1BD /* Services */,
Expand Down Expand Up @@ -473,16 +473,16 @@
D89DBE2B2B88817E00E5F1BD /* JSONUtils.swift in Sources */,
D8A7CA802BA867F80014EC67 /* String+Extension.swift in Sources */,
D89DBE282B88802800E5F1BD /* Country.swift in Sources */,
D8910E382BB6D1D300877CE0 /* ExpenseStore.swift in Sources */,
D83B15092B999789004A5F4F /* GroupRepository.swift in Sources */,
D8D14A5A2BA1E6E400F45FF2 /* MemberRepository.swift in Sources */,
D89DBE532B8DC9F700E5F1BD /* AppRoute.swift in Sources */,
D8A7CA752BA5AB670014EC67 /* UserStore.swift in Sources */,
D89DBE402B8C9E7400E5F1BD /* RouterView.swift in Sources */,
D85E86E52BAB088F002EDF76 /* ExpenseRepository.swift in Sources */,
D8A7CA772BA5AB800014EC67 /* GroupStore.swift in Sources */,
D8AC25BE2B7F359B00CEAAD3 /* FirebaseProvider.swift in Sources */,
D89DBE1D2B872F0B00E5F1BD /* NonceGenerator.swift in Sources */,
D8D14A5C2BA1E73600F45FF2 /* Member.swift in Sources */,
D8A7CA792BA5AB920014EC67 /* MemberStore.swift in Sources */,
D85E86DE2BAB0292002EDF76 /* Expense.swift in Sources */,
D8D42AA92B872726009B345D /* DDLogProvider.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -559,7 +559,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -619,7 +619,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -648,7 +648,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -746,7 +746,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
20 changes: 12 additions & 8 deletions Data/Data/DI/AppAssembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class AppAssembly: Assembly {
StorageManager.init()
}.inObjectScope(.container)

// MARK: - Stores

container.register(UserStore.self) { _ in
UserStore.init()
}.inObjectScope(.container)
Expand All @@ -39,14 +41,16 @@ public class AppAssembly: Assembly {
GroupStore.init()
}.inObjectScope(.container)

container.register(MemberStore.self) { _ in
MemberStore.init()
}.inObjectScope(.container)

container.register(ShareCodeStore.self) { _ in
ShareCodeStore.init()
}.inObjectScope(.container)

container.register(ExpenseStore.self) { _ in
ExpenseStore.init()
}.inObjectScope(.container)

// MARK: - Repositories

container.register(UserRepository.self) { _ in
UserRepository.init()
}.inObjectScope(.container)
Expand All @@ -55,12 +59,12 @@ public class AppAssembly: Assembly {
GroupRepository.init()
}.inObjectScope(.container)

container.register(MemberRepository.self) { _ in
MemberRepository.init()
}.inObjectScope(.container)

container.register(ShareCodeRepository.self) { _ in
ShareCodeRepository.init()
}.inObjectScope(.container)

container.register(ExpenseRepository.self) { _ in
ExpenseRepository.init()
}.inObjectScope(.container)
}
}
46 changes: 46 additions & 0 deletions Data/Data/Model/Expense.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Expense.swift
// Data
//
// Created by Amisha Italiya on 20/03/24.
//

import FirebaseFirestore

public struct Expense: Codable {

@DocumentID public var id: String? // Automatically generated ID by Firestore

let name: String
let amount: Double
let date: Timestamp
let paidBy: String
let splitTo: [String] // Reference to user ids involved in the split
let groupId: String
let splitType: SplitType

public init(name: String, amount: Double, date: Timestamp, paidBy: String,
splitTo: [String], groupId: String, splitType: SplitType = .equally) {
self.name = name
self.amount = amount
self.date = date
self.paidBy = paidBy
self.splitTo = splitTo
self.groupId = groupId
self.splitType = splitType
}

enum CodingKeys: String, CodingKey {
case name
case amount
case date
case paidBy = "paid_by"
case splitTo = "split_to"
case groupId = "group_id"
case splitType = "split_type"
}
}

public enum SplitType: String, Codable {
case equally
}
4 changes: 2 additions & 2 deletions Data/Data/Model/Groups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public struct Groups: Codable, Identifiable {

public var name: String
public var createdBy: String
public var members: [Member]
public var members: [String]
public var imageUrl: String?
public var createdAt: Timestamp

public init(name: String, createdBy: String, members: [Member], imageUrl: String? = nil, createdAt: Timestamp) {
public init(name: String, createdBy: String, members: [String], imageUrl: String? = nil, createdAt: Timestamp) {
self.name = name
self.createdBy = createdBy
self.members = members
Expand Down
36 changes: 0 additions & 36 deletions Data/Data/Model/Member.swift

This file was deleted.

24 changes: 24 additions & 0 deletions Data/Data/Repository/ExpenseRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ExpenseRepository.swift
// Data
//
// Created by Amisha Italiya on 20/03/24.
//

import Combine
import FirebaseFirestoreInternal

public class ExpenseRepository: ObservableObject {

@Inject private var store: ExpenseStore

private var cancelable = Set<AnyCancellable>()

public func addExpense(expense: Expense, completion: @escaping (String?) -> Void) {
store.addExpense(expense: expense, completion: completion)
}

public func deleteExpense(id: String) -> AnyPublisher<Void, ServiceError> {
store.deleteExpense(id: id)
}
}
Loading

0 comments on commit 66e3525

Please sign in to comment.