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

Commit 116e36b

Browse files
author
kahverengi
committed
Add getTokenIDByNoteID method to ShareLinkDao
1 parent a15e2f3 commit 116e36b

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ interface ShareLinkDao : Dao<ShareLink> {
2626
handler: (noteID: Int?, asyncResult: AsyncResult<*>) -> Unit
2727
)
2828

29+
fun getTokenIDByNoteID(
30+
noteID: Int,
31+
sqlConnection: SQLConnection,
32+
handler: (tokenID: Int?, asyncResult: AsyncResult<*>) -> Unit
33+
)
34+
2935
fun isLinkExistsByNoteID(
3036
noteID: Int,
3137
sqlConnection: SQLConnection,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ class ShareLinkDaoImpl(override val tableName: String = "share_link") : DaoImpl(
8585
}
8686
}
8787

88+
override fun getTokenIDByNoteID(
89+
noteID: Int,
90+
sqlConnection: SQLConnection,
91+
handler: (tokenID: Int?, asyncResult: AsyncResult<*>) -> Unit
92+
) {
93+
val query =
94+
"SELECT `token_id` FROM `${getTablePrefix() + tableName}` WHERE `note_id` = ?"
95+
96+
sqlConnection.queryWithParams(query, JsonArray().add(noteID)) { queryResult ->
97+
if (queryResult.succeeded()) {
98+
val row = queryResult.result().results[0]
99+
100+
handler.invoke(row.getInteger(0), queryResult)
101+
} else
102+
handler.invoke(null, queryResult)
103+
}
104+
}
105+
88106
override fun isLinkExistsByNoteID(
89107
noteID: Int,
90108
sqlConnection: SQLConnection,

0 commit comments

Comments
 (0)