Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 7a74a4f

Browse files
author
kahverengi
committed
Add deleteByUserIDAndSubject method to TokenDao
1 parent 845c63f commit 7a74a4f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/main/kotlin/com/parnote/db/dao/TokenDao.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ interface TokenDao : Dao<Token> {
3535
handler: (exists: Boolean?, asyncResult: AsyncResult<*>) -> Unit
3636
)
3737

38+
fun deleteByUserIDAndSubject(
39+
userID: Int,
40+
subject: String,
41+
sqlConnection: SQLConnection,
42+
handler: (result: Result?, asyncResult: AsyncResult<*>) -> Unit
43+
)
44+
3845
fun getCreatedTimeByToken(
3946
token: String,
4047
sqlConnection: SQLConnection,

src/main/kotlin/com/parnote/db/entity/TokenDaoImpl.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,23 @@ class TokenDaoImpl(override val tableName: String = "token") : DaoImpl(), TokenD
115115
}
116116
}
117117

118+
override fun deleteByUserIDAndSubject(
119+
userID: Int,
120+
subject: String,
121+
sqlConnection: SQLConnection,
122+
handler: (result: Result?, asyncResult: AsyncResult<*>) -> Unit
123+
) {
124+
val query =
125+
"DELETE from `${databaseManager.getTablePrefix() + tableName}` WHERE `user_id` = ? AND `subject` = ?"
126+
127+
sqlConnection.updateWithParams(query, JsonArray().add(userID).add(subject)) { queryResult ->
128+
if (queryResult.succeeded())
129+
handler.invoke(Successful(), queryResult)
130+
else
131+
handler.invoke(null, queryResult)
132+
}
133+
}
134+
118135
override fun getCreatedTimeByToken(
119136
token: String,
120137
sqlConnection: SQLConnection,

0 commit comments

Comments
 (0)