Skip to content

Commit

Permalink
Merge pull request #149 from Daggerpov/event-color-not-everyone-tag
Browse files Browse the repository at this point in the history
`FullFeedEventDTO`: using any friend tag that isn't "Everyone" for its color
  • Loading branch information
Daggerpov authored Feb 7, 2025
2 parents c01d3d2 + e02904e commit e657251
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -219,12 +217,26 @@ public List<FullFriendTagDTO> convertFriendTagsToFullFriendTags(List<FriendTagDT
@Override
public FriendTagDTO getPertainingFriendTagByUserIds(UUID ownerUserId, UUID friendUserId) {
// Fetch all friend tags for the owner
return getFriendTagsByOwnerId(ownerUserId).stream()
ArrayList<FriendTagDTO> friendTags = new ArrayList<>(getFriendTagsByOwnerId(ownerUserId).stream()
// Filter to include only friend tags where friendUserId exists in friendUserIds
.filter(friendTag -> friendTag.friendUserIds().contains(friendUserId))
// Return the first matching friend tag, or throw an exception if none is found
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No friend tag found containing the specified friendUserId."));
.toList());

// if there's more than just the 'everyone' tag, don't use that one
if (friendTags.size() > 1) friendTags.removeIf(FriendTagDTO::isEveryone);

// arbitrarily grab the first tag that isn't the 'everyone' tag
try {
Optional<FriendTagDTO> friendTag = friendTags.stream().findFirst();
if (friendTag.isPresent()) { // just null-checking
return friendTag.get();
} else {
throw new BaseNotFoundException(EntityType.FriendTag, friendUserId);
}
} catch (Exception e) {
logger.log(e.getMessage());
throw e;
}
}

@Override
Expand Down

0 comments on commit e657251

Please sign in to comment.