using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Common.Page;
using GxPress.Request.ArticleGroup;
using GxPress.Request.Media;
using GxPress.Request.TeacherRequest;
using GxPress.Result.Media;
using GxPress.Result.SystemLabel;
using GxPress.Result.Teacher;
using GxPress.Service.Interface.AppHomePage;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using GxPress.Repository.Interface.Media;
using GxPress.EnumConst;
using GxPress.Common.Tools;
using GxPress.Result.Category;
using GxPress.Repository.Interface.Category;
using GxPress.Service.Interface.Media;
using GxPress.Result.Navigation;
using GxPress.Request.Navigation;
using GxPress.Result.AppChannel;
using GxPress.Service.Interface.AppChannel;
using GxPress.Request.AppChannel;
namespace GxPress.Api.AppControllers
{
///
/// App首页数据
///
[Route("api/app/page")]
[ApiController]
[Authorize]
public class AppPageController : Controller
{
private readonly IAppHomePageService appHomePageService;
private readonly IMediaRepository mediaRepository;
private readonly IMediaService mediaService;
private readonly ICategoryRepository categoryRepository;
private readonly IAppChannelService appChannelService;
public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository, ICategoryRepository categoryRepository, IMediaService mediaService, IAppChannelService appChannelService)
{
this.appHomePageService = appHomePageService;
this.mediaRepository = mediaRepository;
this.categoryRepository = categoryRepository;
this.mediaService = mediaService;
this.appChannelService = appChannelService;
}
///
/// 大咖讲座 每日好书
///
///
///
[HttpPost("cathedra")]
[AllowAnonymous]
public async Task>> GetMediasByTeacherAsync(ArticleGroupRequest request)
{
if (string.IsNullOrEmpty(request.StyleCss))
throw new Common.Exceptions.BusinessException("样式未知!");
return await appHomePageService.GetMediasByTeacherAsync(request);
}
///
/// 大咖讲座分页接口
///
///
[HttpPost("cathedra-page")]
[AllowAnonymous]
public async Task> MediaCathedraResult(ArticleGroupRequest request)
{
return await appHomePageService.MediaCathedraResult(request);
}
///
/// 每日好文
///
///
///
[HttpPost("day-good-text")]
[AllowAnonymous]
public async Task> GetDayGoodTextAsync(MediaSearchRequest request)
{
request.MediaType = GxPress.EnumConst.AllTypeConst.Article.GetHashCode();
request.IsDelete = 0;
request.IsChecked = 1;
return await appHomePageService.GetDayGoodTextAsync(request);
}
///
/// 每日微课
///
///
[HttpPost("day-we-book")]
[AllowAnonymous]
public async Task> GetDayWeBookAsync(MediaDayWeBookRequest request)
{
request.Name = "每日微课";
return await appHomePageService.GetDayWeBookAsync(request);
}
///
/// 信源听说
///
///
///
[HttpPost("chat-hear-speak")]
[AllowAnonymous]
public async Task> GetChatHearSpeak(MediaSearchRequest request)
{
request.MediaType = GxPress.EnumConst.AllTypeConst.Audio.GetHashCode();
request.IsDelete = 0;
request.IsChecked = 1;
return await appHomePageService.GetDayGoodTextAsync(request);
}
///
/// 根据标签ID获取每日好书 分页换一批
///
///
[HttpPost("lable")]
[AllowAnonymous]
public async Task> GetMediaByLableIdsAsync(MediaIdsRequest request)
{
return await appHomePageService.GetMediaByLableIdsAsync(request);
}
///
/// 根据标签ID获取分页数据
///
///
[HttpPost("page-lable")]
[AllowAnonymous]
public async Task> GetMediaByLableIdAsync(MediaLableIdRequest request)
{
return await appHomePageService.GetMediaByLableIdAsync(request);
}
///
/// 名师
///
///
///
[HttpPost("teacher")]
[AllowAnonymous]
public async Task> GetTeacherAsync(TeacherRequest request)
{
return await appHomePageService.GetTeacherAsync(request);
}
///
/// 每日技能分页
///
///
[HttpPost("day-skill")]
[AllowAnonymous]
public async Task> GetDaySkillsAsync(MediaDayWeBookRequest request)
{
request.TypeValue = AllTypeConst.Article.GetHashCode();
return await mediaRepository.GetDaySkillsAsync(request);
}
///
/// 随机每日技能
///
///
[HttpGet("random-day-skill")]
[AllowAnonymous]
public async Task GetRandomDaySkillAsync()
{
return await mediaRepository.GetRandomDaySkillAsync();
}
///
/// 书城
///
///
[HttpGet("book-city")]
[AllowAnonymous]
public async Task>> GetBookCityAsync()
{
ArticleGroupRequest request = new ArticleGroupRequest();
request.ActionUrl = "api/app/page/lable";
return await appHomePageService.GetBookCityAsync(request);
}
///
/// 猜你喜欢
///
///
[HttpGet("user-like")]
[AllowAnonymous]
public async Task> GetUserLikeAsync()
{
var result = await mediaRepository.GetUserLikeAsync();
foreach (var item in result)
{
item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
}
return result;
}
///
/// 导航内容分页
///
///
[HttpPost("content-navigation-list")]
[AllowAnonymous]
public async Task> GetContentNavigationAsync(MediaContentNavigationRequest request)
{
if (request.MediaIds == null)
request.MediaIds = new List();
return await appHomePageService.GetContentNavigationAsync(request);
}
///
/// 内容导航分类
///
///
[HttpGet("category")]
[AllowAnonymous]
public async Task> GetCategoryAllAsync()
{
return await categoryRepository.GetCategoryAllAsync(1);
}
///
/// 榜单
///
///
[HttpGet("ranking")]
[AllowAnonymous]
public async Task> GetRankingListResults()
{
var dictionary = new Dictionary() { { 2, "热书榜" }, { 3, "课程榜" }, { 4, "文献头条" }, { 6, "视听榜" } };
var dictionaryMedia = new Dictionary() { { AllTypeConst.Book.GetHashCode(), "热书榜" }, { AllTypeConst.Curriculum.GetHashCode(), "课程榜" }, { AllTypeConst.Article.GetHashCode(), "文献头条" }, { AllTypeConst.Audio.GetHashCode(), "视听榜" } };
var result = new List();
foreach (var item in dictionary)
{
var mediaRankingResult = new MediaRankingResult();
var request = new RankingListRequest();
request.DataTypeValue = item.Key;
mediaRankingResult.Name = item.Value;
mediaRankingResult.Items = await mediaRepository.GetRankingListResults(request);
foreach (var dic in dictionaryMedia)
{
if (dic.Value.Equals(item.Value))
mediaRankingResult.MediaType = dic.Key;
}
result.Add(mediaRankingResult);
}
return result;
}
///
/// 排行榜分页 1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
///
///
///
[HttpPost("ranking-page")]
[AllowAnonymous]
public async Task> GetRankingPageListResults(RankingListRequest request)
{
return await mediaRepository.GetRankingPageListResults(request);
}
///
/// 明栏
///
///
[HttpGet("star")]
[AllowAnonymous]
public async Task> GetMediaStarLableResultAysnc()
{
return await mediaService.GetMediaStarLableResultAysnc();
}
///
/// 明栏分页
///
///
[HttpPost("star-page")]
[AllowAnonymous]
public async Task> GetStarLablePageAsync(MediaStarLableRequest request)
{
return await mediaService.GetStarLablePageAsync(request);
}
///
/// 获取搜索内容
///
///
///
[HttpPost("navigation-search")]
[AllowAnonymous]
public async Task GetNavigationSearchResultAsync(NavigationSearchRequest request)
{
return await appHomePageService.GetNavigationSearchResultAsync(request);
}
///
/// 获取App频道
///
///
[HttpGet("channel")]
[AllowAnonymous]
public async Task> GetAppChannelsAsync()
{
return await appChannelService.GetAppChannelsAsync();
}
///
/// 查询 获取频道分类
///
///
[HttpGet("channel-category/{appChannelId}")]
[AllowAnonymous]
public async Task> GetAllAsync(int appChannelId)
{
return await appChannelService.GetAllAsync(appChannelId);
}
///
/// 根据频道分类ID获取分页数据
///
///
[HttpPost("channel-category-media")]
[AllowAnonymous]
public async Task> GetChannelCategoryMediaPageAsync(AppChannelSearchRequest request)
{
var result = new PagedList();
if (request.CategoryId > 0)
{
if (await appChannelService.IsChildrenAsync(request.CategoryId))
{
var categroys = await appChannelService.GetAllByParentIdAsync(request);
result.Total = categroys.Total;
var list = new List();
foreach (var item in categroys.Items)
{
list.Add(new MediaChannelCategoryResult { Id = item.Id, Name = item.Name, ExpandName = item.ExpandName, IsCategory = true });
}
result.Items = list;
return result;
}
//return await appChannelService.GetChannelCategoryMediaPageAsync(request);
}
return await appChannelService.GetChannelCategoryMediaPageAsync(request);
}
///
/// 书籍SKU
///
///
[HttpGet("sku")]
[AllowAnonymous]
public async Task SkuResultAsync()
{
return await appHomePageService.SkuResultAsync();
}
}
}