From 7c51747a26f7e9b7511b86cdf3e83f222c53ca0c Mon Sep 17 00:00:00 2001 From: Nick Blakely Date: Sun, 16 Aug 2020 02:03:10 -0700 Subject: [PATCH] Add Discord URI service. --- .../Contracts/V1/AppVersion.cs | 2 +- .../Contracts/V1/DiscordStatus.cs | 7 +++++ .../Contracts/V1/PlayerInfo.cs | 2 +- .../Contracts/V1/ServerInfo.cs | 2 +- .../Contracts/V1/ServerInfoWithHostAddress.cs | 2 +- .../Contracts/V1/VersionInfo.cs | 2 +- Giants.Services/Core/Entities/ServerInfo.cs | 2 +- Giants.Services/Core/Entities/VersionInfo.cs | 2 +- Giants.Services/Core/ServicesModule.cs | 2 ++ Giants.Services/Mapper/Mapper.cs | 9 +++--- Giants.Services/Services/DiscordService.cs | 19 +++++++++++++ Giants.Services/Services/IDiscordService.cs | 7 +++++ .../Services/ServerRegistryCleanupService.cs | 1 - .../Services/ServerRegistryService.cs | 3 -- .../Store/InMemoryServerRegistryStore.cs | 1 - .../Controllers/DiscordController.cs | 28 +++++++++++++++++++ .../Controllers/ServersController.cs | 6 ++-- .../Controllers/VersionController.cs | 5 ++-- Giants.WebApi/appsettings.json | 3 +- 19 files changed, 82 insertions(+), 23 deletions(-) create mode 100644 Giants.DataContract/Contracts/V1/DiscordStatus.cs create mode 100644 Giants.Services/Services/DiscordService.cs create mode 100644 Giants.Services/Services/IDiscordService.cs create mode 100644 Giants.WebApi/Controllers/DiscordController.cs diff --git a/Giants.DataContract/Contracts/V1/AppVersion.cs b/Giants.DataContract/Contracts/V1/AppVersion.cs index cdd7c1f..5bcf9c8 100644 --- a/Giants.DataContract/Contracts/V1/AppVersion.cs +++ b/Giants.DataContract/Contracts/V1/AppVersion.cs @@ -1,4 +1,4 @@ -namespace Giants.DataContract +namespace Giants.DataContract.V1 { using System; using System.ComponentModel.DataAnnotations; diff --git a/Giants.DataContract/Contracts/V1/DiscordStatus.cs b/Giants.DataContract/Contracts/V1/DiscordStatus.cs new file mode 100644 index 0000000..979f794 --- /dev/null +++ b/Giants.DataContract/Contracts/V1/DiscordStatus.cs @@ -0,0 +1,7 @@ +namespace Giants.DataContract.V1 +{ + public class DiscordStatus + { + public string DiscordUri { get; set; } + } +} diff --git a/Giants.DataContract/Contracts/V1/PlayerInfo.cs b/Giants.DataContract/Contracts/V1/PlayerInfo.cs index 3b9c072..f804f64 100644 --- a/Giants.DataContract/Contracts/V1/PlayerInfo.cs +++ b/Giants.DataContract/Contracts/V1/PlayerInfo.cs @@ -1,7 +1,7 @@ using System; using System.ComponentModel.DataAnnotations; -namespace Giants.DataContract +namespace Giants.DataContract.V1 { public class PlayerInfo { diff --git a/Giants.DataContract/Contracts/V1/ServerInfo.cs b/Giants.DataContract/Contracts/V1/ServerInfo.cs index 471642d..31d45a9 100644 --- a/Giants.DataContract/Contracts/V1/ServerInfo.cs +++ b/Giants.DataContract/Contracts/V1/ServerInfo.cs @@ -1,4 +1,4 @@ -namespace Giants.DataContract +namespace Giants.DataContract.V1 { using System; using System.Collections.Generic; diff --git a/Giants.DataContract/Contracts/V1/ServerInfoWithHostAddress.cs b/Giants.DataContract/Contracts/V1/ServerInfoWithHostAddress.cs index f9c24b9..4e4707a 100644 --- a/Giants.DataContract/Contracts/V1/ServerInfoWithHostAddress.cs +++ b/Giants.DataContract/Contracts/V1/ServerInfoWithHostAddress.cs @@ -1,4 +1,4 @@ -namespace Giants.DataContract +namespace Giants.DataContract.V1 { using System; using System.ComponentModel.DataAnnotations; diff --git a/Giants.DataContract/Contracts/V1/VersionInfo.cs b/Giants.DataContract/Contracts/V1/VersionInfo.cs index bf5e3af..983eca6 100644 --- a/Giants.DataContract/Contracts/V1/VersionInfo.cs +++ b/Giants.DataContract/Contracts/V1/VersionInfo.cs @@ -1,4 +1,4 @@ -namespace Giants.DataContract +namespace Giants.DataContract.V1 { using System; using System.ComponentModel.DataAnnotations; diff --git a/Giants.Services/Core/Entities/ServerInfo.cs b/Giants.Services/Core/Entities/ServerInfo.cs index 08e2d92..4fa3530 100644 --- a/Giants.Services/Core/Entities/ServerInfo.cs +++ b/Giants.Services/Core/Entities/ServerInfo.cs @@ -2,7 +2,7 @@ { using System; - public class ServerInfo : DataContract.ServerInfo, IIdentifiable + public class ServerInfo : DataContract.V1.ServerInfo, IIdentifiable { public string id => this.HostIpAddress; diff --git a/Giants.Services/Core/Entities/VersionInfo.cs b/Giants.Services/Core/Entities/VersionInfo.cs index 1064547..a8d24e7 100644 --- a/Giants.Services/Core/Entities/VersionInfo.cs +++ b/Giants.Services/Core/Entities/VersionInfo.cs @@ -2,7 +2,7 @@ namespace Giants.Services { - public class VersionInfo : DataContract.VersionInfo, IIdentifiable + public class VersionInfo : DataContract.V1.VersionInfo, IIdentifiable { public string id => GenerateId(this.AppName); diff --git a/Giants.Services/Core/ServicesModule.cs b/Giants.Services/Core/ServicesModule.cs index 906221d..d438030 100644 --- a/Giants.Services/Core/ServicesModule.cs +++ b/Giants.Services/Core/ServicesModule.cs @@ -1,6 +1,7 @@ namespace Giants.Services { using Giants.Services.Core; + using Giants.Services.Services; using Giants.Services.Store; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; @@ -16,6 +17,7 @@ services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddHostedService(); services.AddHostedService(); diff --git a/Giants.Services/Mapper/Mapper.cs b/Giants.Services/Mapper/Mapper.cs index da35346..7dbd9c7 100644 --- a/Giants.Services/Mapper/Mapper.cs +++ b/Giants.Services/Mapper/Mapper.cs @@ -1,6 +1,7 @@ namespace Giants.Services { using AutoMapper; + using Giants.DataContract.V1; public static class Mapper { @@ -17,10 +18,10 @@ if (Instance == null) { var config = new MapperConfiguration(cfg => { - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); - cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); + cfg.CreateMap(); }); Instance = new AutoMapper.Mapper(config); diff --git a/Giants.Services/Services/DiscordService.cs b/Giants.Services/Services/DiscordService.cs new file mode 100644 index 0000000..7e82786 --- /dev/null +++ b/Giants.Services/Services/DiscordService.cs @@ -0,0 +1,19 @@ +namespace Giants.Services.Services +{ + using Microsoft.Extensions.Configuration; + + public class DiscordService : IDiscordService + { + private readonly IConfiguration configuration; + + public DiscordService(IConfiguration configuration) + { + this.configuration = configuration; + } + + public string GetDiscordUri() + { + return this.configuration["DiscordUri"]; + } + } +} diff --git a/Giants.Services/Services/IDiscordService.cs b/Giants.Services/Services/IDiscordService.cs new file mode 100644 index 0000000..3d80c3e --- /dev/null +++ b/Giants.Services/Services/IDiscordService.cs @@ -0,0 +1,7 @@ +namespace Giants.Services +{ + public interface IDiscordService + { + string GetDiscordUri(); + } +} diff --git a/Giants.Services/Services/ServerRegistryCleanupService.cs b/Giants.Services/Services/ServerRegistryCleanupService.cs index 1d760a1..9837301 100644 --- a/Giants.Services/Services/ServerRegistryCleanupService.cs +++ b/Giants.Services/Services/ServerRegistryCleanupService.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Linq; - using System.Text; using System.Threading; using System.Threading.Tasks; using Giants.Services.Core; diff --git a/Giants.Services/Services/ServerRegistryService.cs b/Giants.Services/Services/ServerRegistryService.cs index ddf2323..dcf13a5 100644 --- a/Giants.Services/Services/ServerRegistryService.cs +++ b/Giants.Services/Services/ServerRegistryService.cs @@ -1,12 +1,9 @@ namespace Giants.Services { using System; - using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; - using Giants.Services.Core; - using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; diff --git a/Giants.Services/Store/InMemoryServerRegistryStore.cs b/Giants.Services/Store/InMemoryServerRegistryStore.cs index 65c6975..88b49cc 100644 --- a/Giants.Services/Store/InMemoryServerRegistryStore.cs +++ b/Giants.Services/Store/InMemoryServerRegistryStore.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; - using System.Net; using System.Threading.Tasks; public class InMemoryServerRegistryStore : IServerRegistryStore diff --git a/Giants.WebApi/Controllers/DiscordController.cs b/Giants.WebApi/Controllers/DiscordController.cs new file mode 100644 index 0000000..9cd513b --- /dev/null +++ b/Giants.WebApi/Controllers/DiscordController.cs @@ -0,0 +1,28 @@ +namespace Giants.WebApi.Controllers +{ + using Giants.DataContract.V1; + using Giants.Services; + using Microsoft.AspNetCore.Mvc; + + [ApiController] + [Route("api/[controller]")] + public class DiscordController : ControllerBase + { + private readonly IDiscordService discordService; + + public DiscordController( + IDiscordService discordService) + { + this.discordService = discordService; + } + + [HttpGet] + public DiscordStatus GetDiscordStatus() + { + return new DiscordStatus + { + DiscordUri = this.discordService.GetDiscordUri() + }; + } + } +} diff --git a/Giants.WebApi/Controllers/ServersController.cs b/Giants.WebApi/Controllers/ServersController.cs index 403600b..e83ae42 100644 --- a/Giants.WebApi/Controllers/ServersController.cs +++ b/Giants.WebApi/Controllers/ServersController.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using AutoMapper; -using Giants.DataContract; +using Giants.DataContract.V1; using Giants.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -44,7 +44,7 @@ namespace Giants.Web.Controllers } [HttpGet] - public async Task> GetServers() + public async Task> GetServers() { IEnumerable serverInfo = await this.serverRegistryService.GetAllServers(); @@ -65,7 +65,7 @@ namespace Giants.Web.Controllers } [HttpPost] - public async Task AddServer([FromBody]DataContract.ServerInfo serverInfo) + public async Task AddServer([FromBody] DataContract.V1.ServerInfo serverInfo) { ArgumentUtility.CheckForNull(serverInfo, nameof(serverInfo)); diff --git a/Giants.WebApi/Controllers/VersionController.cs b/Giants.WebApi/Controllers/VersionController.cs index 2f4b453..b62f39d 100644 --- a/Giants.WebApi/Controllers/VersionController.cs +++ b/Giants.WebApi/Controllers/VersionController.cs @@ -1,6 +1,5 @@ using System.Threading.Tasks; using AutoMapper; -using Giants.DataContract; using Giants.Services; using Microsoft.AspNetCore.Mvc; @@ -22,11 +21,11 @@ namespace Giants.WebApi.Controllers } [HttpGet] - public async Task GetVersionInfo(string appName) + public async Task GetVersionInfo(string appName) { Services.VersionInfo versionInfo = await this.updaterService.GetVersionInfo(appName); - return mapper.Map(versionInfo); + return mapper.Map(versionInfo); } } } diff --git a/Giants.WebApi/appsettings.json b/Giants.WebApi/appsettings.json index 53040ff..2dfca16 100644 --- a/Giants.WebApi/appsettings.json +++ b/Giants.WebApi/appsettings.json @@ -11,5 +11,6 @@ "ContainerId": "DefaultContainer", "ServerTimeoutPeriodInMinutes": "7", "ServerCleanupIntervalInMinutes": "1", - "MaxServerCount": 1000 + "MaxServerCount": 1000, + "DiscordUri": "https://discord.gg/Avj4azU" }