aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-05-23 12:33:27 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-05-23 12:44:23 -0500
commitea78f7f0c5b0858f15a1af8a700100d7ae101ae1 (patch)
treee80b630134f8ce909112b51253acfd1dcd04bdb5 /src
parent7588c5d8281213de2714d817c7e861cc5fb661e7 (diff)
downloadslskd-ea78f7f0c5b0858f15a1af8a700100d7ae101ae1.tar.gz
add SearchDbContext
Diffstat (limited to 'src')
-rw-r--r--src/slskd/API/Controllers/SearchesController.cs2
-rw-r--r--src/slskd/Core/Search/SearchDbContext.cs (renamed from src/slskd/Core/DbContext.cs)11
-rw-r--r--src/slskd/Program.cs10
-rw-r--r--src/slskd/Startup.cs14
4 files changed, 22 insertions, 15 deletions
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
/// <response code="404">A matching search was not found.</response>
[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/Search/SearchDbContext.cs
index ba4e50a6..4832bc17 100644
--- a/src/slskd/Core/DbContext.cs
+++ b/src/slskd/Core/Search/SearchDbContext.cs
@@ -1,4 +1,4 @@
-// <copyright file="DbContext.cs" company="slskd Team">
+// <copyright file="SearchDbContext.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -15,18 +15,17 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
-namespace slskd
+namespace slskd.Search
{
using Microsoft.EntityFrameworkCore;
- using slskd.Search;
- public class AppDbContext : DbContext
+ public class SearchDbContext : DbContext
{
- public AppDbContext(DbContextOptions<AppDbContext> options)
+ public SearchDbContext(DbContextOptions<SearchDbContext> options)
: base(options)
{
}
- public DbSet<Search.Search> Searches { get; set; }
+ public DbSet<Search> 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
@@ -63,11 +63,6 @@ namespace slskd
public static readonly string DefaultConfigurationFile = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.yml");
/// <summary>
- /// The default XML documentation filename.
- /// </summary>
- public static readonly string DefaultXmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml");
-
- /// <summary>
/// The default incomplete download directory.
/// </summary>
public static readonly string DefaultIncompleteDirectory = Path.Combine(DefaultAppDirectory, "incomplete");
@@ -88,6 +83,11 @@ namespace slskd
public static readonly string EnvironmentVariablePrefix = $"{AppName.ToUpperInvariant()}_";
/// <summary>
+ /// The default XML documentation filename.
+ /// </summary>
+ public static readonly string XmlDocumentationFile = Path.Combine(AppContext.BaseDirectory, "etc", $"{AppName}.xml");
+
+ /// <summary>
/// Gets the assembly version of the application.
/// </summary>
/// <remarks>
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<SearchDbContext>(options =>
+ {
+ options.UseSqlite($"Data Source={Path.Combine(Options.Directories.App, "search.db")}");
+ });
+
+ services.AddTransient(p => p.GetRequiredService<IDbContextFactory<SearchDbContext>>().CreateDbContext());
+
services.AddSingleton<ITransferTracker, TransferTracker>();
services.AddSingleton<ISearchTracker, SearchTracker>();
services.AddSingleton<IBrowseTracker, BrowseTracker>();