feature: Schema, Migrations, Core CRUD, and Redis Threshold Cache
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
public record ApiResponse<T>(bool Success, int StatusCode, T? Data, ApiError? Error)
|
||||
{
|
||||
public static ApiResponse<T> Ok(T data) =>
|
||||
new(true, 200, data, null);
|
||||
|
||||
public static ApiResponse<T> Created(T data) =>
|
||||
new(true, 201, data, null);
|
||||
|
||||
public static ApiResponse<T> Fail(int statusCode, string message, string code) =>
|
||||
new(false, statusCode, default, new ApiError(message, code));
|
||||
}
|
||||
|
||||
public record ApiError(string Message, string Code);
|
||||
@@ -0,0 +1,5 @@
|
||||
public class ConflictException : DomainException
|
||||
{
|
||||
public ConflictException(string message, string errorCode = "CONFLICT_ERROR")
|
||||
: base(message, errorCode) { }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
public static class DbExceptions
|
||||
{
|
||||
public static bool IsUniqueViolation(DbUpdateException ex) =>
|
||||
ex.InnerException?.Message.Contains("23505") == true
|
||||
|| ex.InnerException?.Message.Contains("unique constraint") == true;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public abstract class DomainException : Exception
|
||||
{
|
||||
public string ErrorCode { get; }
|
||||
|
||||
protected DomainException(string message, string errorCode) : base(message)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class NotFoundException : DomainException
|
||||
{
|
||||
public NotFoundException(string message, string errorCode = "NOT_FOUND")
|
||||
: base(message, errorCode) { }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class ValidationException : DomainException
|
||||
{
|
||||
public ValidationException(string message, string errorCode = "VALIDATION_ERROR")
|
||||
: base(message, errorCode) { }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public record PagedResult<T>(
|
||||
IReadOnlyList<T> Items,
|
||||
int Page,
|
||||
int PageSize,
|
||||
int TotalCount
|
||||
)
|
||||
{
|
||||
public int TotalPages => (int)Math.Ceiling((double)TotalCount/PageSize);
|
||||
}
|
||||
Reference in New Issue
Block a user