Verified Commit 9d1eb764 authored by Mathias B.'s avatar Mathias B.
Browse files

Suppression et mise à jour de rôles en base de données. Fixes #25

parent c1a92e8b
......@@ -174,9 +174,10 @@ impl EventHandler for Handler {
&self,
_ctx: Context,
_guild_id: GuildId,
_removed_role_id: RoleId,
removed_role_id: RoleId,
_removed_role_data_if_available: Option<Role>,
) {
process_handler_result(RoleRepository::delete_by_id(removed_role_id).await);
}
async fn guild_role_update(
......@@ -184,8 +185,9 @@ impl EventHandler for Handler {
_ctx: Context,
_guild_id: GuildId,
_old_data_if_available: Option<Role>,
_new: Role,
new: Role,
) {
process_handler_result(RoleRepository::update(&RoleData::from(&new)).await);
}
async fn guild_update(
......@@ -194,6 +196,7 @@ impl EventHandler for Handler {
_old_data_if_available: Option<Guild>,
_new_but_incomplete: PartialGuild,
) {
todo!()
}
async fn message(&self, ctx: Context, message: Message) {
......
INSERT INTO discord.roles(id, name, guilds_id, position, managed) VALUES ($1, $2, $3, $4, $5)
\ No newline at end of file
INSERT INTO discord.roles(id, name, guilds_id, position, managed) VALUES ($1, $2, $3, $4, $5)
ON CONFLICT DO NOTHING
\ No newline at end of file
UPDATE discord.roles SET
name = $2, position = $3, managed = $4
WHERE id = $1
\ No newline at end of file
......@@ -66,6 +66,29 @@ impl RoleRepository {
).await.map(|_| ())
}
pub async fn delete_by_id(role: RoleId) -> super::PostgreSQLResult<u64> {
let db = DatabaseClient::get();
db.execute(
include_str!("../files/sql/roles/delete.sql"),
&[i64::from(role)]
).await
}
pub async fn update(role: &RoleData) -> super::PostgreSQLResult<u64> {
let db = DatabaseClient::get();
db.execute(
include_str!("../files/sql/roles/update.sql"),
&[
&role.id,
&role.name,
&role.position,
&role.managed
]
).await
}
pub async fn copy_temporary_roles(
temp_table_id: u32,
roles: &[RoleData],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment