aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/www/api/Notifications.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2021-09-06 22:53:43 +0300
committerGravatar Vitaly Takmazov2021-09-06 22:53:43 +0300
commitf4e913a8adbcb4573efe469d847dbb5506da91ff (patch)
tree94c16a0287d3f658d0d8b01c25f354d87b90a090 /src/main/java/com/juick/www/api/Notifications.java
parentbb1afa817b5547ba56c3b161f4b10bc4bc88aed8 (diff)
Cleanup ResponseEntity usage
Diffstat (limited to 'src/main/java/com/juick/www/api/Notifications.java')
-rw-r--r--src/main/java/com/juick/www/api/Notifications.java27
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