feat: add medal module and optimize community entities
1. 新增勋章管理全流程功能,包含实体、DTO、服务层、控制器 2. 重构DotFile实体继承基础实体类 3. 删除UserJournal的无用JournalInstanceId字段 4. 重构CommunityMessage实体字段并新增点赞数、精选标记字段 5. 新增社区点赞、评论、模板言论实体并替换旧有实体文件 6. 更新gitignore忽略PROJECT_STRUCTURE.md文件
This commit is contained in:
@ -0,0 +1,99 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.WebApi.Controllers.WeChat;
|
||||
|
||||
/// <summary>
|
||||
/// 小程序勋章控制器
|
||||
/// </summary>
|
||||
public class WeChatMedalController(IMedalService medalService, ILogger<WeChatMedalController> logger) : WeChatBaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有勋章列表(含当前用户拥有状态)
|
||||
/// </summary>
|
||||
[HttpGet("all")]
|
||||
public async Task<BaseResponse<List<WxMedalListOutput>>> GetAllMedals()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await medalService.GetAllMedalsAsync(userId.Value);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "获取勋章列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取勋章列表系统异常");
|
||||
return BaseResponse<List<WxMedalListOutput>>.Fail("获取勋章列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户已拥有的勋章列表
|
||||
/// </summary>
|
||||
[HttpGet("my")]
|
||||
public async Task<BaseResponse<List<WxUserMedalOutput>>> GetUserMedals()
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
var result = await medalService.GetUserMedalsAsync(userId.Value);
|
||||
return Success(result);
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "获取用户勋章列表业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "获取用户勋章列表系统异常");
|
||||
return BaseResponse<List<WxUserMedalOutput>>.Fail("获取用户勋章列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 激活/获得勋章
|
||||
/// </summary>
|
||||
[HttpPost("activate")]
|
||||
public async Task<BaseResponse<object>> ActivateMedal([FromBody] WxMedalActivateInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userId = GetCurrentUserId();
|
||||
if (userId == null)
|
||||
{
|
||||
return BaseResponse<object>.Fail(ResultCode.DENY, "未获取到用户信息");
|
||||
}
|
||||
|
||||
await medalService.ActivateMedalAsync(userId.Value, input);
|
||||
return Success<object>(null!, "勋章激活成功");
|
||||
}
|
||||
catch (BusinessException ex)
|
||||
{
|
||||
logger.LogWarning(ex, "激活勋章业务异常: {Message}", ex.Message);
|
||||
return BaseResponse<object>.Fail(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "激活勋章系统异常,参数:{Input}", input);
|
||||
return BaseResponse<object>.Fail("激活勋章失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user