Set ban through AccountService

This commit is contained in:
P0nk
2024-09-29 19:26:15 +02:00
parent f142e21bbb
commit 99006c2dda
5 changed files with 87 additions and 50 deletions

View File

@@ -45,6 +45,20 @@ public class AccountRepository {
}
}
public Optional<Account> findIdByChrNameIgnoreCase(String name) {
String sql = """
SELECT id
FROM account AS a
INNER JOIN chr AS c ON a.id = c.account
WHERE lower(c.name) = lower(:name)""";
try (Handle handle = connection.getHandle()) {
return handle.createQuery(sql)
.bind("name", name)
.mapTo(Account.class)
.findOne();
}
}
public Integer insert(Account account) {
String sql = """
INSERT INTO account (name, password, birthdate, chr_slots, login_state)
@@ -140,4 +154,19 @@ public class AccountRepository {
.execute() > 0;
}
}
public boolean setBanned(int accountId, Instant bannedUntil, byte banReason, String description) {
String sql = """
UPDATE account
SET banned = true, banned_until = :bannedUntil, ban_reason = :banReason, description = :description
WHERE id = :id""";
try (Handle handle = connection.getHandle()) {
return handle.createUpdate(sql)
.bind("id", accountId)
.bind("bannedUntil", bannedUntil)
.bind("banReason", banReason)
.bind("description", description)
.execute() > 0;
}
}
}