From eb16a396ac367b0f12b89d3211461e3a9a458bd5 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Wed, 11 Feb 2026 11:48:13 +0100 Subject: [PATCH] Endpunkt Erweiterung --- Data/Entities/AiPromptbausteinPrompt.cs | 19 ++++++++++ .../AICore/Facade/AiPromptsApiClient.cs | 25 ++++++++++--- Service/Plugins/AiPromptbausteineService.cs | 36 +++++++++++++------ 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/Data/Entities/AiPromptbausteinPrompt.cs b/Data/Entities/AiPromptbausteinPrompt.cs index f088dcf0b..fb7394a0d 100644 --- a/Data/Entities/AiPromptbausteinPrompt.cs +++ b/Data/Entities/AiPromptbausteinPrompt.cs @@ -58,4 +58,23 @@ namespace BeWo.Data.Entities return (obj.PromptId, obj.ActionType).GetHashCode(); } } + + public class AiPromptbausteinPromptComparer2 : IEqualityComparer + { + public bool Equals(AiPromptbausteinPrompt x, AiPromptbausteinPrompt y) + { + return y is AiPromptbausteinPrompt ent && + x.PromptId == ent.PromptId && + x.Title == ent.Title && + x.Description == ent.Description && + x.OwnsoftRefLink == ent.OwnsoftRefLink && + x.Prompt == ent.Prompt && + x.ActionType == ent.ActionType; + } + + public int GetHashCode(AiPromptbausteinPrompt obj) + { + return (obj.PromptId, obj.ActionType, obj.Title, obj.Description, obj.OwnsoftRefLink, obj.Prompt).GetHashCode(); + } + } } diff --git a/Server/Components/AICore/Facade/AiPromptsApiClient.cs b/Server/Components/AICore/Facade/AiPromptsApiClient.cs index 43d48639c..95d139ab3 100644 --- a/Server/Components/AICore/Facade/AiPromptsApiClient.cs +++ b/Server/Components/AICore/Facade/AiPromptsApiClient.cs @@ -8,6 +8,8 @@ using System.Text; using System.Threading.Tasks; using BS.Shared; using BS.Shared.Interface; +using System.ComponentModel.Design; +using System.Runtime.Remoting.Messaging; namespace AICore.Facade { @@ -24,7 +26,7 @@ namespace AICore.Facade _ErrorExtractor = new DefaultErrorExtractor(); } - public IEnumerable GetAiPrompts() + public IEnumerable GetAiPrompts(AiActionType aiActionType) { var prompts = new List(); @@ -35,7 +37,9 @@ namespace AICore.Facade promptid = "", title = "", prompt = "", - description = "" + description = "", + helpurl = "", + aiactiontype = "" } }; @@ -46,15 +50,28 @@ namespace AICore.Facade return null; } - var data = response.Data.Select(x => new AiPromptbausteinPromptDC() + var data = response.Data.Select(x => new AiPromptbausteinPromptDC() { PromptId = x.promptid, Title = x.title, Description = x.description, Prompt = x.prompt, + OwnsoftRefLink = x.helpurl, + IsOwnsoftPrompt = true, + ActionType = GetAiActionType(x.aiactiontype, aiActionType) }); - return data; + return data.Where(x => x.ActionType == aiActionType); ; + } + + private AiActionType GetAiActionType(string aiactiontype, AiActionType aiActionType) + { + if(Enum.TryParse(aiactiontype, out var result)) + { + return result; + } + + return aiActionType; } } } diff --git a/Service/Plugins/AiPromptbausteineService.cs b/Service/Plugins/AiPromptbausteineService.cs index d502fcc13..5da00ff93 100644 --- a/Service/Plugins/AiPromptbausteineService.cs +++ b/Service/Plugins/AiPromptbausteineService.cs @@ -197,21 +197,37 @@ namespace BeWo.Service.Plugins } private IEnumerable syncOwnSoftPrompts(AiActionType aiActionType) { + var comparer = new AiPromptbausteinPromptPromptIdComparer(); + var comparer2 = new AiPromptbausteinPromptComparer2(); + var current_prompts = DAOFactory.SearchDAO.GetOwnSoftPromptbausteinPrompts(aiActionType); var current_prompts_actives = current_prompts.Where(x => x.IsActive == ActivationTypeId.Active); var current_prompts_deactives = current_prompts.Where(x => x.IsActive != ActivationTypeId.Active); - var actives_prompts = getOwnSoftPrompts(); - - foreach ( var actives in actives_prompts ) - { - actives.ActionType = aiActionType; - } - + var actives_prompts = getOwnSoftPrompts(aiActionType); var request_models = MapperFactory.AiPromptbausteinPrompt.MapToNewEntities(actives_prompts); - var comparer = new AiPromptbausteinPromptPromptIdComparer(); var toadd = request_models.Except(current_prompts, comparer); var toremove = current_prompts_actives.Except(request_models, comparer); var toreadd = current_prompts_deactives.Intersect(request_models, comparer); + //var tocheckupdate = request_models.Union(current_prompts, comparer); + //var toupdate = tocheckupdate.; + + foreach (var a in current_prompts) + { + foreach (var b in request_models) + { + if (!comparer.Equals(a, b)) + continue; + + if(!comparer2.Equals(a, b)) + { + var dc = MapperFactory.AiPromptbausteinPrompt.MapToNewDC(b); + MapperFactory.AiPromptbausteinPrompt.MergeWithEntity(dc, a); + DAOFactory.GenericDAO.Update(a); + } + + break; + } + } DAOFactory.GenericDAO.Insert(toadd); DAOFactory.GenericDAO.Deactivate(toremove); @@ -221,10 +237,10 @@ namespace BeWo.Service.Plugins return prompts; } - private List getOwnSoftPrompts() + private List getOwnSoftPrompts(AiActionType aiActionType) { var client = new AiPromptsApiClient(); - var response = client.GetAiPrompts(); + var response = client.GetAiPrompts(aiActionType); return response?.ToList() ?? new List(); } }