admin 管理员组文章数量: 1086019
I have this function in my TaskService:
func deleteTask(task: DistributionTask) async throws -> Void {
let (tasksCollection, userTasksIdsField, teamTasksIdsField) = task.isCompleted
? (FirestoreConstants.CollectionpletedTasks,
FirestoreConstants.Field.UserpletedTaskIds,
FirestoreConstants.Field.TeampletedTaskIds)
: (FirestoreConstants.Collection.activeTasks,
FirestoreConstants.Field.User.activeTaskIds,
FirestoreConstants.Field.Team.activeTaskIds)
try await taskRepository.deleteTask(from: tasksCollection, taskID: task.id)
try await teamRepository.removeTaskReferenceFromTeam(field: teamTasksIdsField, teamID: task.teamId, taskID: task.id)
try await userRepository.removeTaskReferenceFromUser(field: userTasksIdsField, userID: task.distributorId, taskID: task.id)
}
func deleteTask(from collection: String, taskID: String) async throws -> Void {
try await db.collection(collection).document(taskID).delete()
}
func removeTaskReferenceFromUser(field: String, userID: String, taskID: String) async throws -> Void {
}
func removeTaskReferenceFromTeam(field: String, teamID: String, taskID: String) async throws -> Void {
try await db.collection(FirestoreConstants.Collection.teams).document(teamID).updateData([
field: FieldValue.arrayRemove([taskID])
])
}
and there are three functions defined in different repositories (task, user, team) but they need to be done atomically for example with runTransaction method but the problem is if I coordinate those 3 functions from one single TaskService I can't use transaction.
In addition, I do not want to just wrap those 3 calls with runTransaction in my service because that would mix aplication logic with firebase logic.
My question is how to keep application and firebase logic separated but do those 3 delete functions as atomic operation?
I tried making some kind of transcation coordinator but it did not work.
本文标签: Separating Firebase logic from business logic in Swift using ServiceRepository patternStack Overflow
版权声明:本文标题:Separating Firebase logic from business logic in Swift using Service-Repository pattern - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744093038a2532390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论