diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BoostConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BoostConfiguration.java index 9a4cb010c..d8f7c2df8 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BoostConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/BoostConfiguration.java @@ -22,15 +22,18 @@ public class BoostConfiguration { private final long level; private final Duration expiration; private final Map> currencies; + private final String badge; @JsonCreator public BoostConfiguration( @JsonProperty("level") long level, @JsonProperty("expiration") Duration expiration, - @JsonProperty("currencies") final Map> currencies) { + @JsonProperty("currencies") Map> currencies, + @JsonProperty("badge") String badge) { this.level = level; this.expiration = expiration; this.currencies = currencies; + this.badge = badge; } public long getLevel() { @@ -47,4 +50,9 @@ public class BoostConfiguration { public Map<@NotEmpty String, @Valid @ExactlySize(6) List<@DecimalMin("0.01") @NotNull BigDecimal>> getCurrencies() { return currencies; } + + @NotEmpty + public String getBadge() { + return badge; + } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java index 55cdd26c2..062ab541e 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/SubscriptionController.java @@ -92,7 +92,7 @@ public class SubscriptionController { public SubscriptionController( @Nonnull Clock clock, @Nonnull SubscriptionConfiguration subscriptionConfiguration, - @Nonnull final BoostConfiguration boostConfiguration, + @Nonnull BoostConfiguration boostConfiguration, @Nonnull SubscriptionManager subscriptionManager, @Nonnull StripeManager stripeManager, @Nonnull ServerZkReceiptOperations zkReceiptOperations, @@ -399,6 +399,50 @@ public class SubscriptionController { }); } + public static class GetBoostBadgesResponse { + public static class Level { + private final Badge badge; + + @JsonCreator + public Level( + @JsonProperty("badge") Badge badge) { + this.badge = badge; + } + + public Badge getBadge() { + return badge; + } + } + + private final Map levels; + + @JsonCreator + public GetBoostBadgesResponse( + @JsonProperty("levels") Map levels) { + this.levels = Objects.requireNonNull(levels); + } + + public Map getLevels() { + return levels; + } + } + + @Timed + @GET + @Path("/boost/badges") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public CompletableFuture getBoostBadges(@Context ContainerRequestContext containerRequestContext) { + return CompletableFuture.supplyAsync(() -> { + long boostLevel = boostConfiguration.getLevel(); + String boostBadge = boostConfiguration.getBadge(); + List acceptableLanguages = getAcceptableLanguagesForRequest(containerRequestContext); + GetBoostBadgesResponse getBoostBadgesResponse = new GetBoostBadgesResponse(Map.of(boostLevel, + new GetBoostBadgesResponse.Level(badgeTranslator.translate(acceptableLanguages, boostBadge)))); + return Response.ok(getBoostBadgesResponse).build(); + }); + } + @Timed @GET @Path("/boost/amounts")