mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
InvitationValidator
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace Govor.API.Tests.UnitTests.Infrastructure.Validators;
|
||||
|
||||
[TestFixture]
|
||||
public class InvitationValidatorTests
|
||||
{
|
||||
|
||||
}
|
||||
@@ -134,8 +134,6 @@ if (app.Environment.IsDevelopment())
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using Govor.Core.Models;
|
||||
|
||||
namespace Govor.Core.Infrastructure.Validators;
|
||||
|
||||
public class InvitationValidator : IObjectValidator<Invitation>
|
||||
{
|
||||
public void Validate(Invitation inv)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(inv is null)
|
||||
throw new ArgumentNullException(nameof(inv));
|
||||
if(inv.Id == Guid.Empty)
|
||||
throw new ArgumentException("Id cannot be empty", nameof(inv.Id));
|
||||
if(inv.DateCreated == DateTime.MinValue)
|
||||
throw new ArgumentException("DateCreated cannot be empty", nameof(inv.DateCreated));
|
||||
if(inv.EndDate < inv.DateCreated)
|
||||
throw new ArgumentException("EndDate cannot be less than StartDate", nameof(inv.EndDate));
|
||||
if(inv.MaxParticipants <= 0)
|
||||
throw new ArgumentException("MaxParticipants cannot be less than 0", nameof(inv.MaxParticipants));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidObjectException<Invitation>(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryValidate(Invitation inv)
|
||||
{
|
||||
try
|
||||
{
|
||||
Validate(inv);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Govor.Core.Infrastructure.Validators;
|
||||
using Govor.Core.Models;
|
||||
using Govor.Core.Repositories.Invaites;
|
||||
|
||||
@@ -5,7 +6,16 @@ namespace Govor.Data.Repositories;
|
||||
|
||||
public class InvitesRepository : IInvitesRepository
|
||||
{
|
||||
public Task<List<Invitation>> GetAllAsync()
|
||||
private GovorDbContext _context;
|
||||
private IObjectValidator<Invitation> _validator;
|
||||
|
||||
public InvitesRepository(GovorDbContext context, IObjectValidator<Invitation> validator)
|
||||
{
|
||||
_context = context;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
public async Task<List<Invitation>> GetAllAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user