Mark appeals as sent when successfully submitted and processed, ensuring accurate tracking and status updates.
This commit is contained in:
parent
fe545972e3
commit
c75f0cdb15
|
|
@ -48,6 +48,7 @@ public class AppealController implements AppealsApi {
|
|||
@RateLimit(limit = 3, timeValue = 1, timeUnit = TimeUnit.HOURS, key = "minecraftAppeal")
|
||||
@Override
|
||||
public ResponseEntity<AppealResponseDto> submitMinecraftAppeal(MinecraftAppealDto minecraftAppealDto) {
|
||||
boolean success = true;
|
||||
CompletableFuture<Appeal> appealCompletableFuture = new CompletableFuture<>();
|
||||
|
||||
Connection.getConnection(Databases.DEFAULT)
|
||||
|
|
@ -72,6 +73,7 @@ public class AppealController implements AppealsApi {
|
|||
appealDiscord.sendAppealToDiscord(appeal, history);
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to send appeal {} to Discord", appeal.id(), e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
appealMail.sendAppealNotification(appeal, history);
|
||||
|
|
@ -94,6 +96,15 @@ public class AppealController implements AppealsApi {
|
|||
if (!emailVerification.verified()) {
|
||||
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(
|
||||
appeal.id().toString(),
|
||||
"Your appeal has been submitted. You will be notified when it has been reviewed.",
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package com.alttd.altitudeweb.database.web_db.forms;
|
|||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface AppealMapper {
|
||||
|
||||
|
|
@ -26,4 +28,10 @@ public interface AppealMapper {
|
|||
WHERE uuid = #{uuid}
|
||||
""")
|
||||
List<Appeal> getAppealsByUuid(String uuid);
|
||||
|
||||
@Update("""
|
||||
UPDATE appeals SET send_at = NOW()
|
||||
WHERE id = #{id}
|
||||
""")
|
||||
void markAppealAsSent(UUID id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import org.apache.ibatis.session.SqlSession;
|
|||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
||||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
|
@ -119,18 +120,33 @@ public class Connection {
|
|||
}
|
||||
|
||||
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();
|
||||
dataSource.setDriver("com.mysql.cj.jdbc.Driver");
|
||||
dataSource.setUrl(String.format("jdbc:mysql://%s:%d/%s", settings.host(),
|
||||
settings.port(), settings.name()));
|
||||
settings.port(), settings.name()));
|
||||
dataSource.setUsername(settings.username());
|
||||
dataSource.setPassword(settings.password());
|
||||
Environment environment = new Environment("production", new JdbcTransactionFactory(), dataSource);
|
||||
Configuration configuration = new Configuration(environment);
|
||||
configuration.getTypeHandlerRegistry().register(UUID.class, UUIDTypeHandler.class);
|
||||
addMappers.apply(configuration);
|
||||
|
||||
return new SqlSessionFactoryBuilder().build(configuration);
|
||||
return new Configuration(environment);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user