From ea78f7f0c5b0858f15a1af8a700100d7ae101ae1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 May 2021 12:33:27 -0500 Subject: add SearchDbContext --- src/slskd/API/Controllers/SearchesController.cs | 2 +- src/slskd/Core/DbContext.cs | 32 ------------------------- src/slskd/Core/Search/SearchDbContext.cs | 31 ++++++++++++++++++++++++ src/slskd/Program.cs | 10 ++++---- src/slskd/Startup.cs | 14 ++++++++--- 5 files changed, 48 insertions(+), 41 deletions(-) delete mode 100644 src/slskd/Core/DbContext.cs create mode 100644 src/slskd/Core/Search/SearchDbContext.cs (limited to 'src') diff --git a/src/slskd/API/Controllers/SearchesController.cs b/src/slskd/API/Controllers/SearchesController.cs index 4a3dc7ab..6d322bda 100644 --- a/src/slskd/API/Controllers/SearchesController.cs +++ b/src/slskd/API/Controllers/SearchesController.cs @@ -102,7 +102,7 @@ namespace slskd.API.Controllers /// A matching search was not found. [HttpGet("{id}")] [Authorize] - [ProducesResponseType(typeof(Search), 200)] + [ProducesResponseType(typeof(Soulseek.Search), 200)] [ProducesResponseType(404)] public IActionResult GetById([FromRoute]Guid id) { diff --git a/src/slskd/Core/DbContext.cs b/src/slskd/Core/DbContext.cs deleted file mode 100644 index ba4e50a6..00000000 --- a/src/slskd/Core/DbContext.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -namespace slskd -{ - using Microsoft.EntityFrameworkCore; - using slskd.Search; - - public class AppDbContext : DbContext - { - public AppDbContext(DbContextOptions options) - : base(options) - { - } - - public DbSet Searches { get; set; } - } -} diff --git a/src/slskd/Core/Search/SearchDbContext.cs b/src/slskd/Core/Search/SearchDbContext.cs new file mode 100644 index 00000000..4832bc17 --- /dev/null +++ b/src/slskd/Core/Search/SearchDbContext.cs @@ -0,0 +1,31 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Search +{ + using Microsoft.EntityFrameworkCore; + + public class SearchDbContext : DbContext + { + public SearchDbContext(DbContextOptions options) + : base(options) + { + } + + public DbSet Searches { get; set; } + } +} diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 7a526fb2..7ccebe6e 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -62,11 +62,6 @@ namespace slskd /// public static readonly string DefaultConfigurationFile = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.yml"); - /// - /// The default XML documentation filename. - /// - public static readonly string DefaultXmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml"); - /// /// The default incomplete download directory. /// @@ -87,6 +82,11 @@ namespace slskd /// public static readonly string EnvironmentVariablePrefix = $"{AppName.ToUpperInvariant()}_"; + /// + /// The default XML documentation filename. + /// + public static readonly string XmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml"); + /// /// Gets the assembly version of the application. /// diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index f073117c..bd2e8963 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -24,6 +24,7 @@ namespace slskd using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.ApiExplorer; + using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -149,13 +150,13 @@ namespace slskd Version = "v0", }); - if (File.Exists(Program.DefaultXmlDocumentationFile)) + if (File.Exists(Program.XmlDocumentationFile)) { - options.IncludeXmlComments(Program.DefaultXmlDocumentationFile); + options.IncludeXmlComments(Program.XmlDocumentationFile); } else { - logger.Warning($"Unable to find XML documentation in {Program.DefaultXmlDocumentationFile}, Swagger will not include metadata"); + logger.Warning($"Unable to find XML documentation in {Program.XmlDocumentationFile}, Swagger will not include metadata"); } }); } @@ -165,6 +166,13 @@ namespace slskd services.AddSystemMetrics(); } + services.AddDbContextFactory(options => + { + options.UseSqlite($"Data Source={Path.Combine(Options.Directories.App, "search.db")}"); + }); + + services.AddTransient(p => p.GetRequiredService>().CreateDbContext()); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); -- cgit v1.2.3