From 8772635ad97b464c0fcf606ec8f3b3bc0311f2ea Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Wed, 11 Feb 2026 18:04:36 +0100 Subject: [PATCH] Renamed the Repository protocol in the app target as TodoRepository. --- .../ModelContext+Conformances.swift | 10 +++++-- App/Sources/Protocols/Repository.swift | 28 ------------------- App/Sources/Protocols/TodoRepository.swift | 28 +++++++++++++++++++ .../View Models/NewTaskViewModel.swift | 2 +- .../View Models/TaskListViewModel.swift | 2 +- 5 files changed, 37 insertions(+), 33 deletions(-) delete mode 100644 App/Sources/Protocols/Repository.swift create mode 100644 App/Sources/Protocols/TodoRepository.swift diff --git a/App/Sources/Extensions/ModelContext+Conformances.swift b/App/Sources/Extensions/ModelContext+Conformances.swift index b13caec..593e454 100644 --- a/App/Sources/Extensions/ModelContext+Conformances.swift +++ b/App/Sources/Extensions/ModelContext+Conformances.swift @@ -1,8 +1,12 @@ import SwiftData -/// Extends ModelContext to conform to the Repository protocol. +/// Extends ModelContext to conform to the TodoRepository protocol. /// -/// This extension allows ModelContext from SwiftData to be used as a repository, +/// This extension allows ModelContext from SwiftData to be used as a todo repository, /// enabling dependency injection and facilitating unit testing by allowing mock /// repositories to be substituted during tests. -extension ModelContext: Repository {} +/// +/// The ModelContext methods `delete(_:)` and `insert(_:)` already match the +/// TodoRepository protocol requirements, so this extension simply declares conformance +/// without requiring additional implementation. +extension ModelContext: TodoRepository {} diff --git a/App/Sources/Protocols/Repository.swift b/App/Sources/Protocols/Repository.swift deleted file mode 100644 index c1b97b3..0000000 --- a/App/Sources/Protocols/Repository.swift +++ /dev/null @@ -1,28 +0,0 @@ -import SwiftData - -/// A protocol defining the interface for a data repository. -/// -/// This protocol abstracts the underlying data persistence mechanism, allowing for -/// dependency injection and easier testing. Implementations handle the storage and -/// retrieval of model objects. -protocol Repository { - - /// Deletes a model object from the repository. - /// - /// This method removes the specified object from persistent storage. The deletion - /// is typically performed immediately, though the actual persistence may be deferred - /// until a save operation occurs depending on the implementation. - /// - /// - Parameter model: The model object to delete from the repository. - func delete(_ model: some PersistentModel) - - /// Inserts a new model object into the repository. - /// - /// This method adds a new object to persistent storage. The object is typically - /// tracked immediately, though the actual persistence may be deferred until a - /// save operation occurs depending on the implementation. - /// - /// - Parameter model: The model object to insert into the repository. - func insert(_ model: some PersistentModel) - -} diff --git a/App/Sources/Protocols/TodoRepository.swift b/App/Sources/Protocols/TodoRepository.swift new file mode 100644 index 0000000..4cd9a48 --- /dev/null +++ b/App/Sources/Protocols/TodoRepository.swift @@ -0,0 +1,28 @@ +import SwiftData + +/// A protocol defining the interface for a todo repository. +/// +/// This protocol abstracts the underlying data persistence mechanism for todo tasks, +/// allowing for dependency injection and easier testing. Implementations handle the +/// storage and retrieval of Todo objects. +protocol TodoRepository { + + /// Deletes a todo task from the repository. + /// + /// This method removes the specified todo from persistent storage. The deletion + /// is typically performed immediately, though the actual persistence may be deferred + /// until a save operation occurs depending on the implementation. + /// + /// - Parameter todo: The todo task to delete from the repository. + func delete(_ todo: Todo) + + /// Inserts a new todo task into the repository. + /// + /// This method adds a new todo to persistent storage. The todo is typically + /// tracked immediately, though the actual persistence may be deferred until a + /// save operation occurs depending on the implementation. + /// + /// - Parameter todo: The todo task to insert into the repository. + func insert(_ todo: Todo) + +} diff --git a/App/Sources/View Models/NewTaskViewModel.swift b/App/Sources/View Models/NewTaskViewModel.swift index 9b3fbef..9f03a0f 100644 --- a/App/Sources/View Models/NewTaskViewModel.swift +++ b/App/Sources/View Models/NewTaskViewModel.swift @@ -64,7 +64,7 @@ extension NewTaskView { /// The `note` property value is only included if it's not empty after trimming. /// /// - Parameter repository: The repository to insert a new todo task. - func save(to repository: Repository) { + func save(to repository: TodoRepository) { let trimmedTitle = title.trimmingCharacters(in: .whitespacesAndNewlines) let trimmedNote = note.trimmingCharacters(in: .whitespacesAndNewlines) diff --git a/App/Sources/View Models/TaskListViewModel.swift b/App/Sources/View Models/TaskListViewModel.swift index 9782bdf..b4aae30 100644 --- a/App/Sources/View Models/TaskListViewModel.swift +++ b/App/Sources/View Models/TaskListViewModel.swift @@ -98,7 +98,7 @@ extension TaskListView { func delete( _ tasks: [Todo], at offsets: IndexSet, - from repository: Repository + from repository: TodoRepository ) { for index in offsets { repository.delete(tasks[index])