chore: 初始化项目基础文件
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
namespace TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
|
||||
/// <summary>
|
||||
/// 统一错误码常量。
|
||||
/// </summary>
|
||||
public static class ErrorCodes
|
||||
{
|
||||
public const int BadRequest = 400;
|
||||
public const int Unauthorized = 401;
|
||||
public const int Forbidden = 403;
|
||||
public const int NotFound = 404;
|
||||
public const int Conflict = 409;
|
||||
public const int ValidationFailed = 422;
|
||||
public const int InternalServerError = 500;
|
||||
|
||||
// 业务自定义区间(10000+)
|
||||
public const int BusinessError = 10001;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace TakeoutSaaS.Shared.Abstractions.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 审计字段接口
|
||||
/// </summary>
|
||||
public interface IAuditableEntity
|
||||
{
|
||||
DateTime CreatedAt { get; set; }
|
||||
DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace TakeoutSaaS.Shared.Abstractions.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// 业务异常(用于可预期的业务校验错误)。
|
||||
/// </summary>
|
||||
public class BusinessException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 业务错误码。
|
||||
/// </summary>
|
||||
public int ErrorCode { get; }
|
||||
|
||||
public BusinessException(int errorCode, string message) : base(message)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TakeoutSaaS.Shared.Abstractions.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// 验证异常(用于聚合验证错误信息)。
|
||||
/// </summary>
|
||||
public class ValidationException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 字段/属性的错误集合。
|
||||
/// </summary>
|
||||
public IDictionary<string, string[]> Errors { get; }
|
||||
|
||||
public ValidationException(IDictionary<string, string[]> errors)
|
||||
: base("一个或多个验证错误")
|
||||
{
|
||||
Errors = errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
public interface ITenantProvider
|
||||
{
|
||||
Guid GetCurrentTenantId();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user