diff options
Diffstat (limited to 'src/main/java/com/juick/www/api/Notifications.java')
-rw-r--r-- | src/main/java/com/juick/www/api/Notifications.java | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java index 524e4da4..d00fe4ca 100644 --- a/src/main/java/com/juick/www/api/Notifications.java +++ b/src/main/java/com/juick/www/api/Notifications.java @@ -23,6 +23,7 @@ import com.juick.model.Status; import com.juick.model.User; import com.juick.model.AnonymousUser; import com.juick.util.HttpBadRequestException; +import com.juick.util.HttpForbiddenException; import com.juick.service.MessagesService; import com.juick.service.PushQueriesService; import com.juick.service.SubscriptionService; @@ -33,9 +34,7 @@ import io.swagger.v3.oas.annotations.Hidden; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; 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; @@ -86,17 +85,17 @@ public class Notifications { @Hidden @RequestMapping(value = "/api/notifications", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<List<User>> doGet( + public List<User> doGet( @Visitor User visitor, @RequestParam(required = false, defaultValue = "0") int uid, @RequestParam(required = false, defaultValue = "0") int mid, @RequestParam(required = false, defaultValue = "0") int rid) { if (!(visitor.getName().equals(serviceUser))) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null); + throw new HttpForbiddenException(); } if (uid > 0 && mid == 0) { // PM - return ResponseEntity.ok(Collections.singletonList(collectTokens(uid))); + return Collections.singletonList(collectTokens(uid)); } else { if (mid > 0) { // reply @@ -114,22 +113,22 @@ public class Notifications { users = subscriptionService.getSubscribedUsers(msg.getUser().getUid(), msg); } - return ResponseEntity.ok(users.stream().map(User::getUid) - .map(this::collectTokens).collect(Collectors.toList())); + return users.stream().map(User::getUid) + .map(this::collectTokens).collect(Collectors.toList()); } else { // read - return ResponseEntity.ok(Collections.singletonList(collectTokens(uid))); + return Collections.singletonList(collectTokens(uid)); } } } @Hidden @RequestMapping(value = "/api/notifications", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<Status> doDelete( + public Status doDelete( @Visitor User visitor, @RequestBody List<ExternalToken> list) { if (!visitor.getName().equals(serviceUser)) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null); + throw new HttpForbiddenException(); } list.forEach(t -> { switch (t.getType()) { @@ -147,15 +146,15 @@ public class Notifications { } }); - return ResponseEntity.ok(Status.OK); + return Status.OK; } @Hidden @RequestMapping(value = "/api/notifications/delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<Status> doDeleteTokens( + public Status doDeleteTokens( @Visitor User visitor, @RequestBody List<ExternalToken> list) { if (!visitor.getName().equals(serviceUser)) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).body(null); + throw new HttpForbiddenException(); } list.forEach(t -> { switch (t.getType()) { @@ -173,7 +172,7 @@ public class Notifications { } }); - return ResponseEntity.ok(Status.OK); + return Status.OK; } @Hidden |