feat: 管理端核心实体CRUD补齐
This commit is contained in:
108
src/Api/TakeoutSaaS.AdminApi/Controllers/DeliveriesController.cs
Normal file
108
src/Api/TakeoutSaaS.AdminApi/Controllers/DeliveriesController.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TakeoutSaaS.Application.App.Deliveries.Commands;
|
||||
using TakeoutSaaS.Application.App.Deliveries.Dto;
|
||||
using TakeoutSaaS.Application.App.Deliveries.Queries;
|
||||
using TakeoutSaaS.Domain.Deliveries.Enums;
|
||||
using TakeoutSaaS.Module.Authorization.Attributes;
|
||||
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
using TakeoutSaaS.Shared.Web.Api;
|
||||
|
||||
namespace TakeoutSaaS.AdminApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 配送单管理。
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Authorize]
|
||||
[Route("api/admin/v{version:apiVersion}/deliveries")]
|
||||
public sealed class DeliveriesController : BaseApiController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化控制器。
|
||||
/// </summary>
|
||||
public DeliveriesController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建配送单。
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[PermissionAuthorize("delivery:create")]
|
||||
[ProducesResponseType(typeof(ApiResponse<DeliveryOrderDto>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<DeliveryOrderDto>> Create([FromBody] CreateDeliveryOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return ApiResponse<DeliveryOrderDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询配送单列表。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[PermissionAuthorize("delivery:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<DeliveryOrderDto>>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<IReadOnlyList<DeliveryOrderDto>>> List([FromQuery] long? orderId, [FromQuery] DeliveryStatus? status, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new SearchDeliveryOrdersQuery
|
||||
{
|
||||
OrderId = orderId,
|
||||
Status = status
|
||||
}, cancellationToken);
|
||||
|
||||
return ApiResponse<IReadOnlyList<DeliveryOrderDto>>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配送单详情。
|
||||
/// </summary>
|
||||
[HttpGet("{deliveryOrderId:long}")]
|
||||
[PermissionAuthorize("delivery:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<DeliveryOrderDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<DeliveryOrderDto>> Detail(long deliveryOrderId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new GetDeliveryOrderByIdQuery { DeliveryOrderId = deliveryOrderId }, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<DeliveryOrderDto>.Error(ErrorCodes.NotFound, "配送单不存在")
|
||||
: ApiResponse<DeliveryOrderDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新配送单。
|
||||
/// </summary>
|
||||
[HttpPut("{deliveryOrderId:long}")]
|
||||
[PermissionAuthorize("delivery:update")]
|
||||
[ProducesResponseType(typeof(ApiResponse<DeliveryOrderDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<DeliveryOrderDto>> Update(long deliveryOrderId, [FromBody] UpdateDeliveryOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
command.DeliveryOrderId = command.DeliveryOrderId == 0 ? deliveryOrderId : command.DeliveryOrderId;
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<DeliveryOrderDto>.Error(ErrorCodes.NotFound, "配送单不存在")
|
||||
: ApiResponse<DeliveryOrderDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除配送单。
|
||||
/// </summary>
|
||||
[HttpDelete("{deliveryOrderId:long}")]
|
||||
[PermissionAuthorize("delivery:delete")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<object>> Delete(long deliveryOrderId, CancellationToken cancellationToken)
|
||||
{
|
||||
var success = await _mediator.Send(new DeleteDeliveryOrderCommand { DeliveryOrderId = deliveryOrderId }, cancellationToken);
|
||||
return success
|
||||
? ApiResponse<object>.Ok(null)
|
||||
: ApiResponse<object>.Error(ErrorCodes.NotFound, "配送单不存在");
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,38 @@ public sealed class MerchantsController : BaseApiController
|
||||
return ApiResponse<IReadOnlyList<MerchantDto>>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新商户。
|
||||
/// </summary>
|
||||
[HttpPut("{merchantId:long}")]
|
||||
[PermissionAuthorize("merchant:update")]
|
||||
[ProducesResponseType(typeof(ApiResponse<MerchantDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<MerchantDto>> Update(long merchantId, [FromBody] UpdateMerchantCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
command.MerchantId = command.MerchantId == 0 ? merchantId : command.MerchantId;
|
||||
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<MerchantDto>.Error(ErrorCodes.NotFound, "商户不存在")
|
||||
: ApiResponse<MerchantDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除商户。
|
||||
/// </summary>
|
||||
[HttpDelete("{merchantId:long}")]
|
||||
[PermissionAuthorize("merchant:delete")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<object>> Delete(long merchantId, CancellationToken cancellationToken)
|
||||
{
|
||||
var success = await _mediator.Send(new DeleteMerchantCommand { MerchantId = merchantId }, cancellationToken);
|
||||
return success
|
||||
? ApiResponse<object>.Ok(null)
|
||||
: ApiResponse<object>.Error(ErrorCodes.NotFound, "商户不存在");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商户详情。
|
||||
/// </summary>
|
||||
|
||||
116
src/Api/TakeoutSaaS.AdminApi/Controllers/OrdersController.cs
Normal file
116
src/Api/TakeoutSaaS.AdminApi/Controllers/OrdersController.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TakeoutSaaS.Application.App.Orders.Commands;
|
||||
using TakeoutSaaS.Application.App.Orders.Dto;
|
||||
using TakeoutSaaS.Application.App.Orders.Queries;
|
||||
using TakeoutSaaS.Domain.Orders.Enums;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
using TakeoutSaaS.Module.Authorization.Attributes;
|
||||
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
using TakeoutSaaS.Shared.Web.Api;
|
||||
|
||||
namespace TakeoutSaaS.AdminApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 订单管理。
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Authorize]
|
||||
[Route("api/admin/v{version:apiVersion}/orders")]
|
||||
public sealed class OrdersController : BaseApiController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化控制器。
|
||||
/// </summary>
|
||||
public OrdersController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建订单。
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[PermissionAuthorize("order:create")]
|
||||
[ProducesResponseType(typeof(ApiResponse<OrderDto>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<OrderDto>> Create([FromBody] CreateOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return ApiResponse<OrderDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询订单列表。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[PermissionAuthorize("order:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<OrderDto>>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<IReadOnlyList<OrderDto>>> List(
|
||||
[FromQuery] long? storeId,
|
||||
[FromQuery] OrderStatus? status,
|
||||
[FromQuery] PaymentStatus? paymentStatus,
|
||||
[FromQuery] string? orderNo,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new SearchOrdersQuery
|
||||
{
|
||||
StoreId = storeId,
|
||||
Status = status,
|
||||
PaymentStatus = paymentStatus,
|
||||
OrderNo = orderNo
|
||||
}, cancellationToken);
|
||||
|
||||
return ApiResponse<IReadOnlyList<OrderDto>>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取订单详情。
|
||||
/// </summary>
|
||||
[HttpGet("{orderId:long}")]
|
||||
[PermissionAuthorize("order:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<OrderDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<OrderDto>> Detail(long orderId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new GetOrderByIdQuery { OrderId = orderId }, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<OrderDto>.Error(ErrorCodes.NotFound, "订单不存在")
|
||||
: ApiResponse<OrderDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新订单。
|
||||
/// </summary>
|
||||
[HttpPut("{orderId:long}")]
|
||||
[PermissionAuthorize("order:update")]
|
||||
[ProducesResponseType(typeof(ApiResponse<OrderDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<OrderDto>> Update(long orderId, [FromBody] UpdateOrderCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
command.OrderId = command.OrderId == 0 ? orderId : command.OrderId;
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<OrderDto>.Error(ErrorCodes.NotFound, "订单不存在")
|
||||
: ApiResponse<OrderDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除订单。
|
||||
/// </summary>
|
||||
[HttpDelete("{orderId:long}")]
|
||||
[PermissionAuthorize("order:delete")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<object>> Delete(long orderId, CancellationToken cancellationToken)
|
||||
{
|
||||
var success = await _mediator.Send(new DeleteOrderCommand { OrderId = orderId }, cancellationToken);
|
||||
return success
|
||||
? ApiResponse<object>.Ok(null)
|
||||
: ApiResponse<object>.Error(ErrorCodes.NotFound, "订单不存在");
|
||||
}
|
||||
}
|
||||
108
src/Api/TakeoutSaaS.AdminApi/Controllers/PaymentsController.cs
Normal file
108
src/Api/TakeoutSaaS.AdminApi/Controllers/PaymentsController.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TakeoutSaaS.Application.App.Payments.Commands;
|
||||
using TakeoutSaaS.Application.App.Payments.Dto;
|
||||
using TakeoutSaaS.Application.App.Payments.Queries;
|
||||
using TakeoutSaaS.Domain.Payments.Enums;
|
||||
using TakeoutSaaS.Module.Authorization.Attributes;
|
||||
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
using TakeoutSaaS.Shared.Web.Api;
|
||||
|
||||
namespace TakeoutSaaS.AdminApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 支付记录管理。
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Authorize]
|
||||
[Route("api/admin/v{version:apiVersion}/payments")]
|
||||
public sealed class PaymentsController : BaseApiController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化控制器。
|
||||
/// </summary>
|
||||
public PaymentsController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建支付记录。
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[PermissionAuthorize("payment:create")]
|
||||
[ProducesResponseType(typeof(ApiResponse<PaymentDto>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<PaymentDto>> Create([FromBody] CreatePaymentCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return ApiResponse<PaymentDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询支付记录列表。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[PermissionAuthorize("payment:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<PaymentDto>>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<IReadOnlyList<PaymentDto>>> List([FromQuery] long? orderId, [FromQuery] PaymentStatus? status, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new SearchPaymentsQuery
|
||||
{
|
||||
OrderId = orderId,
|
||||
Status = status
|
||||
}, cancellationToken);
|
||||
|
||||
return ApiResponse<IReadOnlyList<PaymentDto>>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取支付记录详情。
|
||||
/// </summary>
|
||||
[HttpGet("{paymentId:long}")]
|
||||
[PermissionAuthorize("payment:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<PaymentDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<PaymentDto>> Detail(long paymentId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new GetPaymentByIdQuery { PaymentId = paymentId }, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<PaymentDto>.Error(ErrorCodes.NotFound, "支付记录不存在")
|
||||
: ApiResponse<PaymentDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新支付记录。
|
||||
/// </summary>
|
||||
[HttpPut("{paymentId:long}")]
|
||||
[PermissionAuthorize("payment:update")]
|
||||
[ProducesResponseType(typeof(ApiResponse<PaymentDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<PaymentDto>> Update(long paymentId, [FromBody] UpdatePaymentCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
command.PaymentId = command.PaymentId == 0 ? paymentId : command.PaymentId;
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<PaymentDto>.Error(ErrorCodes.NotFound, "支付记录不存在")
|
||||
: ApiResponse<PaymentDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除支付记录。
|
||||
/// </summary>
|
||||
[HttpDelete("{paymentId:long}")]
|
||||
[PermissionAuthorize("payment:delete")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<object>> Delete(long paymentId, CancellationToken cancellationToken)
|
||||
{
|
||||
var success = await _mediator.Send(new DeletePaymentCommand { PaymentId = paymentId }, cancellationToken);
|
||||
return success
|
||||
? ApiResponse<object>.Ok(null)
|
||||
: ApiResponse<object>.Error(ErrorCodes.NotFound, "支付记录不存在");
|
||||
}
|
||||
}
|
||||
109
src/Api/TakeoutSaaS.AdminApi/Controllers/ProductsController.cs
Normal file
109
src/Api/TakeoutSaaS.AdminApi/Controllers/ProductsController.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TakeoutSaaS.Application.App.Products.Commands;
|
||||
using TakeoutSaaS.Application.App.Products.Dto;
|
||||
using TakeoutSaaS.Application.App.Products.Queries;
|
||||
using TakeoutSaaS.Domain.Products.Enums;
|
||||
using TakeoutSaaS.Module.Authorization.Attributes;
|
||||
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
using TakeoutSaaS.Shared.Web.Api;
|
||||
|
||||
namespace TakeoutSaaS.AdminApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 商品管理。
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Authorize]
|
||||
[Route("api/admin/v{version:apiVersion}/products")]
|
||||
public sealed class ProductsController : BaseApiController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化控制器。
|
||||
/// </summary>
|
||||
public ProductsController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建商品。
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[PermissionAuthorize("product:create")]
|
||||
[ProducesResponseType(typeof(ApiResponse<ProductDto>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<ProductDto>> Create([FromBody] CreateProductCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return ApiResponse<ProductDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询商品列表。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[PermissionAuthorize("product:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<ProductDto>>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<IReadOnlyList<ProductDto>>> List([FromQuery] long? storeId, [FromQuery] long? categoryId, [FromQuery] ProductStatus? status, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new SearchProductsQuery
|
||||
{
|
||||
StoreId = storeId,
|
||||
CategoryId = categoryId,
|
||||
Status = status
|
||||
}, cancellationToken);
|
||||
|
||||
return ApiResponse<IReadOnlyList<ProductDto>>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取商品详情。
|
||||
/// </summary>
|
||||
[HttpGet("{productId:long}")]
|
||||
[PermissionAuthorize("product:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<ProductDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<ProductDto>> Detail(long productId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new GetProductByIdQuery { ProductId = productId }, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<ProductDto>.Error(ErrorCodes.NotFound, "商品不存在")
|
||||
: ApiResponse<ProductDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新商品。
|
||||
/// </summary>
|
||||
[HttpPut("{productId:long}")]
|
||||
[PermissionAuthorize("product:update")]
|
||||
[ProducesResponseType(typeof(ApiResponse<ProductDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<ProductDto>> Update(long productId, [FromBody] UpdateProductCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
command.ProductId = command.ProductId == 0 ? productId : command.ProductId;
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<ProductDto>.Error(ErrorCodes.NotFound, "商品不存在")
|
||||
: ApiResponse<ProductDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除商品。
|
||||
/// </summary>
|
||||
[HttpDelete("{productId:long}")]
|
||||
[PermissionAuthorize("product:delete")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<object>> Delete(long productId, CancellationToken cancellationToken)
|
||||
{
|
||||
var success = await _mediator.Send(new DeleteProductCommand { ProductId = productId }, cancellationToken);
|
||||
return success
|
||||
? ApiResponse<object>.Ok(null)
|
||||
: ApiResponse<object>.Error(ErrorCodes.NotFound, "商品不存在");
|
||||
}
|
||||
}
|
||||
108
src/Api/TakeoutSaaS.AdminApi/Controllers/StoresController.cs
Normal file
108
src/Api/TakeoutSaaS.AdminApi/Controllers/StoresController.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Application.App.Stores.Queries;
|
||||
using TakeoutSaaS.Domain.Stores.Enums;
|
||||
using TakeoutSaaS.Module.Authorization.Attributes;
|
||||
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||
using TakeoutSaaS.Shared.Web.Api;
|
||||
|
||||
namespace TakeoutSaaS.AdminApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 门店管理。
|
||||
/// </summary>
|
||||
[ApiVersion("1.0")]
|
||||
[Authorize]
|
||||
[Route("api/admin/v{version:apiVersion}/stores")]
|
||||
public sealed class StoresController : BaseApiController
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化控制器。
|
||||
/// </summary>
|
||||
public StoresController(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建门店。
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[PermissionAuthorize("store:create")]
|
||||
[ProducesResponseType(typeof(ApiResponse<StoreDto>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<StoreDto>> Create([FromBody] CreateStoreCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return ApiResponse<StoreDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询门店列表。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[PermissionAuthorize("store:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<IReadOnlyList<StoreDto>>), StatusCodes.Status200OK)]
|
||||
public async Task<ApiResponse<IReadOnlyList<StoreDto>>> List([FromQuery] long? merchantId, [FromQuery] StoreStatus? status, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new SearchStoresQuery
|
||||
{
|
||||
MerchantId = merchantId,
|
||||
Status = status
|
||||
}, cancellationToken);
|
||||
|
||||
return ApiResponse<IReadOnlyList<StoreDto>>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取门店详情。
|
||||
/// </summary>
|
||||
[HttpGet("{storeId:long}")]
|
||||
[PermissionAuthorize("store:read")]
|
||||
[ProducesResponseType(typeof(ApiResponse<StoreDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<StoreDto>> Detail(long storeId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _mediator.Send(new GetStoreByIdQuery { StoreId = storeId }, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<StoreDto>.Error(ErrorCodes.NotFound, "门店不存在")
|
||||
: ApiResponse<StoreDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新门店。
|
||||
/// </summary>
|
||||
[HttpPut("{storeId:long}")]
|
||||
[PermissionAuthorize("store:update")]
|
||||
[ProducesResponseType(typeof(ApiResponse<StoreDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<StoreDto>> Update(long storeId, [FromBody] UpdateStoreCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
command.StoreId = command.StoreId == 0 ? storeId : command.StoreId;
|
||||
var result = await _mediator.Send(command, cancellationToken);
|
||||
return result == null
|
||||
? ApiResponse<StoreDto>.Error(ErrorCodes.NotFound, "门店不存在")
|
||||
: ApiResponse<StoreDto>.Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除门店。
|
||||
/// </summary>
|
||||
[HttpDelete("{storeId:long}")]
|
||||
[PermissionAuthorize("store:delete")]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||
public async Task<ApiResponse<object>> Delete(long storeId, CancellationToken cancellationToken)
|
||||
{
|
||||
var success = await _mediator.Send(new DeleteStoreCommand { StoreId = storeId }, cancellationToken);
|
||||
return success
|
||||
? ApiResponse<object>.Ok(null)
|
||||
: ApiResponse<object>.Error(ErrorCodes.NotFound, "门店不存在");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user