feat(apiv2): delete endpoints

This commit is contained in:
spiral 2021-10-12 06:41:38 -04:00
parent c164fad2ac
commit 0aefafb62d
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
4 changed files with 41 additions and 22 deletions

View File

@ -66,15 +66,20 @@ namespace PluralKit.API
}; };
} }
[HttpDelete("groups/{group_id}")] [HttpDelete("groups/{groupRef}")]
public async Task<IActionResult> GroupDelete(string group_id) public async Task<IActionResult> GroupDelete(string groupRef)
{ {
return new ObjectResult("Unimplemented") var group = await ResolveGroup(groupRef);
{ if (group == null)
StatusCode = 501 throw APIErrors.GroupNotFound;
};
var system = await ResolveSystem("@me");
if (system.Id != group.System)
throw APIErrors.NotOwnGroupError;
await _repo.DeleteGroup(group.Id);
return NoContent();
} }
} }
} }

View File

@ -67,15 +67,20 @@ namespace PluralKit.API
}; };
} }
[HttpDelete("members/{member}")] [HttpDelete("members/{memberRef}")]
public async Task<IActionResult> MemberDelete(string member) public async Task<IActionResult> MemberDelete(string memberRef)
{ {
return new ObjectResult("Unimplemented") var member = await ResolveMember(memberRef);
{ if (member == null)
StatusCode = 501 throw APIErrors.MemberNotFound;
};
var system = await ResolveSystem("@me");
if (system.Id != member.System)
throw APIErrors.NotOwnMemberError;
await _repo.DeleteMember(member.Id);
return NoContent();
} }
} }
} }

View File

@ -131,13 +131,20 @@ namespace PluralKit.API
}; };
} }
[HttpDelete("systems/{system}/switches/{switch_id}")] [HttpDelete("systems/@me/switches/{switchRef}")]
public async Task<IActionResult> SwitchDelete(string system, string switch_id) public async Task<IActionResult> SwitchDelete(string switchRef)
{ {
return new ObjectResult("Unimplemented") if (!Guid.TryParse(switchRef, out var switchId))
{ throw APIErrors.SwitchNotFound;
StatusCode = 501
}; 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();
} }
} }

View File

@ -52,6 +52,8 @@ namespace PluralKit.API
public static PKError UnauthorizedGroupMemberList = new(403, 30003, "Unauthorized to view group member list"); 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 UnauthorizedCurrentFronters = new(403, 30004, "Unauthorized to view current fronters.");
public static PKError UnauthorizedFrontHistory = new(403, 30004, "Unauthorized to view front history."); 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"); public static PKError Unimplemented = new(501, 50001, "Unimplemented");
} }
} }