-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
1,453 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Qodana | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
- feature/add-todo-list | ||
|
||
jobs: | ||
qodana: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: 'Qodana Scan' | ||
uses: JetBrains/qodana-action@v2023.2 | ||
env: | ||
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import auth.{JwtService, JwtServiceImpl} | ||
import com.google.inject.AbstractModule | ||
import dao.{DatabaseExecutionContext, DatabaseExecutionContextImpl} | ||
import liquibase.LiquibaseRunner | ||
import play.api.libs.concurrent.AkkaGuiceSupport | ||
|
||
class Module extends AbstractModule with AkkaGuiceSupport { | ||
override def configure(): Unit = { | ||
bind(classOf[LiquibaseRunner]).asEagerSingleton() | ||
bind(classOf[ShutdownHook]).asEagerSingleton() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import org.slf4j.Logger | ||
|
||
import scala.concurrent.Future | ||
import play.api.inject.ApplicationLifecycle | ||
|
||
import javax.inject._ | ||
|
||
class ShutdownHook @Inject()(lifecycle: ApplicationLifecycle) { | ||
val logger: Logger = org.slf4j.LoggerFactory.getLogger("ShutdownHook") | ||
|
||
lifecycle.addStopHook { () => | ||
logger.info("ShutdownHook is running") | ||
val threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean | ||
val threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds, 100) | ||
val stackTrace = threadInfos.map(threadInfo => { | ||
s""" | ||
'${threadInfo.getThreadName}': ${threadInfo.getThreadState} | ||
at ${threadInfo.getStackTrace.mkString("\n at ")} | ||
""" | ||
}).mkString("\n") | ||
logger.info(s"Thread dump:\n$stackTrace") | ||
Future.successful(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package controllers | ||
|
||
import auth.AuthenticatedAction | ||
import org.slf4j.{Logger, LoggerFactory} | ||
import play.api.libs.json.Json | ||
import play.api.mvc.{Action, AnyContent, ControllerComponents} | ||
import service.UserTodoService | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
class UserTodoController @Inject()(cc: ControllerComponents, userTodoService: UserTodoService, | ||
authenticatedAction: AuthenticatedAction) | ||
extends EmoBaseController(cc, authenticatedAction) { | ||
|
||
private val logger: Logger = LoggerFactory.getLogger(classOf[UserTodoController]) | ||
|
||
def fetchUserTodos(page: Int, size: Int): Action[AnyContent] = { //TODO: Add pagination | ||
authenticatedActionWithUser { implicit token => | ||
logger.info("Fetching user todos") | ||
userTodoService.fetchByUserId(token.userId).map(userTodos => Ok(Json.toJson(userTodos))) | ||
} | ||
} | ||
|
||
def complete(userTodoId: Long, isDone: Boolean): Action[AnyContent] = { | ||
authenticatedActionWithUser { implicit token => | ||
if (isDone) { | ||
logger.info("Completing user todo {}", Map("userTodoId" -> userTodoId)) | ||
userTodoService.complete(token.userId, userTodoId).map(userTodos => Ok(Json.toJson(userTodos))) | ||
} else { | ||
logger.info("Uncompleting user todo {}", Map("userTodoId" -> userTodoId)) | ||
userTodoService.uncomplete(token.userId, userTodoId).map(userTodos => Ok(Json.toJson(userTodos))) | ||
} | ||
|
||
} | ||
} | ||
|
||
def archive(userTodoId: Long, isArchived: Boolean): Action[AnyContent] = { | ||
authenticatedActionWithUser { implicit token => | ||
if (isArchived) { | ||
logger.info("Archiving user todo {}", Map("userTodoId" -> userTodoId)) | ||
userTodoService.archive(token.userId, userTodoId).map(userTodos => Ok(Json.toJson(userTodos))) | ||
} else { | ||
logger.info("Unarchiving user todo {}", Map("userTodoId" -> userTodoId)) | ||
userTodoService.unarchive(token.userId, userTodoId).map(userTodos => Ok(Json.toJson(userTodos))) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package dao | ||
|
||
import anorm.{SQL, SqlParser} | ||
import dao.model.{Note, NoteTodo} | ||
import service.DateTimeService | ||
|
||
import java.sql.Connection | ||
import javax.inject.Inject | ||
|
||
class NoteTodoDao @Inject()() { | ||
def findById(id: Long)(implicit connection: Connection): Option[NoteTodo] = { | ||
SQL("SELECT * FROM note_todos WHERE id = {id}").on("id" -> id).as(NoteTodo.parser.singleOpt) | ||
} | ||
|
||
def verifyNoteTodoBelongsToUser(userId: Long, noteTodoId: Long)(implicit connection: Connection): Boolean = { | ||
SQL( | ||
""" | ||
SELECT emotion_records.user_id | ||
FROM note_todos | ||
INNER JOIN note_note_todos ON note_todos.id = note_note_todos.note_todo_id | ||
INNER JOIN notes ON note_note_todos.note_id = notes.id | ||
INNER JOIN emotion_record_notes ON notes.id = emotion_record_notes.note_id | ||
INNER JOIN emotion_records ON emotion_record_notes.emotion_record_id = emotion_records.id | ||
WHERE note_todos.id = {noteTodoId} AND emotion_records.user_id = {userId} | ||
""").on( | ||
"noteTodoId" -> noteTodoId, | ||
"userId" -> userId | ||
).as(SqlParser.scalar[Long].singleOpt).isDefined | ||
} | ||
|
||
def acceptNoteTodo(noteTodoId: Long)(implicit connection: Connection): Boolean = { | ||
val updated: Int = SQL( | ||
""" | ||
UPDATE note_todos | ||
SET is_accepted = true | ||
WHERE id = {noteTodoId} | ||
""").on( | ||
"noteTodoId" -> noteTodoId | ||
).executeUpdate() | ||
updated == 1 | ||
} | ||
|
||
|
||
def insert(noteId: Long, todo: NoteTodo)(implicit connection: Connection): Option[Long] = { | ||
val todoId: Option[Long] = SQL(""" | ||
INSERT INTO note_todos (title, description, is_accepted, is_ai) | ||
VALUES ({title}, {description}, {is_accepted}, {is_ai}) | ||
""").on( | ||
"title" -> todo.title, | ||
"description" -> todo.description, | ||
"is_accepted" -> todo.isAccepted, | ||
"is_ai" -> todo.isAi | ||
).executeInsert() | ||
|
||
for { | ||
id <- todoId | ||
} yield { | ||
linkTodoToNote (id, noteId) | ||
} | ||
todoId | ||
} | ||
|
||
private def linkTodoToNote(todoId: Long, noteId: Long)(implicit connection: Connection): Int = { | ||
SQL( | ||
""" | ||
INSERT INTO note_note_todos (note_id, note_todo_id) | ||
VALUES ({noteId}, {noteTodoId}) | ||
""").on( | ||
"noteTodoId" -> todoId, | ||
"noteId" -> noteId | ||
).executeUpdate() | ||
} | ||
|
||
def findNoteTodosByNoteId(noteId: Long)(implicit connection: Connection): Option[List[NoteTodo]] = { | ||
val todos = SQL("SELECT * FROM note_todos inner join note_note_todos on id = note_todo_id WHERE note_id = " + | ||
"{noteId}").on("noteId" -> noteId).as(NoteTodo.parser.*) | ||
todos.size match { | ||
case 0 => None | ||
case _ => Some(todos) | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.