mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Admins Repository
+ tests
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using Govor.Core.Models;
|
||||
|
||||
namespace Govor.Core.Infrastructure.Validators;
|
||||
|
||||
public class AdminValidator : IObjectValidator<Admin>
|
||||
{
|
||||
public void Validate(Admin admin)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(admin is null)
|
||||
throw new ArgumentNullException(nameof(admin));
|
||||
if(admin.UserId == Guid.Empty)
|
||||
throw new ArgumentException("User ID cannot be empty", nameof(admin.UserId));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new InvalidObjectException<Admin>(e);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryValidate(Admin admin)
|
||||
{
|
||||
try
|
||||
{
|
||||
Validate(admin);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user