basic profile info endpoints created
This commit is contained in:
@@ -11,6 +11,7 @@ using WatchIt.WebAPI.Services.Controllers.Common;
|
||||
using WatchIt.WebAPI.Services.Utility.Tokens;
|
||||
using WatchIt.WebAPI.Services.Utility.Tokens.Exceptions;
|
||||
using WatchIt.WebAPI.Services.Utility.User;
|
||||
using Account = WatchIt.Database.Model.Account.Account;
|
||||
using AccountProfilePicture = WatchIt.Common.Model.Accounts.AccountProfilePicture;
|
||||
|
||||
namespace WatchIt.WebAPI.Services.Controllers.Accounts;
|
||||
@@ -129,6 +130,31 @@ public class AccountsControllerService(
|
||||
return RequestResult.Ok(picture);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> GetAccountInfo() => await GetAccountInfo(userService.GetUserId());
|
||||
public async Task<RequestResult> GetAccountInfo(long id)
|
||||
{
|
||||
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (account is null)
|
||||
{
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
AccountResponse response = new AccountResponse(account);
|
||||
return RequestResult.Ok(response);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> PutAccountInfo(AccountRequest data)
|
||||
{
|
||||
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == userService.GetUserId());
|
||||
if (account is null)
|
||||
{
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
data.UpdateAccount(account);
|
||||
return RequestResult.Ok();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -10,4 +10,7 @@ public interface IAccountsControllerService
|
||||
Task<RequestResult> AuthenticateRefresh();
|
||||
Task<RequestResult> Logout();
|
||||
Task<RequestResult> GetAccountProfilePicture(long id);
|
||||
Task<RequestResult> GetAccountInfo();
|
||||
Task<RequestResult> GetAccountInfo(long id);
|
||||
Task<RequestResult> PutAccountInfo(AccountRequest data);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Security.Claims;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using WatchIt.Database;
|
||||
|
||||
namespace WatchIt.WebAPI.Services.Utility.User;
|
||||
@@ -53,5 +54,17 @@ public class UserValidator
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserValidator MustHaveId(long id)
|
||||
{
|
||||
Claim adminClaim = _claimsPrincipal.FindFirst(x => x.Type == JwtRegisteredClaimNames.Sub)!;
|
||||
if (adminClaim.Value == id.ToString())
|
||||
{
|
||||
IsValid = false;
|
||||
_validationErrors.Add("User have wrong id");
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user