Browse Source

jdbc migrate hot fix and clear

master
gsd 1 year ago
parent
commit
90a039e347
  1. 46
      src/main/java/app/services/db/BanService.java
  2. 10
      src/main/java/app/services/db/DiscordAuthService.java

46
src/main/java/app/services/db/BanService.java

@ -35,12 +35,8 @@ public class BanService {
public Ban getBan(SteamID steamID) {
return jdbcTemplate.query("SELECT * FROM light_bans WHERE account_id = ? AND active = 1",
new Object[]{ steamID.account_id },
new RowMapper<Ban>() {
@Override
public Ban mapRow(ResultSet resultSet, int num) throws SQLException {
return new Ban(resultSet);
}
}).stream()
(rs, n) -> new Ban(rs))
.stream()
.peek(ban -> ban.cryptIP(cryptedCookie))
.peek(ban -> ban.fillAdmins(permitionService))
.findFirst()
@ -50,12 +46,8 @@ public class BanService {
public Ban getBan(int ban_id) {
return jdbcTemplate.query("SELECT * FROM light_bans WHERE id = ?",
new Object[]{ ban_id },
new RowMapper<Ban>() {
@Override
public Ban mapRow(ResultSet resultSet, int num) throws SQLException {
return new Ban(resultSet);
}
}).stream()
(rs, n) -> new Ban(rs))
.stream()
.peek(ban -> ban.cryptIP(cryptedCookie))
.peek(ban -> ban.fillAdmins(permitionService))
.findFirst()
@ -65,12 +57,8 @@ public class BanService {
public List<Ban> getBans(SteamID steamID) {
return jdbcTemplate.query("SELECT * FROM light_bans WHERE account_id = ? AND active = 0",
new Object[]{steamID.account_id},
new RowMapper<Ban>() {
@Override
public Ban mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Ban(rs);
}
}).stream()
(rs, n) -> new Ban(rs))
.stream()
.peek(ban -> ban.cryptIP(cryptedCookie))
.peek(ban -> ban.fillAdmins(permitionService))
.toList();
@ -79,12 +67,8 @@ public class BanService {
public List<Ban> getLastBans(Integer limit, Integer offset) {
return jdbcTemplate.query("SELECT * FROM `light_bans` WHERE `active` = ? ORDER BY `light_bans`.`id` DESC LIMIT ? OFFSET ?",
new Object[]{1, limit, offset},
new RowMapper<Ban>() {
@Override
public Ban mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Ban(rs);
}
}).stream()
(rs, n) -> new Ban(rs))
.stream()
.peek(ban -> ban.cryptIP(cryptedCookie))
.peek(ban -> ban.fillAdmins(permitionService))
.toList();
@ -92,12 +76,7 @@ public class BanService {
public Long getBansCount() {
return jdbcTemplate.query("SELECT COUNT(*) as c FROM `light_bans` WHERE active = 1",
new RowMapper<Long>() {
@Override
public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong("c");
}
}).stream().findFirst().orElse(0L);
(rs, n) -> rs.getLong("c")).stream().findFirst().orElse(0L);
}
public boolean removeBan(PlayerProfile user, PlayerProfile admin) {
@ -122,12 +101,7 @@ public class BanService {
public List<Long> getUsersDiscordWithBanOnServers() {
return jdbcTemplate.query("SELECT `discord_id` FROM `light_bans` INNER JOIN `steam2discord` ON `light_bans`.`active` = ? AND `light_bans`.`steam_id` COLLATE utf8mb4_unicode_ci LIKE `steam2discord`.`steam_id`",
new Object[]{1},
new RowMapper<Long>() {
@Override
public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong("discord_id");
}
});
(rs, n) -> rs.getLong("discord_id"));
}
public String deCrypt(String crypted) {

10
src/main/java/app/services/db/DiscordAuthService.java

@ -25,12 +25,8 @@ public class DiscordAuthService {
public SteamID getSteamIDofDiscordID(String discord_id) {
return jdbcTemplate.query("SELECT steam_id FROM steam2discord WHERE discord_id = ? AND active = 1 LIMIT 1",
new Object[]{ discord_id },
new RowMapper<SteamID>() {
@Override
public SteamID mapRow(ResultSet rs, int numRow) throws SQLException {
return SteamIDConverter.getSteamID(rs.getString("steam_id"));
}
}).stream().findFirst().orElse(null);
(rs, n) -> SteamIDConverter.getSteamID(rs.getString("steam_id")))
.stream().findFirst().orElse(null);
}
public String getDiscordIDofSteamID(SteamID steamID) {
@ -57,7 +53,7 @@ public class DiscordAuthService {
public List<String> getAccountsNotInList(List<String> discord_accounts) {
String inSql = String.join(",", Collections.nCopies(discord_accounts.size(), "?"));
return jdbcTemplate.query("SELECT `discord_id` FROM `steam2discord` WHERE `active` = 1 AND `discord_id` in (" + inSql + ")",
new Object[]{ discord_accounts.toArray() },
discord_accounts.toArray(),
new RowMapper<String>() {
@Override
public String mapRow(ResultSet rs, int rowNum) throws SQLException {

Loading…
Cancel
Save