using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XYY.Core.Standard.Mvc;
using XYY.Service.Standard.Channel;
using XYY.Service.Standard.Channel.Model;

namespace XYY.API.SINO.Order.Controllers
{
    [Route("api/[controller]/[action]")]
    public class BaseInfoController : ApiControllerBase
    {
        IChannelService _channelService;
        public BaseInfoController(IChannelService channelService)
        {
            _channelService = channelService;
        }

        [HttpGet]
        [HttpPost]
        public async Task<IActionResult> GetAllPublic()
        {
            var channels = await _channelService.CacheGetAllPublic();


            if (channels?.Any() == true)
            {
                var dtos = channels.Select(c => new PublicChannelDto
                {
                    Code = c.Code,
                    Id = c.Id,
                    Name = c.Name
                }).ToList();
                return Ok(dtos);
            }
            else
                return Error("无数据");
        }
    }
}
