Save accepted ToS to PG

This commit is contained in:
P0nk
2024-09-26 21:13:40 +02:00
parent c7f835da0d
commit 0f2ef341ce
8 changed files with 136 additions and 49 deletions

View File

@@ -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();
}
}
}