-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIssueRepo.kt
44 lines (39 loc) · 1.36 KB
/
IssueRepo.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.ishroid.example.app.repo
import com.ishroid.example.app.database.IssueTable
import com.ishroid.example.app.database.UserTable
import com.ishroid.example.app.model.Issue
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
class IssueRepo {
suspend fun create(issue: Issue) {
transaction {
IssueTable.insert {
it[userId] = issue.userUuid
it[title] = issue.title
it[description] = issue.description
it[refImages] = issue.refImages
it[refVideos] = issue.refVideos
}
}
}
suspend fun getAll(): List<Issue> {
return transaction {
IssueTable.selectAll().map {
it.toIssue()
}
}
}
suspend fun get(id: Int): Issue? {
return transaction {
IssueTable.select { IssueTable.id eq id }.map {
it.toIssue()
}.firstOrNull()
}
}
private fun ResultRow.toIssue(): Issue {
return Issue(this[IssueTable.userId], this[IssueTable.id].value, this[IssueTable.title], this[IssueTable.description], this[IssueTable.refImages], this[IssueTable.refVideos])
}
}