Add Minecraft appeal functionality with database integration, UUID handling, and API response adjustments.
This commit is contained in:
@@ -5,12 +5,13 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PrivilegedUser {
|
||||
private int id;
|
||||
private String uuid;
|
||||
private UUID uuid;
|
||||
private List<String> permissions;
|
||||
}
|
||||
|
||||
+9
-1
@@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface PrivilegedUserMapper {
|
||||
|
||||
@@ -24,7 +25,7 @@ public interface PrivilegedUserMapper {
|
||||
@Result(property = "permissions", column = "id", javaType = List.class,
|
||||
many = @Many(select = "getPermissionsForUser"))
|
||||
})
|
||||
Optional<PrivilegedUser> getUserByUuid(@Param("uuid") String uuid);
|
||||
Optional<PrivilegedUser> getUserByUuid(@Param("uuid") UUID uuid);
|
||||
|
||||
/**
|
||||
* Retrieves all privileged users with their permissions
|
||||
@@ -100,4 +101,11 @@ public interface PrivilegedUserMapper {
|
||||
WHERE user_id = #{userId} AND privileges = #{permission}
|
||||
""")
|
||||
int removePermissionFromUser(@Param("userId") int userId, @Param("permission") String permission);
|
||||
|
||||
@Insert("""
|
||||
INSERT INTO privileged_users (uuid)
|
||||
VALUES (#{uuid})
|
||||
""")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
|
||||
int createPrivilegedUser(UUID uuid);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.alttd.altitudeweb.database.web_db.forms;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record Appeal(
|
||||
UUID id,
|
||||
UUID uuid,
|
||||
String username,
|
||||
String reason,
|
||||
Instant createdAt,
|
||||
Instant sendAt,
|
||||
String email,
|
||||
Long assignedTo
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.alttd.altitudeweb.database.web_db.forms;
|
||||
|
||||
import com.alttd.altitudeweb.model.MinecraftAppealDto;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AppealMapper {
|
||||
|
||||
@Insert("""
|
||||
INSERT INTO appeals (uuid, username, reason, created_at, send_at, e_mail, assigned_to)
|
||||
VALUES (#{uuid}, #{username}, #{reason}, #{createdAt}, #{sendAt}, #{email}, #{assignedTo})
|
||||
""")
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
Appeal createAppeal(Appeal appeal);
|
||||
|
||||
@Update("""
|
||||
UPDATE appeals
|
||||
SET reason = #{reason},
|
||||
created_at = #{createdAt},
|
||||
send_at = #{sendAt},
|
||||
e_mail = #{email},
|
||||
assigned_to = #{assignedTo}
|
||||
WHERE id = #{id}
|
||||
""")
|
||||
void updateAppeal(Appeal appeal);
|
||||
|
||||
@Select("""
|
||||
SELECT id, uuid, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
|
||||
FROM appeals
|
||||
WHERE id = #{id}
|
||||
""")
|
||||
Appeal getAppealById(int id);
|
||||
|
||||
@Select("""
|
||||
SELECT id, uuid, reason, created_at AS createdAt, send_at AS sendAt, e_mail AS email, assigned_to AS assignedTo
|
||||
FROM appeals
|
||||
WHERE uuid = #{uuid}
|
||||
""")
|
||||
List<Appeal> getAppealsByUuid(String uuid);
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.web_db.KeyPairMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.PrivilegedUserMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.SettingsMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.AppealMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -20,12 +21,14 @@ public class InitializeWebDb {
|
||||
configuration.addMapper(SettingsMapper.class);
|
||||
configuration.addMapper(KeyPairMapper.class);
|
||||
configuration.addMapper(PrivilegedUserMapper.class);
|
||||
configuration.addMapper(AppealMapper.class);
|
||||
}).join()
|
||||
.runQuery(SqlSession -> {
|
||||
createSettingsTable(SqlSession);
|
||||
createKeyTable(SqlSession);
|
||||
createPrivilegedUsersTable(SqlSession);
|
||||
createPrivilegesTable(SqlSession);
|
||||
.runQuery(sqlSession -> {
|
||||
createSettingsTable(sqlSession);
|
||||
createKeyTable(sqlSession);
|
||||
createPrivilegedUsersTable(sqlSession);
|
||||
createPrivilegesTable(sqlSession);
|
||||
createAppealTable(sqlSession);
|
||||
});
|
||||
log.debug("Initialized WebDb");
|
||||
}
|
||||
@@ -70,7 +73,7 @@ public class InitializeWebDb {
|
||||
String query = """
|
||||
CREATE TABLE IF NOT EXISTS privileged_users (
|
||||
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
uuid VARCHAR(36) NOT NULL
|
||||
uuid UUID UNIQUE NOT NULL
|
||||
);
|
||||
""";
|
||||
try (Statement statement = sqlSession.getConnection().createStatement()) {
|
||||
@@ -99,4 +102,25 @@ public class InitializeWebDb {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAppealTable(@NotNull SqlSession sqlSession) {
|
||||
String query = """
|
||||
CREATE TABLE IF NOT EXISTS appeals (
|
||||
id UUID NOT NULL DEFAULT (UUID()) PRIMARY KEY,
|
||||
uuid UUID NOT NULL,
|
||||
username VARCHAR(16) 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user