diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-05-23 12:26:31 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-05-23 12:44:22 -0500 |
| commit | 2ed141e2f55207cce5ab80acc8477402fd5aae94 (patch) | |
| tree | 10bc10b983c637656cb628c242abba4cef3c9307 | |
| parent | c72d7088ce6d39193ae1a80f2808e34d07e6078f (diff) | |
| download | slskd-2ed141e2f55207cce5ab80acc8477402fd5aae94.tar.gz | |
add DbContext and domain for search
| -rw-r--r-- | src/slskd/Core/DbContext.cs | 32 | ||||
| -rw-r--r-- | src/slskd/Core/Search/Domain/Search.cs | 53 | ||||
| -rw-r--r-- | src/slskd/Core/Search/Domain/SearchResponse.cs | 33 | ||||
| -rw-r--r-- | src/slskd/Core/Search/ISearchTracker.cs | 2 | ||||
| -rw-r--r-- | src/slskd/Core/Search/SearchTracker.cs | 4 |
5 files changed, 121 insertions, 3 deletions
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 file="DbContext.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd +{ + using Microsoft.EntityFrameworkCore; + using slskd.Search; + + public class AppDbContext : DbContext + { + public AppDbContext(DbContextOptions<AppDbContext> options) + : base(options) + { + } + + public DbSet<Search.Search> 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 file="Search.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd.Search +{ + using System; + using Soulseek; + + public class Search + { + public Guid Id { get; init; } + + /// <summary> + /// Gets the text for which to search. + /// </summary> + public string SearchText { get; set; } + + /// <summary> + /// Gets the state of the search. + /// </summary> + public SearchStates State { get; set; } + + /// <summary> + /// Gets the unique identifier for the search. + /// </summary> + 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 file="SearchResponse.cs" company="slskd Team"> +// 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/. +// </copyright> + +namespace slskd.Search +{ + using System; + using System.Text.Json; + + /// <summary> + /// A response to a file search. + /// </summary> + public class SearchResponseRecord + { + public Guid SearchId { get; init; } + + public string ResponseJson { get; set; } + public Soulseek.SearchResponse Response => new Lazy<Soulseek.SearchResponse>(() => JsonSerializer.Deserialize<Soulseek.SearchResponse>(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 /// <summary> /// Gets active searches. /// </summary> - ConcurrentDictionary<Guid, Search> Searches { get; } + ConcurrentDictionary<Guid, Soulseek.Search> Searches { get; } /// <summary> /// 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 /// <summary> /// Gets active searches. /// </summary> - public ConcurrentDictionary<Guid, Search> Searches { get; private set; } = - new ConcurrentDictionary<Guid, Search>(); + public ConcurrentDictionary<Guid, Soulseek.Search> Searches { get; private set; } = + new ConcurrentDictionary<Guid, Soulseek.Search>(); /// <summary> /// Adds or updates a tracked search. |
