-
-
Notifications
You must be signed in to change notification settings - Fork 30
Add Player.currentAvatar FK and publish avatar update events #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
51e66fc
Add Player.currentAvatar FK and publish avatar update events
Brutus5000 96e58ca
Bump faf-db-migrations to v143 for avatar_id column
Brutus5000 48e6d4b
Deprecate AvatarAssignment.selected in favor of Player.currentAvatar
Brutus5000 68cbf53
Audit Player.currentAvatar changes
Brutus5000 5c356a2
Add push-branch-image.sh for pushing test images
Brutus5000 f8f579b
Validate avatar ownership before assigning currentAvatar
Brutus5000 036e722
Use JUnit Jupiter assertThrows in PlayerAvatarValidationHookTest
Brutus5000 8c8ca0e
Merge remote-tracking branch 'origin/develop' into feat/player-avatar…
Brutus5000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/faforever/api/data/hook/PlayerAvatarUpdateHook.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.faforever.api.data.hook; | ||
|
|
||
| import com.faforever.api.config.RabbitConfiguration; | ||
| import com.faforever.api.data.domain.Avatar; | ||
| import com.faforever.api.data.domain.Player; | ||
| import com.yahoo.elide.annotation.LifeCycleHookBinding.Operation; | ||
| import com.yahoo.elide.annotation.LifeCycleHookBinding.TransactionPhase; | ||
| import com.yahoo.elide.core.lifecycle.LifeCycleHook; | ||
| import com.yahoo.elide.core.security.ChangeSpec; | ||
| import com.yahoo.elide.core.security.RequestScope; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class PlayerAvatarUpdateHook implements LifeCycleHook<Player> { | ||
|
|
||
| public static final String ROUTING_KEY_PLAYER_AVATAR_UPDATE = "success.player_avatar.update"; | ||
|
|
||
| private final RabbitTemplate rabbitTemplate; | ||
|
|
||
| @Override | ||
| public void execute(Operation operation, TransactionPhase phase, Player player, RequestScope requestScope, Optional<ChangeSpec> changes) { | ||
| final Avatar avatar = player.getCurrentAvatar(); | ||
| final Integer avatarId = avatar == null ? null : avatar.getId(); | ||
|
|
||
| Map<String, Object> payload = new HashMap<>(); | ||
| payload.put("player_id", player.getId()); | ||
| payload.put("avatar_id", avatarId); | ||
|
|
||
| log.debug("Publishing player_avatar update: {}", payload); | ||
| rabbitTemplate.convertAndSend( | ||
| RabbitConfiguration.EXCHANGE_FAF_LOBBY, | ||
| ROUTING_KEY_PLAYER_AVATAR_UPDATE, | ||
| payload | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.