profile picture and basic info editors added
This commit is contained in:
@@ -27,7 +27,7 @@ public class AccountsController(IAccountsControllerService accountsControllerSer
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||
public async Task<ActionResult> Authenticate([FromBody]AuthenticateRequest body) => await accountsControllerService.Authenticate(body);
|
||||
|
||||
[HttpPost("authenticate-refresh")]
|
||||
[HttpPost("authenticate_refresh")]
|
||||
[Authorize(AuthenticationSchemes = "refresh")]
|
||||
[ProducesResponseType(typeof(AuthenticateResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||
@@ -39,25 +39,38 @@ public class AccountsController(IAccountsControllerService accountsControllerSer
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)]
|
||||
public async Task<ActionResult> Logout() => await accountsControllerService.Logout();
|
||||
|
||||
[HttpGet("{id}/profile-picture")]
|
||||
[HttpGet("{id}/profile_picture")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(AccountProfilePictureResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> GetAccountProfilePicture([FromRoute(Name = "id")]long id) => await accountsControllerService.GetAccountProfilePicture(id);
|
||||
|
||||
[HttpPut("profile_picture")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ProducesResponseType(typeof(AccountProfilePictureResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||
public async Task<ActionResult> PutAccountProfilePicture([FromBody]AccountProfilePictureRequest body) => await accountsControllerService.PutAccountProfilePicture(body);
|
||||
|
||||
[HttpDelete("profile_picture")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
||||
public async Task<ActionResult> DeleteAccountProfilePicture() => await accountsControllerService.DeleteAccountProfilePicture();
|
||||
|
||||
[HttpGet("{id}/info")]
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(typeof(AccountResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> GetAccountInfo([FromRoute]long id) => await accountsControllerService.GetAccountInfo(id);
|
||||
|
||||
[HttpPut("info")]
|
||||
[HttpPut("profile_info")]
|
||||
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
||||
[ProducesResponseType(typeof(AccountResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<ActionResult> PutAccountInfo([FromBody]AccountRequest data) => await accountsControllerService.PutAccountInfo(data);
|
||||
public async Task<ActionResult> PutAccountProfileInfo([FromBody]AccountProfileInfoRequest data) => await accountsControllerService.PutAccountProfileInfo(data);
|
||||
|
||||
[HttpGet("{id}/movies")]
|
||||
[AllowAnonymous]
|
||||
|
||||
@@ -142,6 +142,48 @@ public class AccountsControllerService(
|
||||
AccountProfilePictureResponse picture = new AccountProfilePictureResponse(account.ProfilePicture);
|
||||
return RequestResult.Ok(picture);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> PutAccountProfilePicture(AccountProfilePictureRequest data)
|
||||
{
|
||||
Account account = await database.Accounts.FirstAsync(x => x.Id == userService.GetUserId());
|
||||
Database.Model.Account.AccountProfilePicture? picture = account.ProfilePicture;
|
||||
|
||||
if (picture is null)
|
||||
{
|
||||
picture = data.CreateMediaPosterImage();
|
||||
await database.AccountProfilePictures.AddAsync(picture);
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
account.ProfilePictureId = picture.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
data.UpdateMediaPosterImage(picture);
|
||||
}
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
AccountProfilePictureResponse returnData = new AccountProfilePictureResponse(picture);
|
||||
return RequestResult.Ok(returnData);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> DeleteAccountProfilePicture()
|
||||
{
|
||||
Account account = await database.Accounts.FirstAsync(x => x.Id == userService.GetUserId());
|
||||
Database.Model.Account.AccountProfilePicture? picture = account.ProfilePicture;
|
||||
|
||||
if (picture is not null)
|
||||
{
|
||||
account.ProfilePictureId = null;
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
database.AccountProfilePictures.Attach(picture);
|
||||
database.AccountProfilePictures.Remove(picture);
|
||||
await database.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return RequestResult.NoContent();
|
||||
}
|
||||
|
||||
public async Task<RequestResult> GetAccountInfo(long id)
|
||||
{
|
||||
@@ -151,11 +193,11 @@ public class AccountsControllerService(
|
||||
return RequestResult.NotFound();
|
||||
}
|
||||
|
||||
AccountResponse response = new AccountResponse(account);
|
||||
return RequestResult.Ok(response);
|
||||
AccountResponse profileInfoResponse = new AccountResponse(account);
|
||||
return RequestResult.Ok(profileInfoResponse);
|
||||
}
|
||||
|
||||
public async Task<RequestResult> PutAccountInfo(AccountRequest data)
|
||||
public async Task<RequestResult> PutAccountProfileInfo(AccountProfileInfoRequest data)
|
||||
{
|
||||
Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == userService.GetUserId());
|
||||
if (account is null)
|
||||
@@ -164,6 +206,8 @@ public class AccountsControllerService(
|
||||
}
|
||||
|
||||
data.UpdateAccount(account);
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
return RequestResult.Ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,10 @@ public interface IAccountsControllerService
|
||||
Task<RequestResult> AuthenticateRefresh();
|
||||
Task<RequestResult> Logout();
|
||||
Task<RequestResult> GetAccountProfilePicture(long id);
|
||||
Task<RequestResult> PutAccountProfilePicture(AccountProfilePictureRequest data);
|
||||
Task<RequestResult> DeleteAccountProfilePicture();
|
||||
Task<RequestResult> GetAccountInfo(long id);
|
||||
Task<RequestResult> PutAccountInfo(AccountRequest data);
|
||||
Task<RequestResult> PutAccountProfileInfo(AccountProfileInfoRequest data);
|
||||
Task<RequestResult> GetAccountRatedMovies(long id, MovieRatedQueryParameters query);
|
||||
Task<RequestResult> GetAccountRatedSeries(long id, SeriesRatedQueryParameters query);
|
||||
Task<RequestResult> GetAccountRatedPersons(long id, PersonRatedQueryParameters query);
|
||||
|
||||
@@ -4,14 +4,10 @@ using WatchIt.Database;
|
||||
|
||||
namespace WatchIt.WebAPI.Validators.Accounts;
|
||||
|
||||
public class AccountRequestValidator : AbstractValidator<AccountRequest>
|
||||
public class AccountProfileInfoRequestValidator : AbstractValidator<AccountProfileInfoRequest>
|
||||
{
|
||||
public AccountRequestValidator(DatabaseContext database)
|
||||
public AccountProfileInfoRequestValidator(DatabaseContext database)
|
||||
{
|
||||
RuleFor(x => x.Username).NotEmpty()
|
||||
.MaximumLength(50);
|
||||
RuleFor(x => x.Email).EmailAddress()
|
||||
.MaximumLength(320);
|
||||
RuleFor(x => x.Description).MaximumLength(1000);
|
||||
When(x => x.GenderId.HasValue, () =>
|
||||
{
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
using WatchIt.Common.Model.Accounts;
|
||||
|
||||
namespace WatchIt.WebAPI.Validators.Accounts;
|
||||
|
||||
public class AccountProfilePictureRequestValidator : AbstractValidator<AccountProfilePictureRequest>
|
||||
{
|
||||
public AccountProfilePictureRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Image).NotEmpty();
|
||||
RuleFor(x => x.MimeType).Matches(@"\w+/.+").WithMessage("Incorrect mimetype");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user