Test for friends controllers

This commit is contained in:
Artemy
2025-07-12 19:51:15 +07:00
parent 96587b491d
commit 97b2ea14b2
4 changed files with 392 additions and 397 deletions
@@ -42,7 +42,7 @@ public class FriendsRequestQueryController : Controller
catch (InvalidOperationException ex)
{
_logger.LogError(ex, ex.Message);
return BadRequest("Failed to get friend requests. User data missing.");
return Ok(new List<FriendshipDto>());
}
catch (Exception ex)
{
@@ -57,12 +57,14 @@ public class FriendsRequestQueryController : Controller
try
{
var result = await _friendsService.GetResponsesAsync(_currentUserService.GetCurrentUserId());
return Ok(BuildFriendshipDtos(result));
var response = _mapper.Map<List<FriendshipDto>>(result);
return Ok(response);
}
catch (InvalidOperationException ex)
{
_logger.LogError(ex, ex.Message);
return Ok(Array.Empty<FriendshipDto>());
return Ok(new List<FriendshipDto>());
}
catch (Exception ex)
{
@@ -70,12 +72,4 @@ public class FriendsRequestQueryController : Controller
return StatusCode(500, new { error = "Internal server error." });
}
}
private List<FriendshipDto> BuildFriendshipDtos(IEnumerable<Friendship> friendships) => friendships.Select(f => new FriendshipDto
{
Id = f.Id,
Status = f.Status,
AddresseeId = f.AddresseeId,
RequesterId = f.RequesterId,
}).ToList();
}