Add endpoint to fetch information on boost badges

This commit is contained in:
Ehren Kret 2021-10-26 14:04:49 -07:00
parent a124b3abe9
commit 24480b2090
2 changed files with 54 additions and 2 deletions

View File

@ -22,15 +22,18 @@ public class BoostConfiguration {
private final long level;
private final Duration expiration;
private final Map<String, List<BigDecimal>> currencies;
private final String badge;
@JsonCreator
public BoostConfiguration(
@JsonProperty("level") long level,
@JsonProperty("expiration") Duration expiration,
@JsonProperty("currencies") final Map<String, List<BigDecimal>> currencies) {
@JsonProperty("currencies") Map<String, List<BigDecimal>> 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;
}
}

View File

@ -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<Long, Level> levels;
@JsonCreator
public GetBoostBadgesResponse(
@JsonProperty("levels") Map<Long, Level> levels) {
this.levels = Objects.requireNonNull(levels);
}
public Map<Long, Level> getLevels() {
return levels;
}
}
@Timed
@GET
@Path("/boost/badges")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public CompletableFuture<Response> getBoostBadges(@Context ContainerRequestContext containerRequestContext) {
return CompletableFuture.supplyAsync(() -> {
long boostLevel = boostConfiguration.getLevel();
String boostBadge = boostConfiguration.getBadge();
List<Locale> 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")