From 34aa00ddc772fd02a2930677bbb974014af363bb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 May 2021 22:23:33 -0500 Subject: remove annotations from File and Response --- src/slskd/Core/Search/Domain/File.cs | 16 +------ src/slskd/Core/Search/Domain/Response.cs | 51 ++++++++++++++++++++ src/slskd/Core/Search/Domain/Search.cs | 56 +++++++++++----------- src/slskd/Core/Search/Domain/SearchResponse.cs | 66 -------------------------- 4 files changed, 80 insertions(+), 109 deletions(-) create mode 100644 src/slskd/Core/Search/Domain/Response.cs delete mode 100644 src/slskd/Core/Search/Domain/SearchResponse.cs (limited to 'src') diff --git a/src/slskd/Core/Search/Domain/File.cs b/src/slskd/Core/Search/Domain/File.cs index ee14dcff..5ad99986 100644 --- a/src/slskd/Core/Search/Domain/File.cs +++ b/src/slskd/Core/Search/Domain/File.cs @@ -17,19 +17,8 @@ namespace slskd.Search { - using System; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Text.Json.Serialization; - public class File { - [ForeignKey("SearchResponse")] - [JsonIgnore] - public Guid SearchResponseId { get; init; } - - [Key] - public Guid Id { get; init; } public int? BitDepth { get; init; } public int? BitRate { get; init; } public int Code { get; init; } @@ -41,12 +30,10 @@ namespace slskd.Search public long Size { get; init; } public bool IsLocked { get; init; } - public static File FromSoulseekFile(Soulseek.File file, Guid searchResponseId, bool isLocked = false) + public static File FromSoulseekFile(Soulseek.File file) { return new File() { - SearchResponseId = searchResponseId, - Id = Guid.NewGuid(), BitDepth = file.BitDepth, BitRate = file.BitRate, Code = file.Code, @@ -56,7 +43,6 @@ namespace slskd.Search Length = file.Length, SampleRate = file.SampleRate, Size = file.Size, - IsLocked = isLocked, }; } } diff --git a/src/slskd/Core/Search/Domain/Response.cs b/src/slskd/Core/Search/Domain/Response.cs new file mode 100644 index 00000000..a675d62f --- /dev/null +++ b/src/slskd/Core/Search/Domain/Response.cs @@ -0,0 +1,51 @@ +// +// 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.Collections.Generic; + using System.Linq; + + public class Response + { + public int FileCount { get; init; } + public ICollection Files { get; init; } = new List(); + public int FreeUploadSlots { get; init; } + public int LockedFileCount { get; init; } + public ICollection LockedFiles { get; init; } = new List(); + public long QueueLength { get; init; } + public int Token { get; init; } + public int UploadSpeed { get; init; } + public string Username { get; init; } + + public static Response FromSoulseekSearchResponse(Soulseek.SearchResponse searchResponse) + { + return new Response() + { + FileCount = searchResponse.FileCount, + Files = searchResponse.Files.Select(file => File.FromSoulseekFile(file)).ToList(), + FreeUploadSlots = searchResponse.FreeUploadSlots, + LockedFileCount = searchResponse.LockedFileCount, + LockedFiles = searchResponse.LockedFiles.Select(file => File.FromSoulseekFile(file)).ToList(), + QueueLength = searchResponse.QueueLength, + Token = searchResponse.Token, + UploadSpeed = searchResponse.UploadSpeed, + Username = searchResponse.Username, + }; + } + } +} \ No newline at end of file diff --git a/src/slskd/Core/Search/Domain/Search.cs b/src/slskd/Core/Search/Domain/Search.cs index 13f1dd06..74be902f 100644 --- a/src/slskd/Core/Search/Domain/Search.cs +++ b/src/slskd/Core/Search/Domain/Search.cs @@ -20,12 +20,15 @@ namespace slskd.Search using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using System.Text.Json; + using System.Text.Json.Serialization; using Soulseek; public class Search { [Key] - public Guid Id { get; init; } = Guid.NewGuid(); + public Guid Id { get; init; } public DateTime StartedAt { get; init; } = DateTime.UtcNow; public DateTime? EndedAt { get; set; } @@ -33,17 +36,17 @@ namespace slskd.Search /// /// Gets the total number of files contained within received responses. /// - public int FileCount { get; init; } + public int FileCount { get; set; } /// /// Gets the total number of locked files contained within received responses. /// - public int LockedFileCount { get; init; } + public int LockedFileCount { get; set; } /// /// Gets the current number of responses received. /// - public int ResponseCount { get; init; } + public int ResponseCount { get; set; } /// /// Gets the text for which to search. @@ -60,35 +63,32 @@ namespace slskd.Search /// public int Token { get; init; } - public ICollection Responses { get; init; } = new List(); - - public static Search FromSoulseekSearch(Soulseek.Search search) + [JsonIgnore] + public string ResponsesJson { - return new Search() + get => JsonSerializer.Serialize(Responses); + set { - FileCount = search.FileCount, - LockedFileCount = search.LockedFileCount, - ResponseCount = search.ResponseCount, - SearchText = search.SearchText, - State = search.State, - Token = search.Token, - }; + Responses = JsonSerializer.Deserialize>(value); + } } - public Search WithSoulseekSearch(Soulseek.Search search) + [NotMapped] + public IEnumerable Responses { get; set; } = new List(); + + public Search UpdateFromSoulseekSearch(Soulseek.Search search) { - return new Search() - { - Id = Id, - StartedAt = StartedAt, - EndedAt = EndedAt, - FileCount = search.FileCount, - LockedFileCount = search.LockedFileCount, - ResponseCount = search.ResponseCount, - SearchText = SearchText, - State = search.State, - Token = Token, - }; + FileCount = search.FileCount; + LockedFileCount = search.LockedFileCount; + ResponseCount = search.ResponseCount; + State = search.State; + return this; + } + + public Search AddResponses(List responses) + { + Responses = responses; + return this; } } } diff --git a/src/slskd/Core/Search/Domain/SearchResponse.cs b/src/slskd/Core/Search/Domain/SearchResponse.cs deleted file mode 100644 index 894fe96c..00000000 --- a/src/slskd/Core/Search/Domain/SearchResponse.cs +++ /dev/null @@ -1,66 +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.Search -{ - using System; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Linq; - using System.Text.Json.Serialization; - - public class SearchResponse - { - [ForeignKey("Search")] - [JsonIgnore] - public Guid SearchId { get; init; } - - [Key] - public Guid Id { get; init; } = Guid.NewGuid(); - public int FileCount { get; init; } - public ICollection Files { get; init; } = new List(); - public int FreeUploadSlots { get; init; } - public int LockedFileCount { get; init; } - public long QueueLength { get; init; } - public int Token { get; init; } - public int UploadSpeed { get; init; } - public string Username { get; init; } - - public static SearchResponse FromSoulseekSearchResponse(Soulseek.SearchResponse searchResponse, Guid searchId) - { - var id = Guid.NewGuid(); - - var files = searchResponse.Files.Select(file => File.FromSoulseekFile(file, id, isLocked: false)).ToList(); - files.AddRange(searchResponse.LockedFiles.Select(file => File.FromSoulseekFile(file, id, isLocked: true))); - - return new SearchResponse() - { - SearchId = searchId, - Id = id, - FileCount = searchResponse.FileCount, - Files = files, - FreeUploadSlots = searchResponse.FreeUploadSlots, - LockedFileCount = searchResponse.LockedFileCount, - QueueLength = searchResponse.QueueLength, - Token = searchResponse.Token, - UploadSpeed = searchResponse.UploadSpeed, - Username = searchResponse.Username, - }; - } - } -} \ No newline at end of file -- cgit v1.2.3