using Application.Domain.Services;
using Application.Web.Model.RequestParms.Maxname;
using Microsoft.AspNetCore.Mvc;
namespace Application.Web.Controllers.Pub
{
///
/// 徽章接口
///
[Route("[controller]/[action]")]
[ApiController]
[Authorize]
public class BadgeController : ControllerBase
{
private readonly IGameBadgeService badgeService;
public BadgeController(IGameBadgeService _badgeService)
{
badgeService = _badgeService;
}
///
/// 获取用户徽章列表
///
///
///
[HttpGet]
public async Task GetUserBadgeList(int page)
{
RefAsync total = 0;
string userId = StateHelper.userId;
var list = await badgeService.GetUserBadgeList(userId, page, 10, total);
return PoAction.Ok(new { list, total });
}
///
/// 获取徽章详情
///
///
///
[HttpGet]
public async Task GetUserBadgeInfo(string ubId)
{
var data = await badgeService.GetUserBadegInfo(ubId);
if (data == null)
{
return PoAction.Message("徽章信息不存在!");
}
string userId = StateHelper.userId;
if (data.userId != userId)
{
return PoAction.Message("徽章信息不存在!");
}
return PoAction.Ok(new { data });
}
///
/// 修改徽章展示不展示
///
///
///
[HttpPost]
public async Task UpdateBadgeShow([FromBody] UpdateBadgeParms par)
{
var data = await badgeService.GetUserBadegInfo(par.ubId);
if (data == null)
{
return PoAction.Message("徽章信息不存在!");
}
string userId = StateHelper.userId;
if (data.userId != userId)
{
return PoAction.Message("徽章信息不存在!");
}
//int onCount = await badgeService.GetUserShowBadgeOnCount(userId);
//int showCount = await badgeService.GetUserShowBadgeCount(userId);
//if (onCount == 0)
//{
// if (showCount >= 1)
// {
// return PoAction.Message("您最多可以同时展示1个徽章!");
// }
//}
//else
//{
// if (showCount >= onCount)
// {
// return PoAction.Message(string.Format("您最多可以同时展示{0}个徽章!", onCount));
// }
//}
int show = data.show == 1 ? 0 : 1;
if (await badgeService.UpdateUserBadgeShow(par.ubId, show))
{
return PoAction.Ok("操作成功!");
}
else
{
return PoAction.Message("操作失败!");
}
}
}
}