Skip to content

Commit

Permalink
Merge pull request #43 from spacecowboy-app/nullability-improvements/1
Browse files Browse the repository at this point in the history
General service code improvements
  • Loading branch information
rolfmichelsen committed Aug 23, 2023
2 parents 013626b + d84adea commit 5f7d7d8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion service/src/Controllers/DTO/Errors/ErrorDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ErrorDetails
/// <summary>
/// The session identifier related to this problem, or <code>null</code>
/// </summary>
public string SessionId { get; init; }
public string? SessionId { get; init; }

/// <summary>
/// The participant identifier related to this problem, or <code>null</code>
Expand Down
11 changes: 4 additions & 7 deletions service/src/Controllers/Hubs/SessionHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
limitations under the License.
*/

using AutoMapper;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Spacecowboy.Service.Controllers.DTO;
Expand All @@ -33,14 +32,12 @@ public class SessionHub: Hub

private readonly ILogger<SessionHub> log;
private readonly ISessionRepository repo;
private readonly IMapper map;


public SessionHub(ILogger<SessionHub> log, ISessionRepository repo, IMapper map)
public SessionHub(ILogger<SessionHub> log, ISessionRepository repo)
{
this.log = log;
this.repo = repo;
this.map = map;
}


Expand All @@ -54,7 +51,7 @@ public override async Task OnConnectedAsync()


/// <inheritdoc/>
public override async Task OnDisconnectedAsync(Exception exception)
public override async Task OnDisconnectedAsync(Exception? exception)
{
await Clients.Caller.SendAsync(EventMessage, "Disconnected from service hub");
await base.OnDisconnectedAsync(exception);
Expand Down Expand Up @@ -116,8 +113,8 @@ public async Task ParticipantHeartbeat(string sessionId, Guid participantId)
/// Return session information to a client
/// </summary>
/// <param name="sessionId">Session identifier</param>
/// <returns>Session information or null on error</returns>
public async Task<SessionResponse> GetSession(string sessionId)
/// <returns>Session information or <code>null</code> on error</returns>
public async Task<SessionResponse?> GetSession(string sessionId)
{
if (repo == null)
{
Expand Down
5 changes: 1 addition & 4 deletions service/src/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Prometheus;
using Spacecowboy.Service.Controllers.DTO;
using Spacecowboy.Service.Controllers.DTO.Errors;
Expand Down Expand Up @@ -62,15 +61,13 @@ public class SessionController : ControllerBase

private readonly ILogger<SessionController> log;
private readonly IMapper map;
private readonly ServiceOptions options;
private readonly ISessionRepository repository;
private readonly IHubContext<SessionHub> sessionHub;

public SessionController(ILogger<SessionController> log, ISessionRepository repository, IMapper map, IOptions<ServiceOptions> options, IHubContext<SessionHub> hub)
public SessionController(ILogger<SessionController> log, ISessionRepository repository, IMapper map, IHubContext<SessionHub> hub)
{
this.log = log ?? throw new ArgumentNullException(nameof(log));
this.map = map ?? throw new ArgumentNullException(nameof(map));
this.options = options.Value ?? throw new ArgumentNullException(nameof(options));
this.repository = repository ?? throw new ArgumentNullException(nameof(repository));
this.sessionHub = hub;

Expand Down
11 changes: 6 additions & 5 deletions service/src/Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
<RootNamespace>Spacecowboy.Service</RootNamespace>
<PackageId>Spacecowboy.Service</PackageId>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>spacecowboy-api.xml</DocumentationFile>
<NoWarn>1591;1701;1702</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -33,11 +34,11 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
<PackageReference Include="prometheus-net" Version="8.0.0" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="prometheus-net" Version="8.0.1" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.2.2" />
<PackageReference Include="StackExchange.Redis" Version="2.6.122" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
Expand Down
9 changes: 6 additions & 3 deletions service/src/ServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

namespace Spacecowboy.Service
{
public class ServiceOptions
/// <summary>
/// Service configuration options.
/// </summary>
public record ServiceOptions
{
public const string Service = "Spacecowboy";

Expand All @@ -26,11 +29,11 @@ public class ServiceOptions
/// <remarks>
/// Valid values are "redis" and "memory".
/// </remarks>
public string RepositoryType { get; set; }
public string? RepositoryType { get; init; }

/// <summary>
/// Name of this instance of the service. Each running instance has a unique name.
/// </summary>
public string InstanceName { get; set; }
public string? InstanceName { get; init; }
}
}
2 changes: 1 addition & 1 deletion service/test/Controller/ParticipantApiTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ParticipantApiTest()

var options = new ServiceOptions();

controller = new SessionController(logger, repository, mapper, Options.Create<ServiceOptions>(options), null);
controller = new SessionController(logger, repository, mapper, null);
}


Expand Down
3 changes: 1 addition & 2 deletions service/test/Controller/SessionControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Spacecowboy.Service.Controllers;
using Spacecowboy.Service.Controllers.DTO;
using Spacecowboy.Service.Controllers.DTO.Errors;
Expand Down Expand Up @@ -61,7 +60,7 @@ public SessionControllerTest()

var options = new ServiceOptions();

controller = new SessionController(logger, repository, mapper, Options.Create<ServiceOptions>(options), null);
controller = new SessionController(logger, repository, mapper, null);
}


Expand Down
12 changes: 7 additions & 5 deletions service/test/Service.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
<Authors>Rolf Michelsen and Tami Weiss</Authors>

<Copyright>Copyright 2021-2023 Rolf Michelsen and Tami Weiss</Copyright>

<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 5f7d7d8

Please sign in to comment.