fix(risk-control): fix code quality issues in FastEndpoints APIs

This commit is contained in:
Sam 2026-02-05 15:17:43 +08:00
parent 1ac028643f
commit f76f81ec55
4 changed files with 13 additions and 28 deletions

View File

@ -31,7 +31,7 @@ public class ParticipateLotteryEndpoint : Endpoint<ParticipateLotteryRequest, Lo
MemberId = req.MemberId, MemberId = req.MemberId,
ActivityType = req.ActivityType, ActivityType = req.ActivityType,
StakePoints = req.StakePoints, StakePoints = req.StakePoints,
IpAddress = HttpContext.Connection.RemoteIpAddress?.ToString(), IpAddress = HttpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown",
DeviceId = HttpContext.Request.Headers["X-Device-ID"].FirstOrDefault() DeviceId = HttpContext.Request.Headers["X-Device-ID"].FirstOrDefault()
}, ct); }, ct);
@ -41,11 +41,8 @@ public class ParticipateLotteryEndpoint : Endpoint<ParticipateLotteryRequest, Lo
public class ParticipateLotteryRequest public class ParticipateLotteryRequest
{ {
[Microsoft.AspNetCore.Mvc.FromBody]
public long MemberId { get; set; } public long MemberId { get; set; }
[Microsoft.AspNetCore.Mvc.FromBody]
public string ActivityType { get; set; } = string.Empty; public string ActivityType { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public int StakePoints { get; set; } public int StakePoints { get; set; }
} }

View File

@ -36,7 +36,7 @@ public class GetPendingAlertsEndpoint : Endpoint<EmptyRequest, IEnumerable<RiskA
} }
} }
public class GetPendingAlertsQuery : IRequest<IEnumerable<RiskAlert>> public class GetPendingAlertsQuery : IRequest<IEnumerable<RiskAlertResponse>>
{ {
} }
@ -74,16 +74,7 @@ public class ResolveAlertEndpoint : Endpoint<ResolveAlertRequest, RiskAlertRespo
Notes = req.Notes Notes = req.Notes
}, ct); }, ct);
Response = new RiskAlertResponse Response = alert;
{
Id = alert.Id,
MemberId = alert.MemberId,
AlertType = alert.AlertType,
Description = alert.Description,
Priority = alert.Priority.ToString(),
Status = alert.Status.ToString(),
CreatedAt = alert.CreatedAt
};
} }
} }
@ -91,11 +82,10 @@ public class ResolveAlertRequest
{ {
[Microsoft.AspNetCore.Mvc.FromRoute] [Microsoft.AspNetCore.Mvc.FromRoute]
public long AlertId { get; set; } public long AlertId { get; set; }
[Microsoft.AspNetCore.Mvc.FromBody]
public string Notes { get; set; } = string.Empty; public string Notes { get; set; } = string.Empty;
} }
public record ResolveAlertCommand : IRequest<RiskAlert> public record ResolveAlertCommand : IRequest<RiskAlertResponse>
{ {
public long AlertId { get; init; } public long AlertId { get; init; }
public string Notes { get; init; } = string.Empty; public string Notes { get; init; } = string.Empty;

View File

@ -41,14 +41,9 @@ public class EvaluateRiskEndpoint : Endpoint<EvaluateRiskRequest, RiskEvaluation
public class EvaluateRiskRequest public class EvaluateRiskRequest
{ {
[Microsoft.AspNetCore.Mvc.FromBody]
public long MemberId { get; set; } public long MemberId { get; set; }
[Microsoft.AspNetCore.Mvc.FromBody]
public string EntityType { get; set; } = string.Empty; public string EntityType { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public string EntityId { get; set; } = string.Empty; public string EntityId { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public string ActionType { get; set; } = string.Empty; public string ActionType { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public Dictionary<string, object>? Context { get; set; } public Dictionary<string, object>? Context { get; set; }
} }

View File

@ -22,6 +22,15 @@ public class CreateRiskRuleEndpoint : Endpoint<CreateRiskRuleRequest, RiskRuleRe
public override async Task HandleAsync(CreateRiskRuleRequest req, CancellationToken ct) public override async Task HandleAsync(CreateRiskRuleRequest req, CancellationToken ct)
{ {
if (!Enum.IsDefined(typeof(RiskRuleType), req.RuleType))
{
ThrowError($"无效的规则类型: {req.RuleType}");
}
if (!Enum.IsDefined(typeof(RiskRuleAction), req.Action))
{
ThrowError($"无效的规则动作: {req.Action}");
}
var rule = await _mediator.Send(new CreateRiskRuleCommand var rule = await _mediator.Send(new CreateRiskRuleCommand
{ {
Name = req.Name, Name = req.Name,
@ -47,17 +56,11 @@ public class CreateRiskRuleEndpoint : Endpoint<CreateRiskRuleRequest, RiskRuleRe
public class CreateRiskRuleRequest public class CreateRiskRuleRequest
{ {
[Microsoft.AspNetCore.Mvc.FromBody]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public string Description { get; set; } = string.Empty; public string Description { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public int RuleType { get; set; } public int RuleType { get; set; }
[Microsoft.AspNetCore.Mvc.FromBody]
public int Action { get; set; } public int Action { get; set; }
[Microsoft.AspNetCore.Mvc.FromBody]
public string ConfigJson { get; set; } = string.Empty; public string ConfigJson { get; set; } = string.Empty;
[Microsoft.AspNetCore.Mvc.FromBody]
public int Priority { get; set; } public int Priority { get; set; }
} }