[backend] Reformat and SuppressMessage in BiteBack

This commit is contained in:
pancakes 2024-10-20 17:06:47 +10:00 committed by Iceshrimp development
parent ed81306ef1
commit c0ac326622

View file

@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using System.Net; using System.Net;
using System.Net.Mime; using System.Net.Mime;
using Iceshrimp.Backend.Controllers.Shared.Attributes; using Iceshrimp.Backend.Controllers.Shared.Attributes;
@ -27,18 +28,22 @@ public class MiscController(DatabaseContext db, NoteRenderer noteRenderer, BiteS
[Authorize] [Authorize]
[ProducesResults(HttpStatusCode.OK)] [ProducesResults(HttpStatusCode.OK)]
[ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)] [ProducesErrors(HttpStatusCode.BadRequest, HttpStatusCode.NotFound)]
[SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataUsage",
Justification = "IncludeCommonProperties")]
[SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataQuery",
Justification = "IncludeCommonProperties")]
public async Task BiteBack(string id) public async Task BiteBack(string id)
{ {
var user = HttpContext.GetUserOrFail(); var user = HttpContext.GetUserOrFail();
var target = await db.Bites var target = await db.Bites
.IncludeCommonProperties() .IncludeCommonProperties()
.Where(p => p.Id == id) .Where(p => p.Id == id)
.FirstOrDefaultAsync() .FirstOrDefaultAsync() ??
?? throw GracefulException.NotFound("Bite not found"); throw GracefulException.NotFound("Bite not found");
if (user.Id != (target.TargetUserId ?? target.TargetNote?.UserId ?? target.TargetBite?.UserId)) if (user.Id != (target.TargetUserId ?? target.TargetNote?.UserId ?? target.TargetBite?.UserId))
throw GracefulException.BadRequest("You can only bite back at a user who bit you"); throw GracefulException.BadRequest("You can only bite back at a user who bit you");
await biteSvc.BiteAsync(user, target); await biteSvc.BiteAsync(user, target);
} }