Skip to content

Commit

Permalink
fix(badges): Mongo field is 'badges', not 'badge'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Apr 8, 2024
1 parent 62e9147 commit fab9fab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/app/badge/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *serviceImpl) RemoveBadgeFromPlayer(ctx context.Context, playerId uuid.U
player.ActiveBadge = s.calculateActiveBadge(player.Badges)
}

s.log.Debugw("Updating badge", "playerId", playerId, "badge", player.Badges, "activeBadge", player.ActiveBadge)
s.log.Debugw("Updating badge", "playerId", playerId, "badges", player.Badges, "activeBadge", player.ActiveBadge)
if err := s.repo.UpdatePlayerBadgesAndActive(ctx, playerId, player.Badges, player.ActiveBadge); err != nil {
return fmt.Errorf("failed to update player: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/repository/mongo_badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (m *mongoRepository) UpdatePlayerBadgesAndActive(ctx context.Context, playe
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

update := bson.M{"$set": bson.M{"badge": badges}}
update := bson.M{"$set": bson.M{"badges": badges}}
if activeBadge != nil {
update["$set"].(bson.M)["activeBadge"] = activeBadge
} else {
Expand All @@ -49,7 +49,7 @@ func (m *mongoRepository) AddPlayerBadge(ctx context.Context, playerId uuid.UUID
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

result, err := m.playerCollection.UpdateOne(ctx, bson.M{"_id": playerId}, bson.M{"$addToSet": bson.M{"badge": badgeId}})
result, err := m.playerCollection.UpdateOne(ctx, bson.M{"_id": playerId}, bson.M{"$addToSet": bson.M{"badges": badgeId}})
if err != nil {
return 0, err
}
Expand All @@ -61,7 +61,7 @@ func (m *mongoRepository) RemovePlayerBadge(ctx context.Context, playerId uuid.U
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

result, err := m.playerCollection.UpdateOne(ctx, bson.M{"_id": playerId}, bson.M{"$pull": bson.M{"badge": badgeId}})
result, err := m.playerCollection.UpdateOne(ctx, bson.M{"_id": playerId}, bson.M{"$pull": bson.M{"badges": badgeId}})
if err != nil {
return 0, err
}
Expand Down

0 comments on commit fab9fab

Please sign in to comment.