feat(apiv2): GET endpoints except guilds
- ResolveT methods in ControllerBase - ContextFor methods in ControllerBase
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -16,13 +17,23 @@ namespace PluralKit.API
|
||||
{
|
||||
public GroupControllerV2(IServiceProvider svc) : base(svc) { }
|
||||
|
||||
[HttpGet("systems/{system_id}/groups")]
|
||||
public async Task<IActionResult> GetSystemGroups(string system_id)
|
||||
[HttpGet("systems/{systemRef}/groups")]
|
||||
public async Task<IActionResult> GetSystemGroups(string systemRef)
|
||||
{
|
||||
return new ObjectResult("Unimplemented")
|
||||
{
|
||||
StatusCode = 501
|
||||
};
|
||||
var system = await ResolveSystem(systemRef);
|
||||
if (system == null)
|
||||
throw APIErrors.SystemNotFound;
|
||||
|
||||
var ctx = this.ContextFor(system);
|
||||
|
||||
if (!system.GroupListPrivacy.CanAccess(User.ContextFor(system)))
|
||||
throw APIErrors.UnauthorizedGroupList;
|
||||
|
||||
var groups = _repo.GetSystemGroups(system.Id);
|
||||
return Ok(await groups
|
||||
.Where(g => g.Visibility.CanAccess(ctx))
|
||||
.Select(g => g.ToJson(ctx))
|
||||
.ToListAsync());
|
||||
}
|
||||
|
||||
[HttpPost("groups")]
|
||||
@@ -34,13 +45,16 @@ namespace PluralKit.API
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet("groups/{group_id}")]
|
||||
public async Task<IActionResult> GroupGet(string group_id)
|
||||
[HttpGet("groups/{groupRef}")]
|
||||
public async Task<IActionResult> GroupGet(string groupRef)
|
||||
{
|
||||
return new ObjectResult("Unimplemented")
|
||||
{
|
||||
StatusCode = 501
|
||||
};
|
||||
var group = await ResolveGroup(groupRef);
|
||||
if (group == null)
|
||||
throw APIErrors.GroupNotFound;
|
||||
|
||||
var system = await _repo.GetSystem(group.System);
|
||||
|
||||
return Ok(group.ToJson(this.ContextFor(group), systemStr: system.Hid));
|
||||
}
|
||||
|
||||
[HttpPatch("groups/{group_id}")]
|
||||
|
||||
Reference in New Issue
Block a user