[backend/api] Add endpoint for deleting emojis

This commit is contained in:
pancakes 2024-06-24 17:34:54 +10:00 committed by Iceshrimp development
parent 6743442ce8
commit af376ffbe5
2 changed files with 24 additions and 0 deletions

View file

@ -278,4 +278,15 @@ public class AdminController(
return Ok(res);
}
[HttpDelete("emoji/{id}")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(string))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ErrorResponse))]
public async Task<IActionResult> DeleteEmoji(string id)
{
var emojiId = await emojiSvc.DeleteEmoji(id);
if (emojiId == null) return NotFound();
return Ok(emojiId);
}
}

View file

@ -59,6 +59,19 @@ public partial class EmojiService(DatabaseContext db, DriveService driveSvc, Sys
return emoji;
}
public async Task<string?> DeleteEmoji(string id)
{
var emoji = await db.Emojis.FirstOrDefaultAsync(p => p.Id == id);
if (emoji == null) return null;
var emojiId = emoji.Id;
db.Remove(emoji);
await db.SaveChangesAsync();
return emojiId;
}
public async Task<List<Emoji>> ProcessEmojiAsync(List<ASEmoji>? emoji, string host)
{
emoji?.RemoveAll(p => p.Name == null);