using Femto.Common.Domain; using Femto.Modules.Auth.Application.Dto; using Femto.Modules.Auth.Data; using Femto.Modules.Auth.Infrastructure; using Femto.Modules.Auth.Models; using Microsoft.EntityFrameworkCore; namespace Femto.Modules.Auth.Application.Services; internal class AuthService(AuthContext context, SessionStorage storage) : IAuthService { public async Task GetUserWithCredentials( string username, string password, CancellationToken cancellationToken = default ) { return await context .Users.Where(u => u.Username == username) .Select(u => new UserInfo(u.Id, u.Username, u.Roles.Select(r => r.Role).ToList())) .SingleOrDefaultAsync(cancellationToken); } public Task GetUserWithId(Guid? userId, CancellationToken cancellationToken) { return context .Users.Where(u => u.Id == userId) .Select(u => new UserInfo(u.Id, u.Username, u.Roles.Select(r => r.Role).ToList())) .SingleOrDefaultAsync(cancellationToken); } public async Task CreateStrongSession(Guid userId) { var session = new Session(userId, true); await storage.AddSession(session); return session; } public async Task CreateWeakSession(Guid userId) { var session = new Session(userId, false); await storage.AddSession(session); return session; } public Task GetSession(string sessionId) { return storage.GetSession(sessionId); } public async Task DeleteSession(string sessionId) { await storage.DeleteSession(sessionId); } public async Task CreateLongTermSession(Guid userId, bool isStrong) { throw new NotImplementedException(); } public async Task DeleteLongTermSession(string sessionId) { throw new NotImplementedException(); } public async Task RefreshLongTermSession(string sessionId) { throw new NotImplementedException(); } public async Task ValidateLongTermSession(string sessionId) { throw new NotImplementedException(); } }