Skip to content

Commit

Permalink
Dropped support for user measures in the API V1
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha12 committed Oct 28, 2024
1 parent ef901f9 commit 0a3b72f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 167 deletions.
8 changes: 4 additions & 4 deletions src/GrillBot.App/Actions/ActionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ private static IServiceCollection AddApiActions(this IServiceCollection services
.AddScoped<Api.V1.User.UpdateUser>()
.AddScoped<Api.V1.User.Hearthbeat>();

services
.AddScoped<Api.V1.UserMeasures.CreateUserMeasuresWarning>()
.AddScoped<Api.V1.UserMeasures.GetUserMeasuresList>();

// V2
services
.AddScoped<Api.V2.GetTodayBirthdayInfo>()
Expand Down Expand Up @@ -232,6 +228,10 @@ private static IServiceCollection AddCommandsActions(this IServiceCollection ser
.AddScoped<Commands.Unverify.SetUnverify>()
.AddScoped<Commands.Unverify.UnverifyList>();

// UserMeasures
services
.AddScoped<Commands.UserMeasures.CreateUserMeasuresWarning>();

services
.AddScoped<Commands.Permissions.PermissionsCleaner>()
.AddScoped<Commands.Permissions.PermissionSetter>();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using GrillBot.Core.RabbitMQ.Publisher;
using GrillBot.Core.Services.UserMeasures.Models.Events;

namespace GrillBot.App.Actions.Commands.UserMeasures;

public class CreateUserMeasuresWarning : CommandAction
{
private readonly IRabbitPublisher _rabbitPublisher;

public CreateUserMeasuresWarning(IRabbitPublisher rabbitPublisher)
{
_rabbitPublisher = rabbitPublisher;
}

public Task ProcessAsync(IGuildUser user, string message, bool notification)
{
var moderatorId = Context.User.Id.ToString();
var guildId = user.GuildId.ToString();

var payload = new MemberWarningPayload(DateTime.UtcNow, message, guildId, moderatorId, user.Id.ToString(), notification);
return _rabbitPublisher.PublishAsync(payload);
}
}
41 changes: 2 additions & 39 deletions src/GrillBot.App/Controllers/UserMeasuresController.cs
Original file line number Diff line number Diff line change
@@ -1,65 +1,30 @@
using GrillBot.App.Actions;
using GrillBot.App.Actions.Api;
using GrillBot.App.Actions.Api.V1.UserMeasures;
using GrillBot.App.Actions.Api.V2.User;
using GrillBot.App.Infrastructure.Auth;
using GrillBot.Core.Models.Pagination;
using GrillBot.Core.Services.UserMeasures;
using GrillBot.Core.Services.UserMeasures.Models.Measures;
using GrillBot.Data.Models.API.UserMeasures;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace GrillBot.App.Controllers;

[ApiKeyAuth]
[Route("api/user/measures")]
[ApiExplorerSettings(GroupName = "v1")]
[ApiExplorerSettings(GroupName = "v2")]
public class UserMeasuresController : Core.Infrastructure.Actions.ControllerBase
{
public UserMeasuresController(IServiceProvider serviceProvider) : base(serviceProvider)
{
}

/// <summary>
/// Get paginated list of user measures.
/// </summary>
/// <response code="200">Returns paginated list of user measures.</response>
/// <response code="400">Validation of parameters failed.</response>
[HttpPost("list")]
[ProducesResponseType(typeof(PaginatedResponse<UserMeasuresListItem>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Admin")]
public async Task<IActionResult> GetUserMeasuresListAsync([FromBody] MeasuresListParams parameters)
{
ApiAction.Init(this, parameters);
return await ProcessAsync<GetUserMeasuresList>(parameters);
}

/// <summary>
/// Create new member warning.
/// </summary>
/// <response code="200">Creates new member warning</response>
/// <response code="400">Validation of parameters failed.</response>
[HttpPost("create")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status200OK)]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Admin")]
public async Task<IActionResult> CreateUserMeasuresWarningAsync([FromBody] CreateMemberWarningParams parameters)
{
ApiAction.Init(this, parameters);
return await ProcessAsync<CreateUserMeasuresWarning>(parameters);
}

/// <summary>
/// Create or update member timeout.
/// </summary>
/// <param name="parameters">Timeout parameters</param>
/// <response code="200">Timeout has been successfully created.</response>
/// <response code="400">Validation of parameters failed.</response>
[ApiKeyAuth]
[ApiExplorerSettings(GroupName = "v2")]
[HttpPost("timeout/create")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
Expand All @@ -76,8 +41,6 @@ public async Task<IActionResult> CreateUserMeasuresTimeoutAsync([FromBody] Creat
/// <response code="200">Timeout has been successfully deleted.</response>
/// <response code="400">Validation of parameters failed.</response>
/// <response code="404">Timeout wasn't found.</response>
[ApiKeyAuth]
[ApiExplorerSettings(GroupName = "v2")]
[HttpDelete("timeout/{timeoutId}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
Expand Down
2 changes: 1 addition & 1 deletion src/GrillBot.App/Modules/Interactions/User/UserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task CreateWarningAsync(
bool notification = true
)
{
using var command = GetActionAsCommand<Actions.Api.V1.UserMeasures.CreateUserMeasuresWarning>();
using var command = GetCommand<Actions.Commands.UserMeasures.CreateUserMeasuresWarning>();
await command.Command.ProcessAsync(user, message, notification);

await SetResponseAsync(GetText(nameof(CreateWarningAsync), "Success"));
Expand Down
10 changes: 0 additions & 10 deletions src/GrillBot.Data/Models/API/UserMeasures/UserMeasuresListItem.cs

This file was deleted.

0 comments on commit 0a3b72f

Please sign in to comment.