using YD_Event.Application.Auth;
using YD_Event.Application.Client.Dtos;
using YD_Event.Application.Config;
namespace YD_Event.Application.Client;
///
/// 博客基本信息
///
[AllowAnonymous]
[ApiDescriptionSettings("博客前端接口")]
public class AppController : IDynamicApiController
{
private readonly CustomConfigService _customConfigService;
private readonly ISqlSugarRepository _albumsRepository;
private readonly AuthManager _authManager;
private readonly ISqlSugarRepository _linkRepository;
public AppController(CustomConfigService customConfigService,
ISqlSugarRepository albumsRepository,
AuthManager authManager,
ISqlSugarRepository linkRepository)
{
_customConfigService = customConfigService;
_albumsRepository = albumsRepository;
_authManager = authManager;
_linkRepository = linkRepository;
}
///
/// 博客基本信息
///
///
[HttpGet]
public async Task Info()
{
var blogSetting = await _customConfigService.Get();
var info = await _customConfigService.Get();
var pics = await _albumsRepository.AsQueryable().InnerJoin((albums, pictures) => albums.Id == pictures.AlbumId)
.Where(albums => albums.Type.HasValue)
.WithCache()
.Select((albums, pictures) => new
{
albums.Type,
pictures.Url
}).ToListAsync();
var dictionary = pics.GroupBy(x => x.Type)
.ToDictionary(x => x.Key.ToString(), v => v.Select(x => x.Url).ToList());
return new BlogOutput { Site = blogSetting, Info = info, Covers = dictionary };
}
///
/// 友情链接
///
///
[HttpGet]
public async Task> Links()
{
return await _linkRepository.AsQueryable().Where(x => x.Status == AvailabilityStatus.Enable)
.OrderBy(x => x.Sort)
.OrderBy(x => x.Id)
.Select(x => new FriendLinkOutput
{
Id = x.Id,
Link = x.Link,
Logo = x.Logo,
SiteName = x.SiteName,
Remark = x.Remark
}).ToListAsync();
}
}