live-forum/server/webapi/LiveForum/LiveForum.WebApi/Controllers/SearchController.cs
2026-03-24 11:27:37 +08:00

56 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using LiveForum.Code.Base;
using LiveForum.IService.Others;
using LiveForum.Model.Dto.Others;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace LiveForum.WebApi.Controllers
{
/// <summary>
/// 搜索相关接口
/// </summary>
/// <param name="search"></param>
[Route("api/[controller]/[action]")]
[ApiController]
public class SearchController(ISearchService search) : ControllerBase
{
/// <summary>
/// 搜索
/// </summary>
/// <param name="keyword">搜索关键词</param>
/// <param name="searchType">搜索类型1-帖子2-用户默认1</param>
/// <param name="pageIndex">页码从1开始默认1</param>
/// <param name="pageSize">每页数量默认20</param>
/// <returns></returns>
[HttpGet]
public async Task<BaseResponse<SearchRespDto>> Search(string keyword, int searchType = 1, int pageIndex = 1, int pageSize = 20)
{
var request = new SearchReq
{
Keyword = keyword,
SearchType = searchType,
PageIndex = pageIndex,
PageSize = pageSize
};
return await search.Search(request);
}
/// <summary>
/// 获取热门搜索关键词
/// </summary>
/// <param name="limit">返回数量默认10</param>
/// <returns></returns>
[HttpGet]
public async Task<BaseResponseList<HotKeywordDto>> GetHotKeywords(int limit = 10)
{
var request = new GetHotKeywordsReq
{
Limit = limit
};
return await search.GetHotKeywords(request);
}
}
}