chore: 初始化项目基础文件

This commit is contained in:
2025-11-22 21:27:38 +08:00
parent b587e8c1e1
commit ddf584f212
49 changed files with 6629 additions and 15 deletions

View File

@@ -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;
}

View File

@@ -0,0 +1,11 @@
namespace TakeoutSaaS.Shared.Abstractions.Entities;
/// <summary>
/// 审计字段接口
/// </summary>
public interface IAuditableEntity
{
DateTime CreatedAt { get; set; }
DateTime? UpdatedAt { get; set; }
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,7 @@
namespace TakeoutSaaS.Shared.Abstractions.Tenancy;
public interface ITenantProvider
{
Guid GetCurrentTenantId();
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\TakeoutSaaS.Shared.Abstractions\TakeoutSaaS.Shared.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Mvc;
namespace TakeoutSaaS.Shared.Web.Api;
/// <summary>
/// API 基类控制器:
/// - 统一应用 [ApiController] 和默认响应类型
/// - 作为所有 API 控制器的基类,便于复用过滤器/中间件特性
/// </summary>
[ApiController]
[Produces("application/json")]
public abstract class BaseApiController : ControllerBase
{
}