mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
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:
@@ -0,0 +1,38 @@
|
||||
using Govor.Core.Models;
|
||||
|
||||
namespace Govor.Core.Infrastructure.Validators;
|
||||
|
||||
public class FriendshipValidator : IObjectValidator<Friendship>
|
||||
{
|
||||
public void Validate(Friendship friendship)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(friendship is null)
|
||||
throw new ArgumentNullException(nameof(friendship));
|
||||
if(friendship.Id == Guid.Empty)
|
||||
throw new ArgumentException("Id cannot be empty", nameof(friendship.Id));
|
||||
if(friendship.AddresseeId == Guid.Empty)
|
||||
throw new ArgumentException("Addresses cannot be empty", nameof(friendship.AddresseeId));
|
||||
if(friendship.RequesterId == Guid.Empty)
|
||||
throw new ArgumentException("Requester cannot be empty", nameof(friendship.RequesterId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new InvalidObjectException<Friendship>(e);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryValidate(Friendship friendship)
|
||||
{
|
||||
try
|
||||
{
|
||||
Validate(friendship);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user