This commit is contained in:
Łukasz Domeradzki
2024-10-13 18:36:50 +02:00
parent dae03afc2d
commit f2b8897ed1

View File

@@ -74,34 +74,6 @@ public sealed class BotController : ArchiController {
return Ok(new GenericResponse<IReadOnlyDictionary<string, BotAddLicenseResponse>>(result));
}
/// <summary>
/// Redeems points on given bots.
/// </summary>
[Consumes("application/json")]
[HttpPost("{botNames:required}/RedeemPoints/{definitionID:required}")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, EResult>>>((int) HttpStatusCode.OK)]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
public async Task<ActionResult<GenericResponse>> AddLicensePost(string botNames, uint definitionID) {
ArgumentException.ThrowIfNullOrEmpty(botNames);
ArgumentOutOfRangeException.ThrowIfZero(definitionID);
HashSet<Bot>? bots = Bot.GetBots(botNames);
if ((bots == null) || (bots.Count == 0)) {
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
}
IList<EResult> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.RedeemPoints(definitionID))).ConfigureAwait(false);
Dictionary<string, EResult> result = new(bots.Count, Bot.BotsComparer);
foreach (Bot bot in bots) {
result[bot.BotName] = results[result.Count];
}
return Ok(new GenericResponse<IReadOnlyDictionary<string, EResult>>(result));
}
/// <summary>
/// Deletes all files related to given bots.
/// </summary>
@@ -346,6 +318,34 @@ public sealed class BotController : ArchiController {
return Ok(new GenericResponse(results.All(static result => result.Success), string.Join(Environment.NewLine, results.Select(static result => result.Message))));
}
/// <summary>
/// Redeems points on given bots.
/// </summary>
[Consumes("application/json")]
[HttpPost("{botNames:required}/RedeemPoints/{definitionID:required}")]
[ProducesResponseType<GenericResponse<IReadOnlyDictionary<string, EResult>>>((int) HttpStatusCode.OK)]
[ProducesResponseType<GenericResponse>((int) HttpStatusCode.BadRequest)]
public async Task<ActionResult<GenericResponse>> RedeemPointsPost(string botNames, uint definitionID) {
ArgumentException.ThrowIfNullOrEmpty(botNames);
ArgumentOutOfRangeException.ThrowIfZero(definitionID);
HashSet<Bot>? bots = Bot.GetBots(botNames);
if ((bots == null) || (bots.Count == 0)) {
return BadRequest(new GenericResponse(false, Strings.FormatBotNotFound(botNames)));
}
IList<EResult> results = await Utilities.InParallel(bots.Select(bot => bot.Actions.RedeemPoints(definitionID))).ConfigureAwait(false);
Dictionary<string, EResult> result = new(bots.Count, Bot.BotsComparer);
foreach (Bot bot in bots) {
result[bot.BotName] = results[result.Count];
}
return Ok(new GenericResponse<IReadOnlyDictionary<string, EResult>>(result));
}
/// <summary>
/// Redeems cd-keys on given bot.
/// </summary>