-
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::DAL): Add implementation of ChatSessionRepository
- Loading branch information
1 parent
aafee55
commit 0ef449a
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/Server/StellarChat.Server.Api/DAL/Mongo/Documents/Chat/ChatSessionDocument.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,13 @@ | ||
using StellarChat.Shared.Infrastructure.DAL.Mongo; | ||
|
||
namespace StellarChat.Server.Api.DAL.Mongo.Documents.Chat; | ||
|
||
internal class ChatSessionDocument : IIdentifiable<Guid> | ||
{ | ||
public Guid Id { get; set; } | ||
public string Title { get; set; } = string.Empty; | ||
public string Metaprompt { get; set; } = string.Empty; | ||
public HashSet<string> ActivePlugins { get; set; } = new(); | ||
public DateTimeOffset CreatedAt { get; set; } | ||
public DateTimeOffset UpdatedAt { get; set; } | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Server/StellarChat.Server.Api/DAL/Mongo/Repositories/Chat/ChatSessionRepository.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,35 @@ | ||
using Mapster; | ||
using StellarChat.Server.Api.DAL.Mongo.Documents.Chat; | ||
using StellarChat.Server.Api.Domain.Chat.Models; | ||
using StellarChat.Server.Api.Domain.Chat.Repositories; | ||
using StellarChat.Shared.Infrastructure.DAL.Mongo; | ||
|
||
namespace StellarChat.Server.Api.DAL.Mongo.Repositories.Chat; | ||
|
||
internal class ChatSessionRepository : IChatSessionRepository | ||
{ | ||
private readonly IMongoRepository<ChatSessionDocument, Guid> _repository; | ||
|
||
public ChatSessionRepository(IMongoRepository<ChatSessionDocument, Guid> repository) => _repository = repository; | ||
|
||
public async ValueTask<ChatSession?> GetAsync(Guid id) | ||
=> (await _repository.GetAsync(id)).Adapt<ChatSession>(); | ||
|
||
public async ValueTask<ChatSession?> GetByTitleAsync(string title) | ||
=> (await _repository.GetAsync(document => document.Title == title)).Adapt<ChatSession>(); | ||
|
||
public async ValueTask<IEnumerable<ChatSession>> BrowseAsync() | ||
=> (await _repository.FindAsync(_ => true)).Adapt<IEnumerable<ChatSession>>(); | ||
|
||
public async ValueTask AddAsync(ChatSession chatSession) | ||
=> await _repository.AddAsync(chatSession.Adapt<ChatSessionDocument>()); | ||
|
||
public async ValueTask UpdateAsync(ChatSession chatSession) | ||
=> await _repository.UpdateAsync(chatSession.Adapt<ChatSessionDocument>()); | ||
|
||
public async ValueTask DeleteAsync(Guid id) | ||
=> await _repository.DeleteAsync(id); | ||
|
||
public async ValueTask<bool> ExistsAsync(Guid id) | ||
=> await _repository.ExistsAsync(document => document.Id == id); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/Server/StellarChat.Server.Api/Domain/Chat/Repositories/IChatSessionRepository.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,14 @@ | ||
using StellarChat.Server.Api.Domain.Chat.Models; | ||
|
||
namespace StellarChat.Server.Api.Domain.Chat.Repositories; | ||
|
||
internal interface IChatSessionRepository | ||
{ | ||
ValueTask<ChatSession?> GetAsync(Guid id); | ||
ValueTask<ChatSession?> GetByTitleAsync(string title); | ||
ValueTask<IEnumerable<ChatSession>> BrowseAsync(); | ||
ValueTask AddAsync(ChatSession chatSession); | ||
ValueTask UpdateAsync(ChatSession chatSession); | ||
ValueTask DeleteAsync(Guid id); | ||
ValueTask<bool> ExistsAsync(Guid 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