feat(dashboard): add key roles
This commit is contained in:
parent
b52df95b65
commit
65d286389d
4 changed files with 170 additions and 4 deletions
|
|
@ -13,6 +13,8 @@
|
|||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Net;
|
||||
using Catalogger.Backend.Api.Middleware;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Remora.Discord.API;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
|
|
@ -104,4 +106,41 @@ public partial class GuildsController
|
|||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPut("key-roles/{roleId}")]
|
||||
public async Task<IActionResult> AddKeyRoleAsync(string id, ulong roleId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (roleCache.GuildRoles(guildId).All(r => r.ID.Value != roleId))
|
||||
throw new ApiError(HttpStatusCode.BadRequest, ErrorCode.BadRequest, "Role not found");
|
||||
|
||||
if (guildConfig.KeyRoles.Contains(roleId))
|
||||
throw new ApiError(
|
||||
HttpStatusCode.BadRequest,
|
||||
ErrorCode.BadRequest,
|
||||
"Role is already a key role"
|
||||
);
|
||||
|
||||
await guildRepository.AddKeyRoleAsync(guildId, DiscordSnowflake.New(roleId));
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("key-roles/{roleId}")]
|
||||
public async Task<IActionResult> RemoveKeyRoleAsync(string id, ulong roleId)
|
||||
{
|
||||
var (guildId, _) = await ParseGuildAsync(id);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (!guildConfig.KeyRoles.Contains(roleId))
|
||||
throw new ApiError(
|
||||
HttpStatusCode.BadRequest,
|
||||
ErrorCode.BadRequest,
|
||||
"Role is already not a key role"
|
||||
);
|
||||
|
||||
await guildRepository.RemoveKeyRoleAsync(guildId, DiscordSnowflake.New(roleId));
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue