mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 11:44:56 +00:00
Refactor: migrate Core -> Domain and reorganize projects
Large refactor that renames/moves core types into a new Govor.Domain surface and reorganizes the Application layer. Models, configurations, migrations and many files moved from Govor.Core/Govor.Data to Govor.Domain; numerous Application services, interfaces and implementations were relocated or added (authentication, friends, messages, medias, push notifications, user sessions, storage, synching, private chats, etc.). Tests updated to use Govor.Domain namespaces and adjusted project references (removed Govor.Data reference from API tests). Also updated API, Hub and mapping code and project files to reflect the new structure and naming. This is primarily a codebase-wide namespace and module reorganization to establish a Domain project and restructure application services.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace Govor.Domain.Common.Constants;
|
||||
|
||||
public class InvitationConstants
|
||||
{
|
||||
public const int MIN_INVITATION_LENGTH = 5;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Govor.Domain.Common.Constants;
|
||||
|
||||
public class UserConstants
|
||||
{
|
||||
public const int MAX_LENGHT_OF_NAME = 44;
|
||||
public const int MIN_LENGHT_OF_NAME = 4;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Govor.Domain.Common;
|
||||
|
||||
|
||||
public record Error(string Code, string Message)
|
||||
{
|
||||
public static readonly Error None = new(string.Empty, string.Empty);
|
||||
public static readonly Error Null = new("NULL", "Value cannot be null.");
|
||||
public override string ToString() => $"{Code}: {Message}";
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Govor.Domain.Common.Extensions;
|
||||
|
||||
public static class QueryableExtensions
|
||||
{
|
||||
public static async Task<List<T>> ToListOrThrowIfEmpty<T>(this IQueryable<T> query, Exception ex)
|
||||
{
|
||||
var list = await query.ToListAsync();
|
||||
if (list.Count == 0) throw ex;
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
namespace Govor.Domain.Common;
|
||||
|
||||
public class Result
|
||||
{
|
||||
protected Result(bool isSuccess, Error error)
|
||||
{
|
||||
if (isSuccess && error != Error.None || !isSuccess && error == Error.None)
|
||||
{
|
||||
throw new ArgumentException("Invalid error state", nameof(error));
|
||||
}
|
||||
|
||||
IsSuccess = isSuccess;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public bool IsSuccess { get; }
|
||||
public bool IsFailure => !IsSuccess;
|
||||
public Error Error { get; }
|
||||
|
||||
public static Result Success() => new(true, Error.None);
|
||||
public static Result Failure(Error error) => new(false, error);
|
||||
|
||||
public static Result Failure(Exception ex) => new(false, new Error(ex.GetType().Name, ex.Message));
|
||||
|
||||
public static implicit operator Result(Error error) => Failure(error);
|
||||
}
|
||||
|
||||
public class Result<T> : Result
|
||||
{
|
||||
private readonly T? _value;
|
||||
|
||||
private Result(T? value, bool isSuccess, Error error) : base(isSuccess, error)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public T Value => IsSuccess
|
||||
? _value!
|
||||
: throw new InvalidOperationException("The value of a failure result cannot be accessed.");
|
||||
|
||||
public static Result<T> Success(T value) => new(value, true, Error.None);
|
||||
public static new Result<T> Failure(Error error) => new(default, false, error);
|
||||
public static new Result<T> Failure(Exception ex) => new(default, false, new Error(ex.GetType().Name, ex.Message));
|
||||
|
||||
public static implicit operator Result<T>(T value) => Success(value);
|
||||
|
||||
public static implicit operator Result<T>(Error error) => Failure(error);
|
||||
public static implicit operator T(Result<T> result) => result.Value;
|
||||
}
|
||||
Reference in New Issue
Block a user