-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ids are string now: JavaScript can't handle the Java Long.
- Loading branch information
Showing
18 changed files
with
208 additions
and
179 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package blog.model | ||
|
||
data class State( | ||
private val users: Map<Long, User> = mapOf(), | ||
private val notes: Map<Long, Note> = mapOf(), | ||
private val tasks: Map<Long, Task> = mapOf(), | ||
private val tags : Map<Long, Tag> = mapOf(), | ||
private val users: Map<String, User> = mapOf(), | ||
private val notes: Map<String, Note> = mapOf(), | ||
private val tasks: Map<String, Task> = mapOf(), | ||
private val tags : Map<String, Tag> = mapOf(), | ||
private val recovered: Boolean = false | ||
) { | ||
fun save(u: User) : State = this.copy(users = this.users.minus(u.id).plus(u.id to u)) | ||
fun findUser(id: Long) : User? = users[id] | ||
fun findUser(id: String) : User? = users[id] | ||
fun findUserByEmail(email: String): User? = users.values.find { it.email == email } | ||
fun allUsers() : List<User> = users.values.toList() | ||
fun userCount() : Int = users.size | ||
fun deleteUser(id: Long) : State = this.copy(users = this.users.minus(id)) | ||
fun deleteUser(id: String) : State = this.copy(users = this.users.minus(id)) | ||
|
||
fun save(n: Note) : State = this.copy(notes = this.notes.minus(n.id).plus(n.id to n)) | ||
fun findNote(id: Long) : Note? = notes[id] | ||
fun findNotesForUser(id: Long): List<Note> = notes.values.filter { it.user == id } | ||
fun noteCount() : Int = notes.size | ||
fun deleteNote(id: Long) : State = this.copy(notes = this.notes.minus(id)) | ||
fun save(n: Note) : State = this.copy(notes = this.notes.minus(n.id).plus(n.id to n)) | ||
fun findNote(id: String) : Note? = notes[id] | ||
fun findNotesForUser(id: String): List<Note> = notes.values.filter { it.user == id } | ||
fun noteCount() : Int = notes.size | ||
fun deleteNote(id: String) : State = this.copy(notes = this.notes.minus(id)) | ||
|
||
fun save(t: Task) : State = this.copy(tasks = this.tasks.minus(t.id).plus(t.id to t)) | ||
fun findTask(id: Long) : Task? = tasks[id] | ||
fun findTasksForUser(id: Long): List<Task> = tasks.values.filter { it.user == id } | ||
fun taskCount() : Int = tasks.size | ||
fun deleteTask(id: Long) : State = this.copy(tasks = this.tasks.minus(id)) | ||
fun save(t: Task) : State = this.copy(tasks = this.tasks.minus(t.id).plus(t.id to t)) | ||
fun findTask(id: String) : Task? = tasks[id] | ||
fun findTasksForUser(id: String): List<Task> = tasks.values.filter { it.user == id } | ||
fun taskCount() : Int = tasks.size | ||
fun deleteTask(id: String) : State = this.copy(tasks = this.tasks.minus(id)) | ||
|
||
fun setRecovered(): State = this.copy(recovered = true) | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.