Skip to content

Commit

Permalink
change parse.json to bodyparse.json
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Dec 14, 2023
1 parent 7e53880 commit 7825b05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
53 changes: 27 additions & 26 deletions app/org/maproulette/framework/controller/CommentController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.maproulette.framework.controller

import javax.inject.Inject
import org.maproulette.exception.{StatusMessage}
import org.maproulette.exception.StatusMessage
import org.maproulette.data.ActionManager
import org.maproulette.framework.service.{CommentService, ServiceManager}
import org.maproulette.session.SessionManager
Expand Down Expand Up @@ -118,7 +118,7 @@ class CommentController @Inject() (
* @return Ok if successful.
*/
def add(taskId: Long, actionId: Option[Long]): Action[JsValue] =
Action.async(parse.json) { implicit request =>
Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val commentResult = (request.body \ "comment").asOpt[String].map(_.trim)

Expand Down Expand Up @@ -155,7 +155,7 @@ class CommentController @Inject() (
* @return Ok if successful.
*/
def addChallengeComment(challengeId: Long): Action[JsValue] =
Action.async(parse.json) { implicit request =>
Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val commentResult = (request.body \ "comment").asOpt[String].map(_.trim)

Expand Down Expand Up @@ -196,7 +196,7 @@ class CommentController @Inject() (
def addToBundleTasks(
bundleId: Long,
actionId: Option[Long]
): Action[JsValue] = Action.async(parse.json) { implicit request =>
): Action[JsValue] = Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val commentResult = (request.body \ "comment").asOpt[String].map(_.trim)

Expand Down Expand Up @@ -232,33 +232,34 @@ class CommentController @Inject() (
* @param commentId The ID of the comment to update
* @return
*/
def update(commentId: Long): Action[JsValue] = Action.async(parse.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val commentResult = (request.body \ "comment").asOpt[String].map(_.trim)
def update(commentId: Long): Action[JsValue] = Action.async(bodyParsers.json) {
implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val commentResult = (request.body \ "comment").asOpt[String].map(_.trim)

commentResult match {
case Some(comment) if comment.nonEmpty =>
try {
Ok(Json.toJson(this.commentService.update(commentId, comment, user)))
} catch {
case _: Throwable =>
// Handle other unexpected errors
BadRequest(Json.toJson(StatusMessage("KO", JsString("Comment couldn't be saved"))))
}
commentResult match {
case Some(comment) if comment.nonEmpty =>
try {
Ok(Json.toJson(this.commentService.update(commentId, comment, user)))
} catch {
case _: Throwable =>
// Handle other unexpected errors
BadRequest(Json.toJson(StatusMessage("KO", JsString("Comment couldn't be saved"))))
}

case Some(comment) =>
// Empty comment is not allowed
BadRequest(Json.toJson(StatusMessage("KO", JsString("Comment cannot be empty"))))
case Some(comment) =>
// Empty comment is not allowed
BadRequest(Json.toJson(StatusMessage("KO", JsString("Comment cannot be empty"))))

case None =>
// "comment" field is missing in the request body
BadRequest(
Json.toJson(
StatusMessage("KO", JsString("Required comment object in request body no found."))
case None =>
// "comment" field is missing in the request body
BadRequest(
Json.toJson(
StatusMessage("KO", JsString("Required comment object in request body no found."))
)
)
)
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TaskBundleController @Inject() (
tags: String = "",
newTaskStatus: String = "",
errorTags: String = ""
): Action[JsValue] = Action.async(parse.json) { implicit request =>
): Action[JsValue] = Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val tasks = this.serviceManager.taskBundle.getTaskBundle(user, id).tasks match {
case Some(t) => {
Expand Down Expand Up @@ -192,7 +192,7 @@ class TaskBundleController @Inject() (
reviewStatus: Int,
tags: String = "",
errorTags: String = ""
): Action[JsValue] = Action.async(parse.json) { implicit request =>
): Action[JsValue] = Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val tasks = this.serviceManager.taskBundle.getTaskBundle(user, id).tasks match {
case Some(t) => t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class TaskReviewController @Inject() (
tags: String = "",
newTaskStatus: String = "",
errorTags: String = ""
): Action[JsValue] = Action.async(parse.json) { implicit request =>
): Action[JsValue] = Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val task = this.taskRepository.retrieve(id) match {
case Some(t) => {
Expand Down Expand Up @@ -521,7 +521,7 @@ class TaskReviewController @Inject() (
reviewStatus: Int,
tags: String = "",
errorTags: String = ""
): Action[JsValue] = Action.async(parse.json) { implicit request =>
): Action[JsValue] = Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
val task = this.taskRepository.retrieve(id) match {
case Some(t) => t
Expand Down

0 comments on commit 7825b05

Please sign in to comment.