Skip to content

Commit

Permalink
move notificationIds to json in services (#997)
Browse files Browse the repository at this point in the history
* move notificationIds to json in services

* run scala fix all
  • Loading branch information
jschwarz2030 authored Dec 23, 2022
1 parent fc0020e commit d2afeaa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
package org.maproulette.framework.controller

import javax.inject.Inject
import org.apache.commons.lang3.StringUtils
import org.maproulette.exception.StatusMessage
import org.maproulette.framework.service.{NotificationService}
import org.maproulette.framework.model.{NotificationSubscriptions}
import org.maproulette.framework.psql.{Order, OrderField, Paging}
import org.maproulette.session.SessionManager
import org.maproulette.utils.{Crypto, Utils}
import org.maproulette.utils.Crypto
import play.api.libs.json._
import play.api.mvc._

Expand Down Expand Up @@ -67,23 +66,24 @@ class NotificationController @Inject() (
}
}

def markNotificationsRead(userId: Long, notificationIds: String): Action[AnyContent] =
Action.async { implicit request =>
def markNotificationsRead(userId: Long): Action[JsValue] =
Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
if (!StringUtils.isEmpty(notificationIds)) {
val parsedNotificationIds = Utils.split(notificationIds).map(_.toLong)
this.service.markNotificationsRead(userId, user, parsedNotificationIds)
val notificationIds = (request.body \ "notificationIds").as[List[Long]]
if (!notificationIds.isEmpty) {
this.service.markNotificationsRead(userId, user, notificationIds)
}
Ok(Json.toJson(StatusMessage("OK", JsString(s"Notifications marked as read"))))
}
}

def deleteNotifications(userId: Long, notificationIds: String): Action[AnyContent] =
Action.async { implicit request =>
def deleteNotifications(userId: Long): Action[JsValue] =
Action.async(bodyParsers.json) { implicit request =>
this.sessionManager.authenticatedRequest { implicit user =>
if (!StringUtils.isEmpty(notificationIds)) {
val parsedNotificationIds = Utils.split(notificationIds).map(_.toLong)
this.service.deleteNotifications(userId, user, parsedNotificationIds)
val notificationIds = (request.body \ "notificationIds").as[List[Long]]

if (!notificationIds.isEmpty) {
this.service.deleteNotifications(userId, user, notificationIds)
}
Ok(Json.toJson(StatusMessage("OK", JsString(s"Notifications deleted"))))
}
Expand Down
22 changes: 14 additions & 8 deletions conf/v2_route/notification.api
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ GET /user/:userId/notifications @org.maproulette.framework.c
# in: path
# description: The id of the user that owns the notifications
# - name: notificationIds
# in: query
# description: One or more comma-separated ids of notifications to mark as read
# type: string,
# in: body
# description: A JSON array of notification ids
# required: true
# schema:
# type: array
# items:
# type: integer
# - name: apiKey
# in: header
# description: The user's apiKey to authorize the request
# required: true
# type: string
###
PUT /user/:userId/notifications @org.maproulette.framework.controller.NotificationController.markNotificationsRead(userId:Long, notificationIds:String)
PUT /user/:userId/notifications @org.maproulette.framework.controller.NotificationController.markNotificationsRead(userId:Long)
###
# tags: [ Notification ]
# summary: Delete user notifications
Expand All @@ -86,17 +89,20 @@ PUT /user/:userId/notifications @org.maproulette.framework.c
# in: path
# description: The id of the user that owns the notifications
# - name: notificationIds
# in: query
# description: One or more comma-separated ids of notifications to delete
# type: string,
# in: body
# description: A JSON array of notification ids
# required: true
# schema:
# type: array
# items:
# type: integer
# - name: apiKey
# in: header
# description: The user's apiKey to authorize the request
# required: true
# type: string
###
DELETE /user/:userId/notifications @org.maproulette.framework.controller.NotificationController.deleteNotifications(userId:Long, notificationIds:String)
PUT /user/:userId/notifications/delete @org.maproulette.framework.controller.NotificationController.deleteNotifications(userId:Long)
###
# tags: [ Notification ]
# summary: Retrieves Users notification subscriptions
Expand Down

0 comments on commit d2afeaa

Please sign in to comment.