Track chat session lifecycles: added session start/end times, database schema, and persistence logic.
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
package com.alttd.altitudeweb.database.web_db.chat_session;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ChatSession {
|
||||
|
||||
private final UUID uuid;
|
||||
private final Instant session_start;
|
||||
private final Instant session_end;
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.alttd.altitudeweb.database.web_db.chat_session;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
|
||||
public interface ChatSessionMapper {
|
||||
|
||||
@Insert("""
|
||||
INSERT INTO chat_session (uuid, session_start, session_end)
|
||||
VALUES (#{uuid}, #{session_start}, #{session_end})
|
||||
""")
|
||||
void storeSession(ChatSession chatSession);
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.alttd.altitudeweb.database.Databases;
|
||||
import com.alttd.altitudeweb.database.web_db.KeyPairMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.PrivilegedUserMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.SettingsMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.chat_session.ChatSessionMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.AppealMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.DiscordAppealMapper;
|
||||
import com.alttd.altitudeweb.database.web_db.forms.StaffApplicationMapper;
|
||||
@@ -28,6 +29,7 @@ public class InitializeWebDb {
|
||||
configuration.addMapper(DiscordAppealMapper.class);
|
||||
configuration.addMapper(StaffApplicationMapper.class);
|
||||
configuration.addMapper(EmailVerificationMapper.class);
|
||||
configuration.addMapper(ChatSessionMapper.class);
|
||||
}).join()
|
||||
.runQuery(sqlSession -> {
|
||||
createSettingsTable(sqlSession);
|
||||
@@ -38,6 +40,7 @@ public class InitializeWebDb {
|
||||
createdDiscordAppealTable(sqlSession);
|
||||
createStaffApplicationsTable(sqlSession);
|
||||
createUserEmailsTable(sqlSession);
|
||||
createChatSessionTable(sqlSession);
|
||||
});
|
||||
log.debug("Initialized WebDb");
|
||||
}
|
||||
@@ -208,4 +211,21 @@ public class InitializeWebDb {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createChatSessionTable(@NotNull SqlSession sqlSession) {
|
||||
String query = """
|
||||
CREATE TABLE IF NOT EXISTS chat_session (
|
||||
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
uuid UUID NOT NULL,
|
||||
session_start TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
session_end TIMESTAMP NULL,
|
||||
FOREIGN KEY (uuid) REFERENCES privileged_users(uuid) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
""";
|
||||
try (Statement statement = sqlSession.getConnection().createStatement()) {
|
||||
statement.execute(query);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user