aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Notifications.java27
1 files changed, 4 insertions, 23 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java b/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
index 48db64be..7b901a15 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Notifications.java
@@ -1,25 +1,18 @@
package com.juick.api.controllers;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.Message;
-import com.juick.User;
import com.juick.Status;
import com.juick.TokensList;
+import com.juick.User;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.service.MessagesService;
import com.juick.service.PushQueriesService;
import com.juick.service.SubscriptionService;
-import com.juick.service.UserService;
import com.juick.util.UserUtils;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.inject.Inject;
import java.io.IOException;
@@ -36,8 +29,6 @@ public class Notifications {
@Inject
PushQueriesService pushQueriesService;
@Inject
- UserService userService;
- @Inject
MessagesService messagesService;
@Inject
SubscriptionService subscriptionService;
@@ -95,17 +86,12 @@ public class Notifications {
@RequestMapping(value = "/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status doDelete(
- @RequestBody String requestBody) throws IOException {
+ @RequestBody TokensList list) throws IOException {
User visitor = UserUtils.getCurrentUser();
// FIXME: it is possible to delete other user's tokens
if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
throw new HttpForbiddenException();
}
- ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
- TokensList list = mapper.readValue(requestBody, TokensList.class);
switch (list.getType()) {
case "gcm":
list.getTokens().forEach(t -> pushQueriesService.deleteGCMToken(t));
@@ -125,16 +111,11 @@ public class Notifications {
@RequestMapping(value = "/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Status doPut(
- @RequestBody String requestBody) throws IOException {
+ @RequestBody TokensList list) throws IOException {
User visitor = UserUtils.getCurrentUser();
if (visitor.getUid() == 0) {
throw new HttpForbiddenException();
}
- ObjectMapper mapper = new ObjectMapper();
- mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
- TokensList list = mapper.readValue(requestBody, TokensList.class);
switch (list.getType()) {
case "gcm":
list.getTokens().forEach(t -> pushQueriesService.addGCMToken(visitor.getUid(), t));