From 2ed141e2f55207cce5ab80acc8477402fd5aae94 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 23 May 2021 12:26:31 -0500 Subject: add DbContext and domain for search --- src/slskd/Core/DbContext.cs | 32 ++++++++++++++++ src/slskd/Core/Search/Domain/Search.cs | 53 ++++++++++++++++++++++++++ src/slskd/Core/Search/Domain/SearchResponse.cs | 33 ++++++++++++++++ src/slskd/Core/Search/ISearchTracker.cs | 2 +- src/slskd/Core/Search/SearchTracker.cs | 4 +- 5 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 src/slskd/Core/DbContext.cs create mode 100644 src/slskd/Core/Search/Domain/Search.cs create mode 100644 src/slskd/Core/Search/Domain/SearchResponse.cs (limited to 'src') diff --git a/src/slskd/Core/DbContext.cs b/src/slskd/Core/DbContext.cs new file mode 100644 index 00000000..ba4e50a6 --- /dev/null +++ b/src/slskd/Core/DbContext.cs @@ -0,0 +1,32 @@ +// +// 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/Domain/Search.cs b/src/slskd/Core/Search/Domain/Search.cs new file mode 100644 index 00000000..10cbdc9d --- /dev/null +++ b/src/slskd/Core/Search/Domain/Search.cs @@ -0,0 +1,53 @@ +// +// 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 System; + using Soulseek; + + public class Search + { + public Guid Id { get; init; } + + /// + /// Gets the text for which to search. + /// + public string SearchText { get; set; } + + /// + /// Gets the state of the search. + /// + public SearchStates State { get; set; } + + /// + /// Gets the unique identifier for the search. + /// + public int Token { get; set; } + + public static Search FromSoulseekSearch(Soulseek.Search s) + { + return new Search + { + Id = Guid.NewGuid(), + SearchText = s.SearchText, + State = s.State, + Token = s.Token, + }; + } + } +} diff --git a/src/slskd/Core/Search/Domain/SearchResponse.cs b/src/slskd/Core/Search/Domain/SearchResponse.cs new file mode 100644 index 00000000..b9bafc7b --- /dev/null +++ b/src/slskd/Core/Search/Domain/SearchResponse.cs @@ -0,0 +1,33 @@ +// +// 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 System; + using System.Text.Json; + + /// + /// A response to a file search. + /// + public class SearchResponseRecord + { + public Guid SearchId { get; init; } + + public string ResponseJson { get; set; } + public Soulseek.SearchResponse Response => new Lazy(() => JsonSerializer.Deserialize(ResponseJson)).Value; + } +} \ No newline at end of file diff --git a/src/slskd/Core/Search/ISearchTracker.cs b/src/slskd/Core/Search/ISearchTracker.cs index c2bdcbaa..c962138e 100644 --- a/src/slskd/Core/Search/ISearchTracker.cs +++ b/src/slskd/Core/Search/ISearchTracker.cs @@ -29,7 +29,7 @@ namespace slskd.Search /// /// Gets active searches. /// - ConcurrentDictionary Searches { get; } + ConcurrentDictionary Searches { get; } /// /// Adds or updates a tracked search. diff --git a/src/slskd/Core/Search/SearchTracker.cs b/src/slskd/Core/Search/SearchTracker.cs index c4f124ca..b1ab2b18 100644 --- a/src/slskd/Core/Search/SearchTracker.cs +++ b/src/slskd/Core/Search/SearchTracker.cs @@ -29,8 +29,8 @@ namespace slskd.Search /// /// Gets active searches. /// - public ConcurrentDictionary Searches { get; private set; } = - new ConcurrentDictionary(); + public ConcurrentDictionary Searches { get; private set; } = + new ConcurrentDictionary(); /// /// Adds or updates a tracked search. -- cgit v1.2.3