39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using Mapster;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Volo.Abp.Application.Services;
|
|
using Yi.Framework.AiHub.Application.Contracts.Dtos;
|
|
using Yi.Framework.AiHub.Application.Contracts.IServices;
|
|
using Yi.Framework.AiHub.Domain.Entities;
|
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
|
|
|
namespace Yi.Framework.AiHub.Application.Services;
|
|
|
|
/// <summary>
|
|
/// 排行榜服务
|
|
/// </summary>
|
|
public class RankingService : ApplicationService, IRankingService
|
|
{
|
|
private readonly ISqlSugarRepository<RankingItemAggregateRoot, Guid> _repository;
|
|
|
|
public RankingService(ISqlSugarRepository<RankingItemAggregateRoot, Guid> repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取排行榜列表(全量返回,按得分降序)
|
|
/// </summary>
|
|
[HttpGet("ranking/list")]
|
|
[AllowAnonymous]
|
|
public async Task<List<RankingItemDto>> GetListAsync([FromQuery] RankingGetListInput input)
|
|
{
|
|
var query = _repository._DbQueryable
|
|
.WhereIF(input.Type.HasValue, x => x.Type == input.Type!.Value)
|
|
.OrderByDescending(x => x.Score);
|
|
|
|
var entities = await query.ToListAsync();
|
|
return entities.Adapt<List<RankingItemDto>>();
|
|
}
|
|
}
|