Save accepted ToS to PG
This commit is contained in:
@@ -3,6 +3,11 @@ package database.account;
|
||||
import database.PgDatabaseConnection;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Ponk
|
||||
*/
|
||||
public class AccountRepository {
|
||||
private final PgDatabaseConnection connection;
|
||||
|
||||
@@ -10,8 +15,17 @@ public class AccountRepository {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public Account getByName(String name) {
|
||||
return null; // TODO
|
||||
public Optional<Account> findById(int accountId) {
|
||||
String sql = """
|
||||
SELECT id, name, password, pin, pic, logged_in, last_login, birthdate, banned, gender, tos_accepted
|
||||
FROM account
|
||||
WHERE id = :id""";
|
||||
try (Handle handle = connection.getHandle()) {
|
||||
return handle.createQuery(sql)
|
||||
.bind("id", accountId)
|
||||
.mapTo(Account.class)
|
||||
.findOne();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer insert(Account account) {
|
||||
@@ -28,4 +42,17 @@ public class AccountRepository {
|
||||
.one();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTos(int accountId, boolean acceptedTos) {
|
||||
String sql = """
|
||||
UPDATE account
|
||||
SET tos_accepted = :acceptedTos
|
||||
WHERE id = :id""";
|
||||
try (Handle handle = connection.getHandle()) {
|
||||
handle.createUpdate(sql)
|
||||
.bind("id", accountId)
|
||||
.bind("acceptedTos", acceptedTos)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user