aboutsummaryrefslogtreecommitdiff
path: root/juick-api
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-01 15:06:08 +0300
committerGravatar Vitaly Takmazov2016-12-01 15:06:08 +0300
commita19d224e5de6a067cc559a23cf6b4afdef060d56 (patch)
tree8198e97a3bd7354da2973ad647d99a110cfa69b5 /juick-api
parent3d7f60c1c0b48dad2f58bffe3352d1c5c1b93f00 (diff)
juick-api: Notifications controller from perl, refactoring
Diffstat (limited to 'juick-api')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Notifications.java53
1 files changed, 48 insertions, 5 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 35298095..789adf5f 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
@@ -54,11 +54,11 @@ public class Notifications {
if (uid > 0) {
switch (type) {
case "gcm":
- return ResponseEntity.ok(pushQueriesService.getAndroidRegID(uid));
+ return ResponseEntity.ok(pushQueriesService.getGCMRegID(uid));
case "apns":
return ResponseEntity.ok(pushQueriesService.getAPNSToken(uid));
case "mpns":
- return ResponseEntity.ok(pushQueriesService.getWinPhoneURL(uid));
+ return ResponseEntity.ok(pushQueriesService.getMPNSURL(uid));
default:
throw new HttpBadRequestException();
}
@@ -78,11 +78,11 @@ public class Notifications {
switch (type) {
case "gcm":
- return ResponseEntity.ok(pushQueriesService.getAndroidTokens(uids));
+ return ResponseEntity.ok(pushQueriesService.getGCMTokens(uids));
case "apns":
return ResponseEntity.ok(pushQueriesService.getAPNSTokens(uids));
case "mpns":
- return ResponseEntity.ok(pushQueriesService.getWindowsTokens(uids));
+ return ResponseEntity.ok(pushQueriesService.getMPNSTokens(uids));
default:
throw new HttpBadRequestException();
}
@@ -98,6 +98,7 @@ public class Notifications {
@RequestBody String requestBody) throws IOException {
String name = UserUtils.getUsername(principal, null);
User visitor = userService.getUserByName(name);
+ // FIXME: it is possible to delete other user's tokens
if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
throw new HttpForbiddenException();
}
@@ -106,7 +107,49 @@ public class Notifications {
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
TokensList list = mapper.readValue(requestBody, TokensList.class);
- list.getTokens().forEach(t -> pushQueriesService.deleteAPNSToken(t));
+ switch (list.getType()) {
+ case "gcm":
+ list.getTokens().forEach(t -> pushQueriesService.deleteGCMToken(t));
+ break;
+ case "apns":
+ list.getTokens().forEach(t -> pushQueriesService.deleteAPNSToken(t));
+ break;
+ case "mpns":
+ list.getTokens().forEach(t -> pushQueriesService.deleteMPNSToken(t));
+ break;
+ default:
+ throw new HttpBadRequestException();
+ }
+
+ return Status.OK;
+ }
+ @RequestMapping(value = "/notifications", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+ public Status doPut(
+ Principal principal,
+ @RequestBody String requestBody) throws IOException {
+ String name = UserUtils.getUsername(principal, null);
+ User visitor = userService.getUserByName(name);
+ 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));
+ break;
+ case "apns":
+ list.getTokens().forEach(t -> pushQueriesService.addAPNSToken(visitor.getUid(), t));
+ break;
+ case "mpns":
+ list.getTokens().forEach(t -> pushQueriesService.addMPNSToken(visitor.getUid(), t));
+ break;
+ default:
+ throw new HttpBadRequestException();
+ }
return Status.OK;
}
}