From c88fc414b96c8bab5de4bd018bb106e2d80e6c5f Mon Sep 17 00:00:00 2001 From: sdcb Date: Fri, 6 Dec 2024 18:44:36 +0800 Subject: [PATCH] possible models --- .../Controllers/Admin/ModelKeys/Dtos/PossibleModelDto.cs | 3 +++ .../Controllers/Admin/ModelKeys/ModelKeysController.cs | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/BE/Controllers/Admin/ModelKeys/Dtos/PossibleModelDto.cs b/src/BE/Controllers/Admin/ModelKeys/Dtos/PossibleModelDto.cs index 9fe97ea1..4413ad59 100644 --- a/src/BE/Controllers/Admin/ModelKeys/Dtos/PossibleModelDto.cs +++ b/src/BE/Controllers/Admin/ModelKeys/Dtos/PossibleModelDto.cs @@ -13,6 +13,9 @@ public record PossibleModelDto [JsonPropertyName("isExists")] public required bool IsExists { get; init; } + [JsonPropertyName("deploymentName")] + public required string? DeploymentName { get; init; } + [JsonPropertyName("isLegacy")] public required bool IsLegacy { get; init; } } diff --git a/src/BE/Controllers/Admin/ModelKeys/ModelKeysController.cs b/src/BE/Controllers/Admin/ModelKeys/ModelKeysController.cs index 2b2ab0b8..7671d926 100644 --- a/src/BE/Controllers/Admin/ModelKeys/ModelKeysController.cs +++ b/src/BE/Controllers/Admin/ModelKeys/ModelKeysController.cs @@ -195,20 +195,19 @@ public async Task> ListModelKeyPossibleModels(s return NotFound(); } - HashSet existingModelRefIds = modelKey.Models - .Select(x => x.ModelReferenceId) - .ToHashSet(); - PossibleModelDto[] readyRefs = await db.ModelReferences .Where(x => x.ProviderId == modelKey.ModelProviderId) .OrderBy(x => x.Name) .Select(x => new PossibleModelDto() { - IsExists = x.Models.Any(m => m.ModelKeyId == modelKeyId), + DeploymentName = x.Models.FirstOrDefault(m => m.ModelKeyId == modelKeyId)!.DeploymentName, ReferenceId = x.Id, ReferenceName = x.Name, IsLegacy = x.IsLegacy, + IsExists = x.Models.Any(m => m.ModelKeyId == modelKeyId), }) + .OrderBy(x => (x.IsLegacy ? 1 : 0) + (x.IsExists ? 2 : 0)) + .ThenByDescending(x => x.ReferenceId) .ToArrayAsync(cancellationToken); return Ok(readyRefs);