Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import Foundation
actor TodoRepositoryImpl: TodoRepository { var todos: [UUID: Todo]
init() { self.todos = [:] }
func create(title: String, order: Int?, urlPrefix: String) async throws -> Todo { let id = UUID() let url = urlPrefix + id.uuidString let todo = Todo(id: id, title: title, order: order, url: url, completed: false) self.todos[id] = todo return todo }
func get(id: UUID) async throws -> Todo? { return self.todos[id] }
func list() async throws -> [Todo] { return self.todos.values.map({ $0 }) }
func update(id: UUID, title: String?, order: Int?, completed: Bool?) async throws -> Todo? { guard var todo = self.todos[id] else { return nil }
if let title { todo.title = title }
if let order { todo.order = order }
if let completed { todo.completed = completed }
return todo }
func delete(id: UUID) async throws -> Bool { guard self.todos[id] != nil else { return true }
self.todos[id] = nil return false }
func deleteAll() async throws { self.todos = [:] }}