diff --git a/src/Services/ListenTogether/ListenTogether.Application/Grains/RoomGrain.cs b/src/Services/ListenTogether/ListenTogether.Application/Grains/RoomGrain.cs index f286ae6..91d809d 100644 --- a/src/Services/ListenTogether/ListenTogether.Application/Grains/RoomGrain.cs +++ b/src/Services/ListenTogether/ListenTogether.Application/Grains/RoomGrain.cs @@ -6,52 +6,52 @@ using Orleans.Runtime; namespace ListenTogether.Application.Grains { - public class RoomGrain : Grain, IRoomGrain + public sealed class RoomGrain : Grain, IRoomGrain { - IPersistentState Room { get; set; } - public ILogger Logger { get; } + private readonly IPersistentState _room; + private readonly ILogger _logger; public RoomGrain([PersistentState("room", "roomStorage")] IPersistentState room, ILogger logger) { - Room = room; - Logger = logger; + _room = room; + _logger = logger; } public async Task JoinRoom(string connectionId, string userName) { - Logger.LogInformation($"User {userName} is joining {Room.State.Code}, listening to {Room.State.Episode.Show.Title}"); - Room.State.AddUser(new User(connectionId, userName)); - await Room.WriteStateAsync(); - return Room.State; + _logger.LogInformation($"User {userName} is joining {_room.State.Code}, listening to {_room.State.Episode.Show.Title}"); + _room.State.AddUser(new User(connectionId, userName)); + await _room.WriteStateAsync(); + return _room.State; } public async Task LeaveRoom(string connectionId) { - var user = Room.State.Users.First(x => x.ConnectionId == connectionId); - Logger.LogInformation($"User {user.Name} is joining {Room.State.Code}, listening to {Room.State.Episode.Show.Title}"); - Room.State.RemoveUser(connectionId); - await Room.WriteStateAsync(); + var user = _room.State.Users.First(_ => _.ConnectionId == connectionId); + _logger.LogInformation($"User {user.Name} is joining {_room.State.Code}, listening to {_room.State.Episode.Show.Title}"); + _room.State.RemoveUser(connectionId); + await _room.WriteStateAsync(); - if(Room.State.Users.Count == 0) + if (_room.State.Users.Count is 0) { base.DeactivateOnIdle(); } - return Room.State; + return _room.State; } public async Task SetRoom(Room room) { - Room.State = room; - await Room.WriteStateAsync(); + _room.State = room; + await _room.WriteStateAsync(); } public Task UpdatePlayerState(TimeSpan seconds, PlayerState playerState) { - Logger.LogInformation($"Updating player state to {playerState} at {seconds}."); - Room.State.UpdatePlayerState(seconds, playerState); - return Task.FromResult(Room.State); + _logger.LogInformation($"Updating player state to {playerState} at {seconds}."); + _room.State.UpdatePlayerState(seconds, playerState); + return Task.FromResult(_room.State); } } } diff --git a/src/Services/ListenTogether/ListenTogether.Application/Interfaces/IRoomGrain.cs b/src/Services/ListenTogether/ListenTogether.Application/Interfaces/IRoomGrain.cs index 2350b10..7cc28a6 100644 --- a/src/Services/ListenTogether/ListenTogether.Application/Interfaces/IRoomGrain.cs +++ b/src/Services/ListenTogether/ListenTogether.Application/Interfaces/IRoomGrain.cs @@ -1,13 +1,12 @@ using ListenTogether.Domain; using Orleans; -namespace ListenTogether.Application.Interfaces +namespace ListenTogether.Application.Interfaces; + +public interface IRoomGrain : IGrainWithStringKey { - public interface IRoomGrain : IGrainWithStringKey - { - Task SetRoom(Room room); - Task JoinRoom(string connectionId, string userName); - Task LeaveRoom(string connectionId); - Task UpdatePlayerState(TimeSpan seconds, PlayerState playerState); - } + Task SetRoom(Room room); + Task JoinRoom(string connectionId, string userName); + Task LeaveRoom(string connectionId); + Task UpdatePlayerState(TimeSpan seconds, PlayerState playerState); } diff --git a/src/Services/ListenTogether/ListenTogether.Domain/Room.cs b/src/Services/ListenTogether/ListenTogether.Domain/Room.cs index 0887dc3..eb6c890 100644 --- a/src/Services/ListenTogether/ListenTogether.Domain/Room.cs +++ b/src/Services/ListenTogether/ListenTogether.Domain/Room.cs @@ -4,7 +4,7 @@ public class Room { private const int Length = 5; private const string ValidCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - private readonly Random _randGenerator = new(); + private readonly Random _randGenerator = Random.Shared; public Room () { diff --git a/src/Services/Podcasts/Podcast.Ingestion.Worker/PodcastIngestionHandler.cs b/src/Services/Podcasts/Podcast.Ingestion.Worker/PodcastIngestionHandler.cs index 5671b1b..160e67a 100644 --- a/src/Services/Podcasts/Podcast.Ingestion.Worker/PodcastIngestionHandler.cs +++ b/src/Services/Podcasts/Podcast.Ingestion.Worker/PodcastIngestionHandler.cs @@ -28,7 +28,7 @@ public class PodcastIngestionHandler : IPodcastIngestionHandler CancellationToken stoppingToken) { _logger.LogInformation($"The show {title} at {url} was received by the ingestion worker."); - var isExistingShow = await _podcastDbContext.Feeds.AnyAsync(feed => feed.Url.ToLower() == url.ToLower(), stoppingToken); + var isExistingShow = await _podcastDbContext.Feeds.AnyAsync(feed => string.Equals(feed.Url, url, StringComparison.OrdinalIgnoreCase), stoppingToken); if (isExistingShow) return; @@ -37,19 +37,9 @@ public class PodcastIngestionHandler : IPodcastIngestionHandler if (!isAcceptedTopic) { _logger.LogInformation($"The show {title} at {url} was not automatically approved."); - var categoryStringArray = string.Empty; - foreach (var cat in feedCategories) - { - categoryStringArray += $"{cat},"; - } - - if(categoryStringArray.Contains(",")) - { - categoryStringArray = categoryStringArray.Substring(0, categoryStringArray.LastIndexOf(',')); - } - // Must be manually approved - var userFeed = new UserSubmittedFeed(title, url, categoryStringArray); + var userFeed = new UserSubmittedFeed( + title, url, string.Join(",", feedCategories)); await _podcastDbContext.UserSubmittedFeeds.AddAsync(userFeed, stoppingToken); await _podcastDbContext.SaveChangesAsync(stoppingToken); _logger.LogInformation($"The show {title} at {url} was saved as a user-submitted feed.");