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

Commit 6d2966b

Browse files
author
kahverengi
committed
Add MoveNoteArchiveAPI
1 parent b63d1c6 commit 6d2966b

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/main/kotlin/com/parnote/ErrorCode.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ enum class ErrorCode {
4747
UNKNOWN_ERROR_44,
4848
UNKNOWN_ERROR_45,
4949
UNKNOWN_ERROR_46,
50+
UNKNOWN_ERROR_47,
51+
UNKNOWN_ERROR_48,
52+
UNKNOWN_ERROR_49,
53+
UNKNOWN_ERROR_50,
5054

5155
REGISTER_NAME_EMPTY,
5256
REGISTER_NAME_SHORT,

src/main/kotlin/com/parnote/di/module/RouterModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class RouterModule(private val mVertx: Vertx) {
5353
GetUserNotesAPI(),
5454
AddNoteAPI(),
5555
EditNoteAPI(),
56-
MoveNoteTrashAPI()
56+
MoveNoteTrashAPI(),
57+
MoveNoteArchiveAPI()
5758
)
5859
}
5960

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.parnote.route.api
2+
3+
import com.parnote.ErrorCode
4+
import com.parnote.model.*
5+
import com.parnote.util.LoginUtil
6+
import io.vertx.ext.web.RoutingContext
7+
8+
class MoveNoteArchiveAPI : LoggedInApi() {
9+
override val routes = arrayListOf("/api/user/moveNoteArchive")
10+
11+
override val routeType = RouteType.POST
12+
13+
override fun getHandler(context: RoutingContext, handler: (result: Result) -> Unit) {
14+
val data = context.bodyAsJson
15+
16+
val id = data.getInteger("id")
17+
18+
databaseManager.createConnection { sqlConnection, _ ->
19+
if (sqlConnection == null) {
20+
handler.invoke(Error(ErrorCode.UNKNOWN_ERROR_47))
21+
22+
return@createConnection
23+
}
24+
25+
LoginUtil.getUserIDFromSessionOrCookie(context, sqlConnection, databaseManager) { userID, _ ->
26+
if (userID == null) {
27+
databaseManager.closeConnection(sqlConnection) {
28+
handler.invoke(Error(ErrorCode.UNKNOWN_ERROR_48))
29+
}
30+
31+
return@getUserIDFromSessionOrCookie
32+
}
33+
34+
databaseManager.getDatabase().noteDao.moveStatus(
35+
id,
36+
userID,
37+
2,
38+
sqlConnection
39+
) { result, _ ->
40+
databaseManager.closeConnection(sqlConnection) {
41+
if (result == null) {
42+
handler.invoke(Error(ErrorCode.UNKNOWN_ERROR_49))
43+
44+
return@closeConnection
45+
}
46+
47+
handler.invoke(
48+
if (result is Successful)
49+
Successful()
50+
else
51+
Error(ErrorCode.UNKNOWN_ERROR_50)
52+
)
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)