profile editing finished

This commit is contained in:
2024-11-05 20:04:15 +01:00
Unverified
parent 314fceb120
commit 26a5e1e558
17 changed files with 475 additions and 16 deletions

View File

@@ -8,6 +8,7 @@ using WatchIt.Common.Model.Accounts;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Movies;
using WatchIt.Common.Model.Persons;
using WatchIt.Common.Model.Photos;
using WatchIt.Common.Model.Series;
using WatchIt.Database;
using WatchIt.Database.Model.Account;
@@ -32,6 +33,8 @@ public class AccountsControllerService(
{
#region PUBLIC METHODS
#region Basic
public async Task<RequestResult> Register(RegisterRequest data)
{
string leftSalt = StringExtensions.CreateRandom(20);
@@ -125,6 +128,10 @@ public class AccountsControllerService(
return RequestResult.NoContent();
}
#endregion
#region Profile picture
public async Task<RequestResult> GetAccountProfilePicture(long id)
{
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
@@ -185,6 +192,55 @@ public class AccountsControllerService(
return RequestResult.NoContent();
}
#endregion
#region Profile background
public async Task<RequestResult> GetAccountProfileBackground(long id)
{
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);
if (account is null)
{
return RequestResult.BadRequest()
.AddValidationError("id", "Account with this id does not exists");
}
if (account.BackgroundPicture is null)
{
return RequestResult.NotFound();
}
PhotoResponse response = new PhotoResponse(account.BackgroundPicture);
return RequestResult.Ok(response);
}
public async Task<RequestResult> PutAccountProfileBackground(AccountProfileBackgroundRequest data)
{
Account account = await database.Accounts.FirstAsync(x => x.Id == userService.GetUserId());
account.BackgroundPictureId = data.Id;
await database.SaveChangesAsync();
PhotoResponse returnData = new PhotoResponse(account.BackgroundPicture!);
return RequestResult.Ok(returnData);
}
public async Task<RequestResult> DeleteAccountProfileBackground()
{
Account account = await database.Accounts.FirstAsync(x => x.Id == userService.GetUserId());
if (account.BackgroundPicture is not null)
{
account.BackgroundPictureId = null;
await database.SaveChangesAsync();
}
return RequestResult.NoContent();
}
#endregion
public async Task<RequestResult> GetAccountInfo(long id)
{
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id);

View File

@@ -16,6 +16,9 @@ public interface IAccountsControllerService
Task<RequestResult> GetAccountProfilePicture(long id);
Task<RequestResult> PutAccountProfilePicture(AccountProfilePictureRequest data);
Task<RequestResult> DeleteAccountProfilePicture();
Task<RequestResult> GetAccountProfileBackground(long id);
Task<RequestResult> PutAccountProfileBackground(AccountProfileBackgroundRequest data);
Task<RequestResult> DeleteAccountProfileBackground();
Task<RequestResult> GetAccountInfo(long id);
Task<RequestResult> PutAccountProfileInfo(AccountProfileInfoRequest data);
Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query);