Created
February 22, 2018 16:13
-
-
Save mczachurski/a9e5451b20ee10d0fa0fc3318f82027b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksRepository : TasksRepositoryProtocol { | |
private let databaseContext: DatabaseContextProtocol | |
init(databaseContext: DatabaseContextProtocol) { | |
self.databaseContext = databaseContext | |
} | |
func getTasks() throws -> [Task] { | |
let tasks = try self.databaseContext.set(Task.self).select() | |
return tasks.sorted { (task1, task2) -> Bool in | |
return task1.name < task2.name | |
} | |
} | |
func getTask(id: Int) throws -> Task? { | |
let task = try self.databaseContext.set(Task.self).where(\Task.id == id).first() | |
return task | |
} | |
func addTask(task: Task) throws { | |
try self.databaseContext.set(Task.self).insert(task) | |
} | |
func updateTask(task: Task) throws { | |
try self.databaseContext.set(Task.self).where(\Task.id == task.id).update(task) | |
} | |
func deleteTask(id: Int) throws { | |
try self.databaseContext.set(Task.self).where(\Task.id == id).delete() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment