using System.Collections.Generic; 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.Merchants.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; /// /// 门店员工管理。 /// [ApiVersion("1.0")] [Authorize] [Route("api/admin/v{version:apiVersion}/stores/{storeId:long}/staffs")] public sealed class StoreStaffsController(IMediator mediator) : BaseApiController { /// /// 查询门店员工列表。 /// [HttpGet] [PermissionAuthorize("store-staff:read")] [ProducesResponseType(typeof(ApiResponse>), StatusCodes.Status200OK)] public async Task>> List( long storeId, [FromQuery] StaffRoleType? role, [FromQuery] StaffStatus? status, CancellationToken cancellationToken) { var result = await mediator.Send(new ListStoreStaffQuery { StoreId = storeId, RoleType = role, Status = status }, cancellationToken); return ApiResponse>.Ok(result); } /// /// 创建门店员工。 /// [HttpPost] [PermissionAuthorize("store-staff:create")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] public async Task> Create(long storeId, [FromBody] CreateStoreStaffCommand command, CancellationToken cancellationToken) { if (command.StoreId == 0) { command = command with { StoreId = storeId }; } var result = await mediator.Send(command, cancellationToken); return ApiResponse.Ok(result); } /// /// 更新门店员工。 /// [HttpPut("{staffId:long}")] [PermissionAuthorize("store-staff:update")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task> Update(long storeId, long staffId, [FromBody] UpdateStoreStaffCommand command, CancellationToken cancellationToken) { if (command.StoreId == 0 || command.StaffId == 0) { command = command with { StoreId = storeId, StaffId = staffId }; } var result = await mediator.Send(command, cancellationToken); return result == null ? ApiResponse.Error(ErrorCodes.NotFound, "员工不存在") : ApiResponse.Ok(result); } /// /// 删除门店员工。 /// [HttpDelete("{staffId:long}")] [PermissionAuthorize("store-staff:delete")] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)] public async Task> Delete(long storeId, long staffId, CancellationToken cancellationToken) { var success = await mediator.Send(new DeleteStoreStaffCommand { StoreId = storeId, StaffId = staffId }, cancellationToken); return success ? ApiResponse.Ok(null) : ApiResponse.Error(ErrorCodes.NotFound, "员工不存在"); } }