-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code(API::GetChatSession): Implement GetChatSession feature
- Loading branch information
1 parent
c312ac3
commit 98f0da8
Showing
10 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/Server/StellarChat.Server.Api/DAL/Mongo/Exceptions/Chat/ChatSessionNotFoundException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using StellarChat.Shared.Abstractions.Exceptions; | ||
|
||
namespace StellarChat.Server.Api.DAL.Mongo.Exceptions.Chat; | ||
|
||
internal sealed class ChatSessionNotFoundException : StellarChatException | ||
{ | ||
public Guid Id { get; } | ||
public string? Title { get; } | ||
|
||
public ChatSessionNotFoundException(Guid id) | ||
: base( | ||
message: $"Chat session with ID: {id} not found.", | ||
userMessage: $"The requested chat session could not be found.") | ||
=> Id = id; | ||
|
||
public ChatSessionNotFoundException(string title) | ||
: base( | ||
message: $"Chat session with title: {title} not found.", | ||
userMessage: $"The chat session with the title '{title}' could not be found.") | ||
=> Title = title; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Server/StellarChat.Server.Api/Features/Chat/GetChatSession/GetChatSession.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Mediator; | ||
using StellarChat.Shared.Abstractions.Contracts.Chat; | ||
|
||
namespace StellarChat.Server.Api.Features.Chat.GetChatSession; | ||
|
||
internal sealed record GetChatSession : IQuery<ChatSessionResponse> | ||
{ | ||
public Guid Id { get; set; } | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Server/StellarChat.Server.Api/Features/Chat/GetChatSession/GetChatSessionEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Mediator; | ||
using StellarChat.Shared.Abstractions.API.Endpoints; | ||
using StellarChat.Shared.Abstractions.Contracts.Chat; | ||
|
||
namespace StellarChat.Server.Api.Features.Chat.GetChatSession; | ||
|
||
internal sealed class GetChatSessionEndpoint : IEndpoint | ||
{ | ||
public void Expose(IEndpointRouteBuilder endpoints) | ||
{ | ||
var chatHistory = endpoints.MapGroup("/chat-history").WithTags("Chat history"); | ||
|
||
chatHistory.MapGet("/sessions/{chatId:guid}", async (Guid chatId, IMediator mediator) => IEndpoint.Select(await mediator.Send(new GetChatSession { Id = chatId }))) | ||
.Produces<ChatSessionResponse>(StatusCodes.Status200OK) | ||
.Produces(StatusCodes.Status404NotFound) | ||
.WithName("GetChatSession") | ||
.WithOpenApi(operation => new(operation) | ||
{ | ||
Summary = "Retrieves a single chat session by 'chatId'." | ||
}); | ||
} | ||
|
||
public void Register(IServiceCollection services, IConfiguration configuration) { } | ||
|
||
public void Use(IApplicationBuilder app) { } | ||
} |
19 changes: 19 additions & 0 deletions
19
src/Server/StellarChat.Server.Api/Features/Chat/GetChatSession/GetChatSessionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Mapster; | ||
using Mediator; | ||
using StellarChat.Server.Api.DAL.Mongo.Exceptions.Chat; | ||
using StellarChat.Server.Api.Domain.Chat.Repositories; | ||
using StellarChat.Shared.Abstractions.Contracts.Chat; | ||
|
||
namespace StellarChat.Server.Api.Features.Chat.GetChatSession; | ||
|
||
internal sealed class GetChatSessionHandler : IQueryHandler<GetChatSession, ChatSessionResponse> | ||
{ | ||
private readonly IChatSessionRepository _chatSessionRepository; | ||
|
||
public GetChatSessionHandler(IChatSessionRepository chatSessionRepository) | ||
=> _chatSessionRepository = chatSessionRepository; | ||
|
||
public async ValueTask<ChatSessionResponse> Handle(GetChatSession query, CancellationToken cancellationToken) | ||
=> (await _chatSessionRepository.GetAsync(query.Id)) | ||
.Adapt<ChatSessionResponse>() ?? throw new ChatSessionNotFoundException(query.Id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/Shared/StellarChat.Shared.Abstractions/Contracts/Chat/ChatSessionResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace StellarChat.Shared.Abstractions.Contracts.Chat; | ||
|
||
public record ChatSessionResponse(Guid Id, string Title, string Metaprompt, HashSet<string> ActivePlugins, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters