-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8069c6d
commit b96d975
Showing
5 changed files
with
124 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace CookingApp.Services.ChatHistory | ||
{ | ||
using CookingApp.Infrastructure.Interfaces; | ||
|
||
public class ChatService : IChatService | ||
{ | ||
private readonly IRepository<Chat> _chatRepository; | ||
|
||
public ChatService(IRepository<Chat> chatRepository) | ||
{ | ||
_chatRepository = chatRepository; | ||
} | ||
|
||
public async Task InsertAsync(Chat chat) | ||
{ | ||
await _chatRepository.InsertAsync(chat); | ||
} | ||
|
||
public async Task<List<Chat>> GetAllChatsAsync() | ||
=> await _chatRepository.GetAllAsync(); | ||
|
||
public async Task<List<Tuple<string, string>>> GetAllByUserId(string userId) | ||
{ | ||
var result = await _chatRepository.GetAllAsync(c => c.UserId == userId); | ||
return result.OrderBy(c => c.CreatedDateTime).Select(c => Tuple.Create(c.Title, c.Id)).ToList(); | ||
} | ||
|
||
public async Task<Chat?> GetByIdAsync(string id) | ||
=> await _chatRepository.GetByIdAsync(id); | ||
|
||
public async Task UpdateAsync(Chat chat) | ||
=> await _chatRepository.UpdateAsync(chat); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/server/CookingApp/Services/ChatService/IChatService.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,15 @@ | ||
namespace CookingApp.Services.ChatHistory | ||
{ | ||
public interface IChatService | ||
{ | ||
Task InsertAsync(Chat chat); | ||
|
||
Task<List<Chat>> GetAllChatsAsync(); | ||
|
||
Task<List<Tuple<string, string>>> GetAllByUserId(string userId); | ||
|
||
Task<Chat?> GetByIdAsync(string id); | ||
|
||
Task UpdateAsync(Chat chat); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace CookingApp.UnitTests.ServiceTests.MongoDB | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
internal class DbTests | ||
{ | ||
} | ||
} |