aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-12-21 03:26:49 +0300
committerGravatar Vitaly Takmazov2022-12-21 03:26:49 +0300
commitcf437e3004149efe3b65e80d618374eb28cca641 (patch)
tree328147d3209d9a4330c1576c9acb4c2b6cc358b6 /src/main
parent1ad1b73a7b85e7e907de1870991a8849487f9543 (diff)
external tokens: adopt records
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/juick/TwitterManager.java2
-rw-r--r--src/main/java/com/juick/model/ExternalToken.java37
-rw-r--r--src/main/java/com/juick/www/api/Notifications.java24
3 files changed, 14 insertions, 49 deletions
diff --git a/src/main/java/com/juick/TwitterManager.java b/src/main/java/com/juick/TwitterManager.java
index a6a53e6c..f4cab89b 100644
--- a/src/main/java/com/juick/TwitterManager.java
+++ b/src/main/java/com/juick/TwitterManager.java
@@ -55,7 +55,7 @@ public class TwitterManager implements NotificationListener {
status += " http://juick.com/" + jmsg.getMid();
var twitter = Twitter.newBuilder()
.oAuthConsumer(twitter_consumer_key, twitter_consumer_secret)
- .oAuthAccessToken(t.getToken(), t.getSecret()).build();
+ .oAuthAccessToken(t.token(), t.secret()).build();
try {
twitter.v1().tweets().updateStatus(status);
} catch (Exception e) {
diff --git a/src/main/java/com/juick/model/ExternalToken.java b/src/main/java/com/juick/model/ExternalToken.java
index 65a07e55..12f5388c 100644
--- a/src/main/java/com/juick/model/ExternalToken.java
+++ b/src/main/java/com/juick/model/ExternalToken.java
@@ -17,48 +17,13 @@
package com.juick.model;
-import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Created by vitalyster on 22.11.2016.
*/
-public class ExternalToken {
- private final String name;
- private final String type;
- private final String token;
- private final String secret;
-
- @JsonCreator
- public ExternalToken(@JsonProperty("name") String name,
+public record ExternalToken(@JsonProperty("name") String name,
@JsonProperty("type") String type,
@JsonProperty("token") String token,
@JsonProperty("secret") String secret) {
- this.name = name;
- this.type = type;
- this.token = token;
- this.secret = secret;
- if (this.type == null) {
- throw new IllegalStateException("Token must have type");
- }
- if (this.token == null) {
- throw new IllegalStateException("Token must have value");
- }
- }
-
- public String getType() {
- return type;
- }
-
- public String getToken() {
- return token;
- }
-
- public String getName() {
- return name;
- }
-
- public String getSecret() {
- return secret;
- }
}
diff --git a/src/main/java/com/juick/www/api/Notifications.java b/src/main/java/com/juick/www/api/Notifications.java
index 43465c1a..5f941ba5 100644
--- a/src/main/java/com/juick/www/api/Notifications.java
+++ b/src/main/java/com/juick/www/api/Notifications.java
@@ -133,15 +133,15 @@ public class Notifications {
throw new HttpForbiddenException();
}
list.forEach(t -> {
- switch (t.getType()) {
+ switch (t.type()) {
case "gcm":
- pushQueriesService.deleteGCMToken(t.getToken());
+ pushQueriesService.deleteGCMToken(t.token());
break;
case "apns":
- pushQueriesService.deleteAPNSToken(t.getToken());
+ pushQueriesService.deleteAPNSToken(t.token());
break;
case "mpns":
- pushQueriesService.deleteMPNSToken(t.getToken());
+ pushQueriesService.deleteMPNSToken(t.token());
break;
default:
throw new HttpBadRequestException();
@@ -159,15 +159,15 @@ public class Notifications {
throw new HttpForbiddenException();
}
list.forEach(t -> {
- switch (t.getType()) {
+ switch (t.type()) {
case "gcm":
- pushQueriesService.deleteGCMToken(t.getToken());
+ pushQueriesService.deleteGCMToken(t.token());
break;
case "apns":
- pushQueriesService.deleteAPNSToken(t.getToken());
+ pushQueriesService.deleteAPNSToken(t.token());
break;
case "mpns":
- pushQueriesService.deleteMPNSToken(t.getToken());
+ pushQueriesService.deleteMPNSToken(t.token());
break;
default:
throw new HttpBadRequestException();
@@ -183,15 +183,15 @@ public class Notifications {
@Visitor User visitor,
@RequestBody List<ExternalToken> list) {
list.forEach(t -> {
- switch (t.getType()) {
+ switch (t.type()) {
case "gcm":
- pushQueriesService.addGCMToken(visitor.getUid(), t.getToken());
+ pushQueriesService.addGCMToken(visitor.getUid(), t.token());
break;
case "apns":
- pushQueriesService.addAPNSToken(visitor.getUid(), t.getToken());
+ pushQueriesService.addAPNSToken(visitor.getUid(), t.token());
break;
case "mpns":
- pushQueriesService.addMPNSToken(visitor.getUid(), t.getToken());
+ pushQueriesService.addMPNSToken(visitor.getUid(), t.token());
break;
default:
throw new HttpBadRequestException();