Saving
This commit is contained in:
1 parent
9719a0c0fd
commit
1e66851113
146 files changed
+738
-382
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using PrivaPub.ClientModels;
|
||||
using PrivaPub.Extensions;
|
||||
using PrivaPub.Resources;
|
||||
using PrivaPub.Services.ClientToServer.Private;
|
||||
using PrivaPub.ClientModels.User.Avatar;
|
||||
|
||||
namespace PrivaPub.Controllers.ClientToServer
|
||||
{
|
||||
[ApiController,
|
||||
Route("clientapi/avatar/private"),
|
||||
Authorize(Policy = Policies.IsUser)]
|
||||
public class PrivateAvatarController : ControllerBase
|
||||
{
|
||||
readonly ILogger<PrivateAvatarController> _logger;
|
||||
readonly IPrivateAvatarUsersService _privateAvatarUsersService;
|
||||
readonly IStringLocalizer _localizer;
|
||||
|
||||
public PrivateAvatarController(IPrivateAvatarUsersService privateAvatarUsersService,
|
||||
IStringLocalizer<GenericRes> localizer,
|
||||
ILogger<PrivateAvatarController> logger)
|
||||
{
|
||||
_privateAvatarUsersService = privateAvatarUsersService;
|
||||
_localizer = localizer;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpPost, Route("/clientapi/avatar/private/insert")]
|
||||
public async Task<IActionResult> InsertAvatar(InsertAvatarForm model)
|
||||
{
|
||||
var result = new WebResult();
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(result.Invalidate(_localizer["Invalid model."]));
|
||||
try
|
||||
{
|
||||
model.RootId = User.GetUserId();
|
||||
result = await _privateAvatarUsersService.InsertAvatar(model);
|
||||
if (!result.IsValid)
|
||||
return StatusCode(result.StatusCode, result);
|
||||
|
||||
return Ok(result.Data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{nameof(PrivateAvatarController)}.{nameof(InsertAvatar)}()");
|
||||
return BadRequest(result.Invalidate(ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost, Route("/clientapi/avatar/private/update")]
|
||||
public async Task<IActionResult> UpdateAvatar(UpdateAvatarForm model)
|
||||
{
|
||||
var result = new WebResult();
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(result.Invalidate(_localizer["Invalid model."]));
|
||||
try
|
||||
{
|
||||
model.RootId = User.GetUserId();
|
||||
result = await _privateAvatarUsersService.UpdateAvatar(model);
|
||||
if (!result.IsValid)
|
||||
return StatusCode(result.StatusCode, result);
|
||||
|
||||
return Ok(result.Data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{nameof(PrivateAvatarController)}.{nameof(UpdateAvatar)}()");
|
||||
return BadRequest(result.Invalidate(ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user