mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
InvitesRepositoryTests
+ other reworks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Govor.Core.Infrastructure.Validators;
|
||||
using Govor.Core.Models;
|
||||
|
||||
namespace Govor.Core.DTOs;
|
||||
|
||||
@@ -13,6 +14,6 @@ public record RegistrationDto
|
||||
[Required]
|
||||
[MinLength(8)]
|
||||
public string Password { get; init; }
|
||||
[MinLength(8)]
|
||||
[MinLength(InvitationValidator.MIN_INVITATION_LENGTH)]
|
||||
public string InviteLink { get; init; }
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Govor.Core.Infrastructure.Validators;
|
||||
|
||||
public class InvitationValidator : IObjectValidator<Invitation>
|
||||
{
|
||||
public const int MIN_INVITATION_LENGTH = 10;
|
||||
public void Validate(Invitation inv)
|
||||
{
|
||||
try
|
||||
@@ -18,6 +19,8 @@ public class InvitationValidator : IObjectValidator<Invitation>
|
||||
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));
|
||||
if(inv.Code == string.Empty || inv.Code.Length < MIN_INVITATION_LENGTH)
|
||||
throw new ArgumentException($"Code cannot be empty or less then {MIN_INVITATION_LENGTH}", nameof(inv.Code));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -4,9 +4,22 @@ public class Invitation
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
public string Code { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime DateCreated { get; set; }
|
||||
public DateTime EndDate { get; set; }
|
||||
public int MaxParticipants { get; set; }
|
||||
public List<User> Users { get; set; } = new List<User>();
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
var invitation = obj as Invitation ?? throw new InvalidCastException();
|
||||
|
||||
return Id == invitation.Id &&
|
||||
IsAdmin == invitation.IsAdmin &&
|
||||
Description == invitation.Description &&
|
||||
DateCreated == invitation.DateCreated &&
|
||||
EndDate == invitation.EndDate &&
|
||||
MaxParticipants == invitation.MaxParticipants;
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,5 @@ public interface IAdminsWriter
|
||||
{
|
||||
Task AddAsync(Admin admin);
|
||||
Task UpdateAsync(Admin admin);
|
||||
Task DeleteAsync(Guid admin);
|
||||
Task RemoveAsync(Guid admin);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Govor.Core.Repositories.Invaites;
|
||||
public interface IInvitesReader
|
||||
{
|
||||
Task<List<Invitation>> GetAllAsync();
|
||||
Task<Invitation> GetByIdAsync(Guid id);
|
||||
Task<Invitation> GetByCodeAsync(string code);
|
||||
Task<List<Invitation>> GetAdminsInvitesAsync();
|
||||
Task<Invitation> FindByIdAsync(Guid id);
|
||||
Task<Invitation> FindByCodeAsync(string code);
|
||||
Task<List<Invitation>> FindAdminsInvitesAsync();
|
||||
}
|
||||
Reference in New Issue
Block a user