mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
4f3f4ec066
Moved service implementations and interfaces from Govor.API and Govor.Core to new Govor.Application and Govor.Contracts projects. Updated namespaces and references throughout the solution. Added custom exception classes for authentication and invite services. Adjusted dependency injection and project references to use the new structure. This refactor improves separation of concerns and prepares the codebase for better maintainability and scalability.
79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using Govor.API.Services.AdminsStuff.Interfaces;
|
|
using Govor.Contracts.DTOs;
|
|
using Govor.Contracts.Requests;
|
|
using Govor.Core.Repositories.Invaites;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Govor.API.Controllers.AdminStuff;
|
|
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class InviteUserController : Controller
|
|
{
|
|
private readonly IInvitesRepository _repository;
|
|
private readonly IInvitationGenerator _invitationGenerator;
|
|
private readonly ILogger<InviteUserController> _logger;
|
|
|
|
public InviteUserController(IInvitationGenerator invitationGenerator,
|
|
IInvitesRepository repository,
|
|
ILogger<InviteUserController> logger)
|
|
{
|
|
_invitationGenerator = invitationGenerator;
|
|
_logger = logger;
|
|
_repository = repository;
|
|
}
|
|
|
|
[HttpPost("[action]")]
|
|
public async Task<IActionResult> Invitation([FromBody] CreateInvitationRequest createInvitation)
|
|
{
|
|
try
|
|
{
|
|
var result = await _invitationGenerator.GenerateInvitationCode(createInvitation.EndDate,
|
|
createInvitation.MaxParticipants,
|
|
createInvitation.IsAdmin,
|
|
createInvitation.Description);
|
|
|
|
return Ok(result);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, e.Message);
|
|
return BadRequest($"An error occured: {e.Message}");
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public async Task<IActionResult> GetAllInvitations()
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation("Getting all invitations by administrator");
|
|
var read = await _repository.GetAllAsync();
|
|
|
|
List<InvitationDto> dto = new List<InvitationDto>();
|
|
|
|
foreach (var inv in read)
|
|
{
|
|
dto.Add(new InvitationDto(){
|
|
Id = inv.Id,
|
|
Description = inv.Description,
|
|
IsAdmin = inv.IsAdmin,
|
|
MaxParticipants = inv.MaxParticipants,
|
|
Code = inv.Code,
|
|
CreatedAt = inv.DateCreated,
|
|
EndAt = inv.EndDate,
|
|
IsActive = inv.IsActive,
|
|
});
|
|
}
|
|
|
|
return Ok(dto);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_logger.LogError(e, e.Message);
|
|
return BadRequest($"An error occured: {e.Message}");
|
|
}
|
|
}
|
|
} |