mirror of
https://github.com/Govor-team/Govor.git
synced 2026-09-17 16:22:49 +00:00
3c785d5c89
Migrate codebase to use SmartRes Result<T, Error> (and Unit) across services and interfaces, replacing previous Result usage and updating many method signatures and implementations. Add ResultExtensions to convert SmartRes results to ASP.NET ActionResult and refactor AuthController to use functional Bind/Tap chains for registration/login flows. Upgrade projects to .NET 10 and bump related NuGet packages; add libs/SmartRes.dll and project references. Simplify DbContext registration to use Npgsql only with retry policies and enable detailed logging. Update Swagger/launch settings and other minor fixes (AutoMapper registration change, whitespace/exception handling, and removal of the Govor.ConsoleClient files).
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using Govor.Domain;
|
|
using Govor.Domain.Common;
|
|
using Govor.Domain.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SmartRes;
|
|
|
|
namespace Govor.Application.PrivateUserChats;
|
|
|
|
public class UserPrivateChatsGetter : IUserPrivateChatsGetterService
|
|
{
|
|
private readonly GovorDbContext _context;
|
|
|
|
public UserPrivateChatsGetter(GovorDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<List<PrivateChat>> GetUserChatsAsync(Guid userId)
|
|
{
|
|
return await _context.PrivateChats
|
|
.AsNoTracking()
|
|
.Where(p => p.UserAId == userId || p.UserBId == userId)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<Result<PrivateChat, Error>> GetPrivateChatAsync(Guid chatId)
|
|
{
|
|
var res = await _context.PrivateChats.AsNoTracking()
|
|
.FirstOrDefaultAsync(p => p.Id == chatId);
|
|
|
|
if (res == null)
|
|
return Result.Failure<PrivateChat>(
|
|
Error.Failure(
|
|
nameof(InvalidOperationException),
|
|
"PrivateChat not found.")
|
|
);
|
|
|
|
return res;
|
|
}
|
|
|
|
public async Task<bool> ExistChatAsync(Guid userIdA, Guid userIdB)
|
|
{
|
|
return await _context.PrivateChats
|
|
.AsNoTracking()
|
|
.AnyAsync(p => (p.UserAId == userIdA && p.UserBId == userIdB) ||
|
|
(p.UserBId == userIdA && p.UserAId == userIdB)
|
|
);
|
|
}
|
|
} |