Skip to content

Commit

Permalink
CB-30 Add ApiActionNodeModel with mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
izzat5233 committed Jan 6, 2025
1 parent fdb7f52 commit f972f74
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ChatbotBuilderApi.Application.Graphs.Nodes.ApiAction;
using ChatbotBuilderApi.Presentation.Graphs.Metas;
using ChatbotBuilderApi.Presentation.Graphs.Ports;
using Riok.Mapperly.Abstractions;

namespace ChatbotBuilderApi.Presentation.Graphs.Nodes.ApiAction;

[Mapper]
public static partial class ApiActionNodeMapper
{
public static ApiActionNodeModel ToModel(this ApiActionNodeDto dto)
{
return new ApiActionNodeModel(
dto.Info.ToModel(),
dto.Visual.ToModel(),
dto.UrlInputPort.ToModel(),
dto.HttpMethod,
dto.Headers,
dto.BodyInputPort?.ToModel(),
dto.ResponseOutputPort.ToModel());
}

public static ApiActionNodeDto ToDto(this ApiActionNodeModel model)
{
return new ApiActionNodeDto(
model.Info.ToDomain(),
model.Visual.ToDomain(),
model.UrlInputPort.ToDto(),
model.HttpMethod,
model.Headers,
model.BodyInputPort?.ToDto(),
model.ResponseOutputPort.ToDto());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ChatbotBuilderApi.Application.Graphs.Nodes;
using ChatbotBuilderApi.Domain.Graphs.Abstract.Services;
using ChatbotBuilderApi.Presentation.Graphs.Metas;
using ChatbotBuilderApi.Presentation.Graphs.Ports;

namespace ChatbotBuilderApi.Presentation.Graphs.Nodes.ApiAction;

/// <summary>
/// API Action node model:
/// <list type="bullet">
/// <item>Executes an API call when activated.</item>
/// <item>The endpoint can be dynamic, constructed from an input port.</item>
/// <item>Requires details about the HTTP method, headers, and body.</item>
/// <item>Has an output port to pass along the API response.</item>
/// </list>
/// </summary>
/// <param name="Info">Generic information for the node.</param>
/// <param name="Visual">Visual information for the node.</param>
/// <param name="UrlInputPort">Text input port for the API endpoint URL.</param>
/// <param name="HttpMethod">The HTTP method to use (GET, POST, PUT, DELETE, etc.).</param>
/// <param name="Headers">Optional dictionary of headers to include in the API call.</param>
/// <param name="BodyInputPort">Optional input port for the request body.</param>
/// <param name="ResponseOutputPort">Output port for the API response. Must be of text data type.</param>
public sealed record ApiActionNodeModel(
InfoMetaModel Info,
VisualMetaModel Visual,
InputPortModel UrlInputPort,
ApiActionHttpMethod HttpMethod,
IReadOnlyDictionary<string, string>? Headers,
InputPortModel? BodyInputPort,
OutputPortModel ResponseOutputPort)
: NodeModel(Info, Visual, NodeType.ApiAction);
3 changes: 3 additions & 0 deletions ChatbotBuilderApi.Presentation/Graphs/Nodes/NodeModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ChatbotBuilderApi.Application.Graphs.Nodes;
using ChatbotBuilderApi.Presentation.Graphs.Metas;
using ChatbotBuilderApi.Presentation.Graphs.Nodes.ApiAction;
using ChatbotBuilderApi.Presentation.Graphs.Nodes.Interaction;
using ChatbotBuilderApi.Presentation.Graphs.Nodes.Prompt;
using ChatbotBuilderApi.Presentation.Graphs.Nodes.Static;
Expand All @@ -15,11 +16,13 @@ namespace ChatbotBuilderApi.Presentation.Graphs.Nodes;
[JsonSubtypes.KnownSubType(typeof(PromptNodeModel), NodeType.Prompt)]
[JsonSubtypes.KnownSubType(typeof(InteractionNodeModel), NodeType.Interaction)]
[JsonSubtypes.KnownSubType(typeof(SwitchNodeModel), NodeType.Switch)]
[JsonSubtypes.KnownSubType(typeof(ApiActionNodeModel), NodeType.ApiAction)]
[SwaggerDiscriminator(nameof(NodeType))]
[SwaggerSubType(typeof(StaticNodeModel), DiscriminatorValue = nameof(NodeType.Static))]
[SwaggerSubType(typeof(PromptNodeModel), DiscriminatorValue = nameof(NodeType.Prompt))]
[SwaggerSubType(typeof(InteractionNodeModel), DiscriminatorValue = nameof(NodeType.Interaction))]
[SwaggerSubType(typeof(SwitchNodeModel), DiscriminatorValue = nameof(NodeType.Switch))]
[SwaggerSubType(typeof(ApiActionNodeModel), DiscriminatorValue = nameof(NodeType.ApiAction))]
public abstract record NodeModel(
InfoMetaModel Info,
VisualMetaModel Visual,
Expand Down

0 comments on commit f972f74

Please sign in to comment.