Skip to content

Commit

Permalink
Fix: KTOR-7248 Methods in FakeTaskRepository in first iteration shoul…
Browse files Browse the repository at this point in the history
…dn't have the suspend keyword (#511)
  • Loading branch information
Omasyo authored Aug 20, 2024
1 parent 9e4b53a commit f8a6241
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions topics/server-integrate-database.topic
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,37 @@
<path>FakeTaskRepository.kt</path>
and add the following <code>class</code>:
</p>
<code-block
src="snippets/tutorial-server-db-integration/src/test/kotlin/com/example/FakeTaskRepository.kt"
lang="kotlin"/>
<code-block lang="kotlin"><![CDATA[
class FakeTaskRepository : TaskRepository {
private val tasks = mutableListOf(
Task("cleaning", "Clean the house", Priority.Low),
Task("gardening", "Mow the lawn", Priority.Medium),
Task("shopping", "Buy the groceries", Priority.High),
Task("painting", "Paint the fence", Priority.Medium)
)
override fun allTasks(): List<Task> = tasks
override fun tasksByPriority(priority: Priority) = tasks.filter {
it.priority == priority
}
override fun taskByName(name: String) = tasks.find {
it.name.equals(name, ignoreCase = true)
}
override fun addTask(task: Task) {
if (taskByName(task.name) != null) {
throw IllegalStateException("Cannot duplicate task names!")
}
tasks.add(task)
}
override fun removeTask(name: String): Boolean {
return tasks.removeIf { it.name == name }
}
}
]]></code-block>
</step>
</procedure>
</chapter>
Expand Down

0 comments on commit f8a6241

Please sign in to comment.