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

Commit b63d1c6

Browse files
author
kahverengi
committed
Add MoveNoteTrashAPI
1 parent 49ad7aa commit b63d1c6

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
@@ -43,6 +43,10 @@ enum class ErrorCode {
4343
UNKNOWN_ERROR_40,
4444
UNKNOWN_ERROR_41,
4545
UNKNOWN_ERROR_42,
46+
UNKNOWN_ERROR_43,
47+
UNKNOWN_ERROR_44,
48+
UNKNOWN_ERROR_45,
49+
UNKNOWN_ERROR_46,
4650

4751
REGISTER_NAME_EMPTY,
4852
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
@@ -52,7 +52,8 @@ class RouterModule(private val mVertx: Vertx) {
5252
InitialLoggedInAPI(),
5353
GetUserNotesAPI(),
5454
AddNoteAPI(),
55-
EditNoteAPI()
55+
EditNoteAPI(),
56+
MoveNoteTrashAPI()
5657
)
5758
}
5859

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 MoveNoteTrashAPI : LoggedInApi() {
9+
override val routes = arrayListOf("/api/user/moveNoteTrash")
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_43))
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_44))
29+
}
30+
31+
return@getUserIDFromSessionOrCookie
32+
}
33+
34+
databaseManager.getDatabase().noteDao.moveStatus(
35+
id,
36+
userID,
37+
3,
38+
sqlConnection
39+
) { result, _ ->
40+
databaseManager.closeConnection(sqlConnection) {
41+
if (result == null) {
42+
handler.invoke(Error(ErrorCode.UNKNOWN_ERROR_45))
43+
44+
return@closeConnection
45+
}
46+
47+
handler.invoke(
48+
if (result is Successful)
49+
Successful()
50+
else
51+
Error(ErrorCode.UNKNOWN_ERROR_46)
52+
)
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)