Mark appeals as sent when successfully submitted and processed, ensuring accurate tracking and status updates.

This commit is contained in:
akastijn 2025-08-24 02:39:47 +02:00
parent fe545972e3
commit c75f0cdb15
3 changed files with 41 additions and 6 deletions

View File

@ -48,6 +48,7 @@ public class AppealController implements AppealsApi {
@RateLimit(limit = 3, timeValue = 1, timeUnit = TimeUnit.HOURS, key = "minecraftAppeal") @RateLimit(limit = 3, timeValue = 1, timeUnit = TimeUnit.HOURS, key = "minecraftAppeal")
@Override @Override
public ResponseEntity<AppealResponseDto> submitMinecraftAppeal(MinecraftAppealDto minecraftAppealDto) { public ResponseEntity<AppealResponseDto> submitMinecraftAppeal(MinecraftAppealDto minecraftAppealDto) {
boolean success = true;
CompletableFuture<Appeal> appealCompletableFuture = new CompletableFuture<>(); CompletableFuture<Appeal> appealCompletableFuture = new CompletableFuture<>();
Connection.getConnection(Databases.DEFAULT) Connection.getConnection(Databases.DEFAULT)
@ -72,6 +73,7 @@ public class AppealController implements AppealsApi {
appealDiscord.sendAppealToDiscord(appeal, history); appealDiscord.sendAppealToDiscord(appeal, history);
} catch (Exception e) { } catch (Exception e) {
log.error("Failed to send appeal {} to Discord", appeal.id(), e); log.error("Failed to send appeal {} to Discord", appeal.id(), e);
success = false;
} }
appealMail.sendAppealNotification(appeal, history); appealMail.sendAppealNotification(appeal, history);
@ -94,6 +96,15 @@ public class AppealController implements AppealsApi {
if (!emailVerification.verified()) { if (!emailVerification.verified()) {
return ResponseEntity.badRequest().build(); return ResponseEntity.badRequest().build();
} }
if (!success) {
return ResponseEntity.internalServerError().build();
}
Connection.getConnection(Databases.DEFAULT)
.runQuery(sqlSession -> {
log.debug("Marking appeal {} as sent", appeal.id());
sqlSession.getMapper(AppealMapper.class)
.markAppealAsSent(appeal.id());
});
AppealResponseDto appealResponseDto = new AppealResponseDto( AppealResponseDto appealResponseDto = new AppealResponseDto(
appeal.id().toString(), appeal.id().toString(),
"Your appeal has been submitted. You will be notified when it has been reviewed.", "Your appeal has been submitted. You will be notified when it has been reviewed.",

View File

@ -2,8 +2,10 @@ package com.alttd.altitudeweb.database.web_db.forms;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List; import java.util.List;
import java.util.UUID;
public interface AppealMapper { public interface AppealMapper {
@ -26,4 +28,10 @@ public interface AppealMapper {
WHERE uuid = #{uuid} WHERE uuid = #{uuid}
""") """)
List<Appeal> getAppealsByUuid(String uuid); List<Appeal> getAppealsByUuid(String uuid);
@Update("""
UPDATE appeals SET send_at = NOW()
WHERE id = #{id}
""")
void markAppealAsSent(UUID id);
} }

View File

@ -12,6 +12,7 @@ import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
@ -119,18 +120,33 @@ public class Connection {
} }
private SqlSessionFactory createSqlSessionFactory(DatabaseSettings settings, AddMappers addMappers) { private SqlSessionFactory createSqlSessionFactory(DatabaseSettings settings, AddMappers addMappers) {
try {
Configuration configuration = getConfiguration(settings);
configuration.getTypeHandlerRegistry().register(UUID.class, UUIDTypeHandler.class);
addMappers.apply(configuration);
return new SqlSessionFactoryBuilder().build(configuration);
} catch (Exception e) {
log.error("""
Failed to create sql session factory with
\thost {}
\tport: {}
\tname: {}
\tusername: {}
""", settings.host(), settings.port(), settings.name(), settings.username(), e);
throw e;
}
}
private static @NotNull Configuration getConfiguration(DatabaseSettings settings) {
PooledDataSource dataSource = new PooledDataSource(); PooledDataSource dataSource = new PooledDataSource();
dataSource.setDriver("com.mysql.cj.jdbc.Driver"); dataSource.setDriver("com.mysql.cj.jdbc.Driver");
dataSource.setUrl(String.format("jdbc:mysql://%s:%d/%s", settings.host(), dataSource.setUrl(String.format("jdbc:mysql://%s:%d/%s", settings.host(),
settings.port(), settings.name())); settings.port(), settings.name()));
dataSource.setUsername(settings.username()); dataSource.setUsername(settings.username());
dataSource.setPassword(settings.password()); dataSource.setPassword(settings.password());
Environment environment = new Environment("production", new JdbcTransactionFactory(), dataSource); Environment environment = new Environment("production", new JdbcTransactionFactory(), dataSource);
Configuration configuration = new Configuration(environment); return new Configuration(environment);
configuration.getTypeHandlerRegistry().register(UUID.class, UUIDTypeHandler.class);
addMappers.apply(configuration);
return new SqlSessionFactoryBuilder().build(configuration);
} }
} }