Skip to content

Commit

Permalink
Enrich clan with URL
Browse files Browse the repository at this point in the history
  • Loading branch information
micheljung committed May 1, 2017
1 parent 7f48cee commit fdeb55e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/faforever/api/clan/ClanService.java
Expand Up @@ -100,7 +100,7 @@ public String generatePlayerInvitationToken(Player requester, int newMemberId, i
}

long expire = Instant.now()
.plus(fafApiProperties.getClan().getInviteLinkExpireDurationInMinutes(), ChronoUnit.MINUTES)
.plus(fafApiProperties.getClan().getInviteLinkExpireDurationMinutes(), ChronoUnit.MINUTES)
.toEpochMilli();

return jwtService.sign(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/faforever/api/config/FafApiProperties.java
Expand Up @@ -117,7 +117,8 @@ public static class FeaturedMods {

@Data
public static class Clan {
private long inviteLinkExpireDurationInMinutes = Duration.ofDays(3).toMinutes();
private long inviteLinkExpireDurationMinutes = Duration.ofDays(3).toMinutes();
private String websiteUrlFormat;
}

@Data
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/faforever/api/data/domain/Clan.java
@@ -1,7 +1,9 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.IsClanLeader;
import com.faforever.api.data.listeners.ClanEnricherListener;
import com.faforever.api.data.validation.IsLeaderInClan;
import com.yahoo.elide.annotation.ComputedAttribute;
import com.yahoo.elide.annotation.CreatePermission;
import com.yahoo.elide.annotation.DeletePermission;
import com.yahoo.elide.annotation.Include;
Expand All @@ -13,6 +15,7 @@
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
Expand All @@ -34,6 +37,7 @@
@CreatePermission(expression = "Prefab.Role.All")
@Setter
@IsLeaderInClan
@EntityListeners(ClanEnricherListener.class)
public class Clan {

private int id;
Expand All @@ -45,6 +49,7 @@ public class Clan {
private Player leader;
private String description;
private String tagColor;
private String websiteUrl;
private List<ClanMembership> memberships;

@Id
Expand Down Expand Up @@ -111,4 +116,9 @@ public String getTagColor() {
public List<ClanMembership> getMemberships() {
return this.memberships;
}

@ComputedAttribute
public String getWebsiteUrl() {
return websiteUrl;
}
}
@@ -0,0 +1,24 @@
package com.faforever.api.data.listeners;

import com.faforever.api.config.FafApiProperties;
import com.faforever.api.data.domain.Clan;
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import javax.persistence.PostLoad;

@Component
public class ClanEnricherListener {

private static FafApiProperties fafApiProperties;

@Inject
public void init(FafApiProperties fafApiProperties) {
ClanEnricherListener.fafApiProperties = fafApiProperties;
}

@PostLoad
public void enrich(Clan clan) {
clan.setWebsiteUrl(String.format(fafApiProperties.getClan().getWebsiteUrlFormat(), clan.getId()));
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config/application-dev.yml
Expand Up @@ -41,6 +41,8 @@ faf-api:
modName: fafdevelop
modFilesExtension: nx5
replaceExisting: true
clan:
website-url-format: ${CLAN_WEBSITE_URL_FORMAT:http://clans.test.faforever.com/clan/%s}

spring:
datasource:
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application-prod.yml
Expand Up @@ -44,6 +44,8 @@ faf-api:
activation-url-format: ${ACTIVATION_URL_FORMAT}
mail:
mandrill-api-key: ${MANDRILL_API_KEY}
clan:
website-url-format: ${CLAN_WEBSITE_URL_FORMAT}

spring:
datasource:
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config/application.yml
Expand Up @@ -6,6 +6,8 @@ faf-api:
from-name: Forged Alliance Forever
link-expiration-seconds: 86400
html-format: <p>Dear %1$s,</p><p>welcome to the Forged Alliance Forever community. Please visit the following link to activate your account:</p><p><a href="%2$s">%2$s</a></p><p>-- The Forged Alliance Forever team.</p>
clan:
invite-link-expire-duration-minutes: ${CLAN_INVITE_LINK_EXPIRE_DURATION_MINUTES:3}

spring:
application:
Expand Down

0 comments on commit fdeb55e

Please sign in to comment.