using CellularManagement.Application.Features.StackCoreIMSBindings.Commands.CreateStackCoreIMSBinding;
using CellularManagement.Application.Features.StackCoreIMSBindings.Commands.DeleteStackCoreIMSBinding;
using CellularManagement.Application.Features.StackCoreIMSBindings.Commands.UpdateStackCoreIMSBinding;
using CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindingById;
using CellularManagement.Application.Features.StackCoreIMSBindings.Queries.GetStackCoreIMSBindings;
using CellularManagement.Domain.Common;
using CellularManagement.Presentation.Abstractions;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace CellularManagement.Presentation.Controllers;
///
/// 栈核心网IMS绑定管理控制器
///
[Route("api/stackcoreimsbindings")]
[ApiController]
[Authorize]
public class StackCoreIMSBindingsController : ApiController
{
private readonly ILogger _logger;
///
/// 初始化栈核心网IMS绑定控制器
///
public StackCoreIMSBindingsController(IMediator mediator, ILogger logger)
: base(mediator)
{
_logger = logger;
}
///
/// 获取栈核心网IMS绑定列表
///
[HttpGet]
public async Task> GetAll([FromQuery] GetStackCoreIMSBindingsQuery query)
{
_logger.LogInformation("开始获取栈核心网IMS绑定列表,页码: {PageNumber}, 每页数量: {PageSize}, 栈ID: {StackId}, 核心网ID: {CnId}, IMS ID: {ImsId}",
query.PageNumber, query.PageSize, query.StackId, query.CnId, query.ImsId);
var result = await mediator.Send(query);
if (!result.IsSuccess)
{
_logger.LogWarning("获取栈核心网IMS绑定列表失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功获取栈核心网IMS绑定列表,共 {Count} 条记录", result.Data?.TotalCount ?? 0);
return result;
}
///
/// 获取栈核心网IMS绑定详情
///
[HttpGet("{id}")]
public async Task> GetById(string id)
{
_logger.LogInformation("开始获取栈核心网IMS绑定详情,绑定ID: {StackCoreIMSBindingId}", id);
var result = await mediator.Send(new GetStackCoreIMSBindingByIdQuery { StackCoreIMSBindingId = id });
if (!result.IsSuccess)
{
_logger.LogWarning("获取栈核心网IMS绑定详情失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功获取栈核心网IMS绑定详情,绑定ID: {StackCoreIMSBindingId}", id);
return result;
}
///
/// 创建栈核心网IMS绑定
///
[HttpPost]
public async Task> Create([FromBody] CreateStackCoreIMSBindingCommand command)
{
_logger.LogInformation("开始创建栈核心网IMS绑定,栈ID: {StackId}, 索引: {Index}, 核心网ID: {CnId}, IMS ID: {ImsId}",
command.StackId, command.Index, command.CnId, command.ImsId);
var result = await mediator.Send(command);
if (!result.IsSuccess)
{
_logger.LogWarning("创建栈核心网IMS绑定失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功创建栈核心网IMS绑定,绑定ID: {StackCoreIMSBindingId}", result.Data?.StackCoreIMSBindingId);
return result;
}
///
/// 更新栈核心网IMS绑定
///
[HttpPut("{id}")]
public async Task> Update(string id, [FromBody] UpdateStackCoreIMSBindingCommand command)
{
_logger.LogInformation("开始更新栈核心网IMS绑定,绑定ID: {StackCoreIMSBindingId}", id);
if (id != command.StackCoreIMSBindingId)
{
_logger.LogWarning("栈核心网IMS绑定ID不匹配,路径ID: {PathId}, 命令ID: {CommandId}", id, command.StackCoreIMSBindingId);
return OperationResult.CreateFailure("栈核心网IMS绑定ID不匹配");
}
var result = await mediator.Send(command);
if (!result.IsSuccess)
{
_logger.LogWarning("更新栈核心网IMS绑定失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功更新栈核心网IMS绑定,绑定ID: {StackCoreIMSBindingId}", id);
return result;
}
///
/// 删除栈核心网IMS绑定
///
[HttpDelete("{id}")]
public async Task> Delete(string id)
{
_logger.LogInformation("开始删除栈核心网IMS绑定,绑定ID: {StackCoreIMSBindingId}", id);
var result = await mediator.Send(new DeleteStackCoreIMSBindingCommand { StackCoreIMSBindingId = id });
if (!result.IsSuccess)
{
_logger.LogWarning("删除栈核心网IMS绑定失败: {Message}", result.ErrorMessages);
return result;
}
_logger.LogInformation("成功删除栈核心网IMS绑定,绑定ID: {StackCoreIMSBindingId}", id);
return result;
}
}