mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
new app server and database + added hub and controller of user profile
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Govor.API.Controllers.AdminStuff;
|
||||
|
||||
[Route("api/admin/[controller]")]
|
||||
[ApiController]
|
||||
[Authorize(Roles = "Admin")]
|
||||
//[Authorize(Roles = "Admin")]
|
||||
public class InviteUserController : Controller
|
||||
{
|
||||
private readonly IInvitesRepository _repository;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.Medias;
|
||||
using Govor.Contracts.Requests;
|
||||
using Govor.Core.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class MediaController : Controller
|
||||
try
|
||||
{
|
||||
byte[] fileBytes = await ReadFileAsync(request.FromFile);
|
||||
|
||||
|
||||
var media = new Media(
|
||||
_currentUserService.GetCurrentUserId(),
|
||||
DateTime.UtcNow,
|
||||
@@ -55,8 +56,15 @@ public class MediaController : Controller
|
||||
fileBytes,
|
||||
request.Type,
|
||||
request.MimeType,
|
||||
request.EncryptedKey
|
||||
);
|
||||
request.EncryptedKey,
|
||||
request.OwnerType,
|
||||
null)
|
||||
{
|
||||
OwnerType = request.OwnerType,
|
||||
OwnerId = request.OwnerType == MediaOwnerType.Avatar
|
||||
? _currentUserService.GetCurrentUserId()
|
||||
: null,
|
||||
};
|
||||
|
||||
var result = await _mediaService.UploadMediaAsync(media);
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
using AutoMapper;
|
||||
using Govor.Application.Interfaces;
|
||||
using Govor.Application.Interfaces.Infrastructure.Extensions;
|
||||
using Govor.Application.Interfaces.Medias;
|
||||
using Govor.Contracts.DTOs;
|
||||
using Govor.Data.Repositories.Exceptions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Govor.API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/profile")]
|
||||
[Authorize(Roles = "Admin,User")]
|
||||
public class ProfileController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<ProfileController> _logger;
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ProfileController(
|
||||
ILogger<ProfileController> logger,
|
||||
IMediaService mediaService,
|
||||
IProfileService profileService,
|
||||
ICurrentUserService currentUserService,
|
||||
IMapper mapper)
|
||||
{
|
||||
_logger = logger;
|
||||
_mediaService = mediaService;
|
||||
_profileService = profileService;
|
||||
_currentUserService = currentUserService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("dowload")]
|
||||
public async Task<IActionResult> DowloadProfile()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = _currentUserService.GetCurrentUserId();
|
||||
var user = await _profileService.GetUserProfileAsync(userId);
|
||||
|
||||
if (user is null)
|
||||
return NotFound("Profile not found");
|
||||
|
||||
var dto = _mapper.Map<UserProfileDto>(user);
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return StatusCode(500, "Unexpected Error! Please try again later.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class SessionController : Controller
|
||||
{
|
||||
private readonly ILogger<SessionController> _logger;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly ICurrentUserSessionService _currentUserSessionService;
|
||||
private readonly IUserSessionReader _userSessionReader;
|
||||
private readonly IUserSessionRevoker _userSessionRevoker;
|
||||
private readonly IMapper _mapper;
|
||||
@@ -22,12 +23,14 @@ public class SessionController : Controller
|
||||
public SessionController(
|
||||
ILogger<SessionController> logger,
|
||||
ICurrentUserService currentUserService,
|
||||
ICurrentUserSessionService currentUserSessionService,
|
||||
IUserSessionReader userSessionReader,
|
||||
IUserSessionRevoker userSessionRevoker,
|
||||
IMapper mapper)
|
||||
{
|
||||
_logger = logger;
|
||||
_currentUserService = currentUserService;
|
||||
_currentUserSessionService = currentUserSessionService;
|
||||
_userSessionReader = userSessionReader;
|
||||
_userSessionRevoker = userSessionRevoker;
|
||||
_mapper = mapper;
|
||||
@@ -86,7 +89,40 @@ public class SessionController : Controller
|
||||
return StatusCode(500, "Unexpected Error! Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("close")]
|
||||
public async Task<IActionResult> CloseCurrent()
|
||||
{
|
||||
try
|
||||
{
|
||||
await _userSessionRevoker.CloseSessionByIdAsync(
|
||||
_currentUserSessionService.GetUserSessionId(),
|
||||
_currentUserService.GetCurrentUserId());
|
||||
|
||||
return Ok();
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
catch (UnauthorizedAccessException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return Forbid(ex.Message);
|
||||
}
|
||||
catch (NotFoundException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, ex.Message);
|
||||
return NotFound(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
return StatusCode(500, "Unexpected Error! Please try again later.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("close/all")]
|
||||
public async Task<IActionResult> CloseAllSessions()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user