User profile service #2

Merged
Jiri merged 16 commits from 250809_UserProfile into main 2025-08-11 20:10:50 +00:00
2 changed files with 28 additions and 0 deletions
Showing only changes of commit 76cb56d819 - Show all commits

View file

@ -0,0 +1,7 @@
namespace DrinkRateAPI.Exceptions;
public class DrinkRateException : Exception;
public class NotFoundException : DrinkRateException;
public class UnauthorizedException : DrinkRateException;

View file

@ -0,0 +1,21 @@
using System.Security.Claims;
using DrinkRateAPI.Contexts;
using DrinkRateAPI.DbEntities;
using DrinkRateAPI.Exceptions;
using Microsoft.EntityFrameworkCore;
namespace DrinkRateAPI.Services;
public class ApplicationUserService(ApplicationDbContext context)
{
private ApplicationDbContext _context = context;
public async Task<DbUserProfile> UserProfileByApplicationUserAsync(ClaimsPrincipal identity)
{
var appUserId = identity.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var profile = await _context.UserProfiles
.FirstAsync(x => x.ApplicationUserId.ToString() == appUserId)
?? throw new NotFoundException();
return profile;
}
}