Add category to badges
This commit is contained in:
parent
ce3835e176
commit
08c6a8c2e5
|
@ -263,3 +263,4 @@ badges:
|
||||||
badges:
|
badges:
|
||||||
- id: TEST
|
- id: TEST
|
||||||
imageUrl: https://example.com/test-badge
|
imageUrl: https://example.com/test-badge
|
||||||
|
category: other
|
||||||
|
|
|
@ -90,11 +90,15 @@ public class ConfiguredProfileBadgeConverter implements ProfileBadgeConverter {
|
||||||
.filter(accountBadge -> accountBadge.isVisible()
|
.filter(accountBadge -> accountBadge.isVisible()
|
||||||
&& now.isBefore(accountBadge.getExpiration())
|
&& now.isBefore(accountBadge.getExpiration())
|
||||||
&& knownBadges.containsKey(accountBadge.getId()))
|
&& knownBadges.containsKey(accountBadge.getId()))
|
||||||
.map(accountBadge -> new Badge(
|
.map(accountBadge -> {
|
||||||
accountBadge.getId(),
|
BadgeConfiguration configuration = knownBadges.get(accountBadge.getId());
|
||||||
knownBadges.get(accountBadge.getId()).getImageUrl(),
|
return new Badge(
|
||||||
resourceBundle.getString(accountBadge.getId() + "_name"),
|
accountBadge.getId(),
|
||||||
resourceBundle.getString(accountBadge.getId() + "_description")))
|
configuration.getCategory(),
|
||||||
|
configuration.getImageUrl(),
|
||||||
|
resourceBundle.getString(accountBadge.getId() + "_name"),
|
||||||
|
resourceBundle.getString(accountBadge.getId() + "_description"));
|
||||||
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,16 @@ import javax.validation.constraints.NotNull;
|
||||||
public class BadgeConfiguration {
|
public class BadgeConfiguration {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final URL imageUrl;
|
private final URL imageUrl;
|
||||||
|
private final String category;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public BadgeConfiguration(
|
public BadgeConfiguration(
|
||||||
@JsonProperty("id") final String id,
|
@JsonProperty("id") final String id,
|
||||||
@JsonProperty("imageUrl") @JsonDeserialize(converter = URLDeserializationConverter.class) final URL imageUrl) {
|
@JsonProperty("imageUrl") @JsonDeserialize(converter = URLDeserializationConverter.class) final URL imageUrl,
|
||||||
|
@JsonProperty("category") final String category) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.imageUrl = imageUrl;
|
this.imageUrl = imageUrl;
|
||||||
|
this.category = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
|
@ -35,4 +38,9 @@ public class BadgeConfiguration {
|
||||||
public URL getImageUrl() {
|
public URL getImageUrl() {
|
||||||
return imageUrl;
|
return imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotEmpty
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
public class Badge {
|
public class Badge {
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private final String category;
|
||||||
private final URL imageUrl;
|
private final URL imageUrl;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
@ -19,10 +20,12 @@ public class Badge {
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public Badge(
|
public Badge(
|
||||||
@JsonProperty("id") final String id,
|
@JsonProperty("id") final String id,
|
||||||
|
@JsonProperty("category") final String category,
|
||||||
@JsonProperty("imageUrl") final URL imageUrl,
|
@JsonProperty("imageUrl") final URL imageUrl,
|
||||||
@JsonProperty("name") final String name,
|
@JsonProperty("name") final String name,
|
||||||
@JsonProperty("description") final String description) {
|
@JsonProperty("description") final String description) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.category = category;
|
||||||
this.imageUrl = imageUrl;
|
this.imageUrl = imageUrl;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
@ -32,6 +35,10 @@ public class Badge {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
public URL getImageUrl() {
|
public URL getImageUrl() {
|
||||||
return imageUrl;
|
return imageUrl;
|
||||||
}
|
}
|
||||||
|
@ -53,13 +60,14 @@ public class Badge {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Badge badge = (Badge) o;
|
Badge badge = (Badge) o;
|
||||||
return Objects.equals(id, badge.id) && Objects.equals(imageUrl,
|
return Objects.equals(id, badge.id) && Objects.equals(category,
|
||||||
badge.imageUrl) && Objects.equals(name, badge.name) && Objects.equals(
|
badge.category) && Objects.equals(imageUrl, badge.imageUrl)
|
||||||
description, badge.description);
|
&& Objects.equals(name, badge.name) && Objects.equals(description,
|
||||||
|
badge.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, imageUrl, name, description);
|
return Objects.hash(id, category, imageUrl, name, description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class ConfiguredProfileBadgeConverterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BadgeConfiguration newBadge(int i) {
|
private static BadgeConfiguration newBadge(int i) {
|
||||||
return new BadgeConfiguration(idFor(i), imageUrlFor(i));
|
return new BadgeConfiguration(idFor(i), imageUrlFor(i), "other");
|
||||||
}
|
}
|
||||||
|
|
||||||
private BadgesConfiguration createBadges(int count) {
|
private BadgesConfiguration createBadges(int count) {
|
||||||
|
@ -140,7 +140,7 @@ public class ConfiguredProfileBadgeConverterTest {
|
||||||
arguments(idFor(0), expired, false, null),
|
arguments(idFor(0), expired, false, null),
|
||||||
arguments(idFor(0), notExpired, false, null),
|
arguments(idFor(0), notExpired, false, null),
|
||||||
arguments(idFor(0), expired, true, null),
|
arguments(idFor(0), expired, true, null),
|
||||||
arguments(idFor(0), notExpired, true, new Badge(idFor(0), imageUrlFor(0), nameFor(0), desriptionFor(0))),
|
arguments(idFor(0), notExpired, true, new Badge(idFor(0), "other", imageUrlFor(0), nameFor(0), desriptionFor(0))),
|
||||||
arguments(idFor(1), expired, false, null),
|
arguments(idFor(1), expired, false, null),
|
||||||
arguments(idFor(1), notExpired, false, null),
|
arguments(idFor(1), notExpired, false, null),
|
||||||
arguments(idFor(1), expired, true, null),
|
arguments(idFor(1), expired, true, null),
|
||||||
|
|
|
@ -104,7 +104,7 @@ class ProfileControllerTest {
|
||||||
(acceptableLanguages, accountBadges) -> {
|
(acceptableLanguages, accountBadges) -> {
|
||||||
try {
|
try {
|
||||||
return List.of(
|
return List.of(
|
||||||
new Badge("TEST1", new URL("https://example.com/badge/1"), "Test Badge", "This badge is in unit tests.")
|
new Badge("TEST1", "other", new URL("https://example.com/badge/1"), "Test Badge", "This badge is in unit tests.")
|
||||||
);
|
);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
|
|
Loading…
Reference in New Issue