Implement Discord appeal functionality, including database schema, API endpoints, front-end form, and Discord message handling.

This commit is contained in:
2025-11-22 22:26:40 +01:00
parent 20ec3648c4
commit 7d59885395
30 changed files with 1143 additions and 38 deletions
@@ -0,0 +1,17 @@
package com.alttd.altitudeweb.database.web_db.forms;
import java.time.Instant;
import java.util.UUID;
public record DiscordAppeal(
UUID id,
UUID uuid,
Long discordId,
String username,
String reason,
Instant createdAt,
Instant sendAt,
String email,
Long assignedTo
) {
}
@@ -0,0 +1,29 @@
package com.alttd.altitudeweb.database.web_db.forms;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.util.UUID;
public interface DiscordAppealMapper {
@Insert("""
INSERT INTO discord_appeals (uuid, discord_id, discord_username, reason, created_at, send_at, e_mail, assigned_to)
VALUES (#{uuid}, #{discord_id}, #{discord_username}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
""")
void createDiscordAppeal(DiscordAppeal discordAppeal);
@Update("""
UPDATE discord_appeals SET send_at = NOW()
WHERE id = #{id}
""")
void markDiscordAppealAsSent(UUID id);
@Update("""
UPDATE discord_appeals SET assigned_to = #{assignedTo}
WHERE id = #{id}
""")
void assignDiscordAppeal(UUID id, Long assignedTo);
}
@@ -33,6 +33,7 @@ public class InitializeWebDb {
createPrivilegedUsersTable(sqlSession);
createPrivilegesTable(sqlSession);
createAppealTable(sqlSession);
createdDiscordAppealTable(sqlSession);
createStaffApplicationsTable(sqlSession);
createUserEmailsTable(sqlSession);
});
@@ -183,4 +184,26 @@ public class InitializeWebDb {
}
}
private static void createdDiscordAppealTable(@NotNull SqlSession sqlSession) {
String query = """
CREATE TABLE IF NOT EXISTS discord_appeals (
id UUID NOT NULL DEFAULT (UUID()) PRIMARY KEY,
uuid UUID NOT NULL,
discord_id BIGINT UNSIGNED NOT NULL,
discord_username VARCHAR(32) NOT NULL,
reason TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
send_at TIMESTAMP NULL,
e_mail TEXT NOT NULL,
assigned_to BIGINT UNSIGNED NULL,
FOREIGN KEY (uuid) REFERENCES privileged_users(uuid) ON DELETE CASCADE ON UPDATE CASCADE
);
""";
try (Statement statement = sqlSession.getConnection().createStatement()) {
statement.execute(query);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}