diff --git a/PluralKit.API/Controllers/v2/GroupControllerV2.cs b/PluralKit.API/Controllers/v2/GroupControllerV2.cs index 4a1f32ca..d29a31f9 100644 --- a/PluralKit.API/Controllers/v2/GroupControllerV2.cs +++ b/PluralKit.API/Controllers/v2/GroupControllerV2.cs @@ -66,15 +66,20 @@ namespace PluralKit.API }; } - [HttpDelete("groups/{group_id}")] - public async Task GroupDelete(string group_id) + [HttpDelete("groups/{groupRef}")] + public async Task GroupDelete(string groupRef) { - return new ObjectResult("Unimplemented") - { - StatusCode = 501 - }; + var group = await ResolveGroup(groupRef); + if (group == null) + throw APIErrors.GroupNotFound; + + var system = await ResolveSystem("@me"); + if (system.Id != group.System) + throw APIErrors.NotOwnGroupError; + + await _repo.DeleteGroup(group.Id); + + return NoContent(); } - - } } \ No newline at end of file diff --git a/PluralKit.API/Controllers/v2/MemberControllerV2.cs b/PluralKit.API/Controllers/v2/MemberControllerV2.cs index 5b97ce78..38b958d4 100644 --- a/PluralKit.API/Controllers/v2/MemberControllerV2.cs +++ b/PluralKit.API/Controllers/v2/MemberControllerV2.cs @@ -67,15 +67,20 @@ namespace PluralKit.API }; } - [HttpDelete("members/{member}")] - public async Task MemberDelete(string member) + [HttpDelete("members/{memberRef}")] + public async Task MemberDelete(string memberRef) { - return new ObjectResult("Unimplemented") - { - StatusCode = 501 - }; + var member = await ResolveMember(memberRef); + if (member == null) + throw APIErrors.MemberNotFound; + + var system = await ResolveSystem("@me"); + if (system.Id != member.System) + throw APIErrors.NotOwnMemberError; + + await _repo.DeleteMember(member.Id); + + return NoContent(); } - - } } \ No newline at end of file diff --git a/PluralKit.API/Controllers/v2/SwitchControllerV2.cs b/PluralKit.API/Controllers/v2/SwitchControllerV2.cs index 56660a0f..f7c2f88c 100644 --- a/PluralKit.API/Controllers/v2/SwitchControllerV2.cs +++ b/PluralKit.API/Controllers/v2/SwitchControllerV2.cs @@ -131,13 +131,20 @@ namespace PluralKit.API }; } - [HttpDelete("systems/{system}/switches/{switch_id}")] - public async Task SwitchDelete(string system, string switch_id) + [HttpDelete("systems/@me/switches/{switchRef}")] + public async Task SwitchDelete(string switchRef) { - return new ObjectResult("Unimplemented") - { - StatusCode = 501 - }; + if (!Guid.TryParse(switchRef, out var switchId)) + throw APIErrors.SwitchNotFound; + + var system = await ResolveSystem("@me"); + var sw = await _repo.GetSwitchByUuid(switchId); + if (sw == null || system.Id != sw.System) + throw APIErrors.SwitchNotFound; + + await _repo.DeleteSwitch(sw.Id); + + return NoContent(); } } diff --git a/PluralKit.API/Errors.cs b/PluralKit.API/Errors.cs index 600c63de..43fee534 100644 --- a/PluralKit.API/Errors.cs +++ b/PluralKit.API/Errors.cs @@ -52,6 +52,8 @@ namespace PluralKit.API public static PKError UnauthorizedGroupMemberList = new(403, 30003, "Unauthorized to view group member list"); public static PKError UnauthorizedCurrentFronters = new(403, 30004, "Unauthorized to view current fronters."); public static PKError UnauthorizedFrontHistory = new(403, 30004, "Unauthorized to view front history."); + public static PKError NotOwnMemberError = new(403, 40001, "Target member is not part of your system."); + public static PKError NotOwnGroupError = new(403, 40002, "Target group is not part of your system."); public static PKError Unimplemented = new(501, 50001, "Unimplemented"); } } \ No newline at end of file