Endpunkt Erweiterung

This commit is contained in:
2026-02-11 11:48:13 +01:00
parent 64af74e711
commit eb16a396ac
3 changed files with 66 additions and 14 deletions

View File

@@ -58,4 +58,23 @@ namespace BeWo.Data.Entities
return (obj.PromptId, obj.ActionType).GetHashCode();
}
}
public class AiPromptbausteinPromptComparer2 : IEqualityComparer<AiPromptbausteinPrompt>
{
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();
}
}
}

View File

@@ -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<AiPromptbausteinPromptDC> GetAiPrompts()
public IEnumerable<AiPromptbausteinPromptDC> GetAiPrompts(AiActionType aiActionType)
{
var prompts = new List<AiPromptbausteinPromptDC>();
@@ -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>(aiactiontype, out var result))
{
return result;
}
return aiActionType;
}
}
}

View File

@@ -197,21 +197,37 @@ namespace BeWo.Service.Plugins
}
private IEnumerable<AiPromptbausteinPrompt> 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<AiPromptbausteinPromptDC> getOwnSoftPrompts()
private List<AiPromptbausteinPromptDC> getOwnSoftPrompts(AiActionType aiActionType)
{
var client = new AiPromptsApiClient();
var response = client.GetAiPrompts();
var response = client.GetAiPrompts(aiActionType);
return response?.ToList() ?? new List<AiPromptbausteinPromptDC>();
}
}