Skip to content

Commit edbd132

Browse files
committed
Add Thread ID Parameter
1 parent 30479c2 commit edbd132

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/main/kotlin/io/codemc/api/database/database.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ fun removeAllUsers() = transaction(database) {
143143
/**
144144
* Adds a request to the database.
145145
* @param messageId The unique ID of the request according to Discord
146+
* @param threadId The unique ID of the thread according to Discord
146147
* @param userId The unique ID of the Discord user
147148
* @param githubName The GitHub username of the user
148149
* @param repoName The name of the repository
149150
* @return The result of the `INSERT` statement
150151
*/
151152
fun createRequest(
152153
messageId: Long,
154+
threadId: Long,
153155
userId: Long,
154156
githubName: String,
155157
repoName: String
@@ -158,6 +160,7 @@ fun createRequest(
158160

159161
return@transaction Requests.insert { row ->
160162
row[Requests.messageId] = messageId
163+
row[Requests.threadId] = threadId
161164
row[Requests.userId] = userId
162165
row[Requests.githubName] = githubName
163166
row[Requests.repoName] = repoName
@@ -175,7 +178,7 @@ fun getRequest(
175178
if (!Requests.exists()) return@transaction null
176179

177180
return@transaction Requests.selectAll().where { Requests.messageId eq messageId }
178-
.map { row -> Request(row[Requests.messageId], row[Requests.userId], row[Requests.githubName], row[Requests.repoName]) }
181+
.map { row -> Request(row[Requests.messageId], row[Requests.threadId], row[Requests.userId], row[Requests.githubName], row[Requests.repoName]) }
179182
.firstOrNull()
180183
}
181184

@@ -200,7 +203,7 @@ fun getAllRequests(): List<Request> = transaction(database) {
200203
if (!Requests.exists()) return@transaction emptyList()
201204

202205
return@transaction Requests.selectAll()
203-
.map { row -> Request(row[Requests.messageId], row[Requests.userId], row[Requests.githubName], row[Requests.repoName]) }
206+
.map { row -> Request(row[Requests.messageId], row[Requests.threadId], row[Requests.userId], row[Requests.githubName], row[Requests.repoName]) }
204207
}
205208

206209
/**

src/main/kotlin/io/codemc/api/database/schema.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ object Requests : Table() {
4040
* The `message_id` column, representing the unique ID of the request according to Discord.
4141
*/
4242
val messageId: Column<Long> = long("message_id").uniqueIndex()
43+
/**
44+
* The `thread_id` column, representing the unique ID of the thread according to Discord.
45+
*/
46+
val threadId: Column<Long> = long("thread_id")
4347
/**
4448
* The `user_id` column, representing the unique ID of the Discord user.
4549
*/
@@ -59,12 +63,14 @@ object Requests : Table() {
5963
/**
6064
* Represents a request in the database.
6165
* @property messageId The unique ID of the request according to Discord.
66+
* @property threadId The unique ID of the thread according to Discord.
6267
* @property userId The unique ID of the Discord user.
6368
* @property githubName The GitHub username of the user.
6469
* @property repoName The name of the repository.
6570
*/
6671
data class Request(
6772
val messageId: Long,
73+
val threadId: Long,
6874
val userId: Long,
6975
val githubName: String,
7076
val repoName: String

src/test/kotlin/io/codemc/api/database/TestDatabase.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class TestDatabase {
113113
val githubName = "MyAuthor"
114114
val repoName = "MyRepo"
115115

116-
createRequest(messageId, userId, githubName, repoName)
116+
createRequest(messageId, 0L, userId, githubName, repoName)
117117

118118
val r = getRequest(messageId)
119119
assertNotNull(r)
@@ -131,7 +131,7 @@ class TestDatabase {
131131
val githubName = "MyAuthor"
132132
val repoName = "MyRepo"
133133

134-
createRequest(messageId, userId, githubName, repoName)
134+
createRequest(messageId, 0L, userId, githubName, repoName)
135135
assertNotNull(getRequest(messageId))
136136

137137
removeRequest(messageId)
@@ -147,7 +147,7 @@ class TestDatabase {
147147
456L
148148
)
149149

150-
requests.forEach { createRequest(it, 0L, "Test", "Test") }
150+
requests.forEach { createRequest(it, 0L,0L, "Test", "Test") }
151151
requests.forEach { assertNotNull(getRequest(it)) }
152152

153153
removeAllRequests()
@@ -164,11 +164,12 @@ class TestDatabase {
164164
456L
165165
)
166166

167-
requests.forEachIndexed { index, l -> createRequest(l, index.toLong(), "Test", "Test") }
167+
requests.forEachIndexed { index, l -> createRequest(l, 0L, index.toLong(), "Test", "Test") }
168168
requests.forEachIndexed { index, l ->
169169
val r = getRequest(l)
170170
assertNotNull(r)
171171
assertEquals(index.toLong(), r?.userId)
172+
assertEquals(0L, r?.threadId)
172173
assertEquals("Test", r?.githubName)
173174
assertEquals("Test", r?.repoName)
174175
}

0 commit comments

Comments
 (0)