Add friendship feature with models, repository, and tests

Introduces Friendship and PrivateChat models, repository interfaces, and implementations for managing friendships. Adds validators and comprehensive unit and integration tests for friendship logic. Updates InviteUserController with new endpoints and restricts access to admin role. Removes unnecessary project references from Govor.API.csproj and registers new DbSets in GovorDbContext.
This commit is contained in:
Artemy
2025-06-27 15:09:28 +07:00
parent 4f3f4ec066
commit 9b9cd73a96
15 changed files with 565 additions and 20 deletions
@@ -9,7 +9,7 @@ namespace Govor.API.Controllers.AdminStuff;
[Route("api/[controller]")]
[ApiController]
[Authorize]
[Authorize(Roles = "Admin")]
public class InviteUserController : Controller
{
private readonly IInvitesRepository _repository;
@@ -43,20 +43,22 @@ public class InviteUserController : Controller
return BadRequest($"An error occured: {e.Message}");
}
}
[HttpGet]
public async Task<IActionResult> GetAllInvitations()
[HttpGet("[action]")]
public async Task<IActionResult> GetAllActiveInvitations()
{
try
{
_logger.LogInformation("Getting all invitations by administrator");
var read = await _repository.GetAllAsync();
_logger.LogInformation("Getting all active invitations by administrator");
List<InvitationDto> dto = new List<InvitationDto>();
var read = await _repository.GetAllAsync();
var result = read.Where(x => x.IsActive == true).ToList();
foreach (var inv in read)
List<InvitationDto> dtos = new List<InvitationDto>();
foreach (var inv in result)
{
dto.Add(new InvitationDto(){
dtos.Add(new InvitationDto(){
Id = inv.Id,
Description = inv.Description,
IsAdmin = inv.IsAdmin,
@@ -68,7 +70,69 @@ public class InviteUserController : Controller
});
}
return Ok(dto);
return Ok(dtos);
}
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> dtos = new List<InvitationDto>();
foreach (var inv in read)
{
dtos.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(dtos);
}
catch (Exception e)
{
_logger.LogError(e, e.Message);
return BadRequest($"An error occured: {e.Message}");
}
}
[HttpGet("{id:guid}")]
public async Task<IActionResult> GetInvitationById(Guid id)
{
try
{
_logger.LogInformation("Getting invitations {id} by administrator");
var read = await _repository.FindByIdAsync(id);
var response = new InvitationDto(){
Id = read.Id,
Description = read.Description,
IsAdmin = read.IsAdmin,
MaxParticipants = read.MaxParticipants,
Code = read.Code,
CreatedAt = read.DateCreated,
EndAt = read.EndDate,
IsActive = read.IsActive,
};
return Ok(response);
}
catch (Exception e)
{
-2
View File
@@ -24,8 +24,6 @@
<ItemGroup>
<ProjectReference Include="..\Govor.Application\Govor.Application.csproj" />
<ProjectReference Include="..\Govor.Contracts\Govor.Contracts.csproj" />
<ProjectReference Include="..\Govor.Core\Govor.Core.csproj" />
<ProjectReference Include="..\Govor.Data\Govor.Data.csproj" />
</ItemGroup>
</Project>