mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-13 05:12:27 +00:00
Refactor Database into DatabaseContext Moved into separate folder so it actually has a namespace instead sitting in the root
39 lines
No EOL
1.2 KiB
C#
39 lines
No EOL
1.2 KiB
C#
using LBPUnion.ProjectLighthouse.Database;
|
|
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
|
|
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Moderator;
|
|
|
|
[ApiController]
|
|
[Route("moderation/case/{id:int}")]
|
|
public class ModerationCaseController : ControllerBase
|
|
{
|
|
private readonly DatabaseContext database;
|
|
|
|
public ModerationCaseController(DatabaseContext database)
|
|
{
|
|
this.database = database;
|
|
}
|
|
|
|
[HttpGet("dismiss")]
|
|
public async Task<IActionResult> DismissCase([FromRoute] int id)
|
|
{
|
|
User? user = this.database.UserFromWebRequest(this.Request);
|
|
if (user == null || !user.IsModerator) return this.StatusCode(403, "");
|
|
|
|
ModerationCase? @case = await this.database.Cases.FirstOrDefaultAsync(c => c.CaseId == id);
|
|
if (@case == null) return this.NotFound();
|
|
|
|
@case.DismissedAt = DateTime.Now;
|
|
@case.DismisserId = user.UserId;
|
|
@case.DismisserUsername = user.Username;
|
|
|
|
@case.Processed = false;
|
|
|
|
await this.database.SaveChangesAsync();
|
|
|
|
return this.Ok();
|
|
}
|
|
} |