Skip to content

Commit 071c1dc

Browse files
committed
feat: update command usage analytics to use generated record methods
1 parent 5002f75 commit 071c1dc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

application/src/main/java/org/togetherjava/tjbot/features/analytics/AnalyticsService.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.togetherjava.tjbot.features.analytics;
22

33
import org.jetbrains.annotations.Nullable;
4-
import org.jooq.impl.DSL;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76

87
import org.togetherjava.tjbot.db.Database;
8+
import org.togetherjava.tjbot.db.generated.tables.CommandUsage;
9+
10+
import java.time.Instant;
911

1012
/**
1113
* Service for tracking and recording command usage analytics.
@@ -45,12 +47,14 @@ public AnalyticsService(Database database) {
4547
public void recordCommandExecution(long channelId, String commandName, long userId,
4648
boolean success, @Nullable String errorMessage) {
4749

48-
database.write(context -> context
49-
.insertInto(DSL.table("command_usage"), DSL.field("channel_id"),
50-
DSL.field("command_name"), DSL.field("user_id"), DSL.field("executed_at"),
51-
DSL.field("success"), DSL.field("error_message"))
52-
.values(channelId, commandName, userId, DSL.currentTimestamp(), success, errorMessage)
53-
.execute());
50+
database.write(context -> context.newRecord(CommandUsage.COMMAND_USAGE)
51+
.setChannelId(channelId)
52+
.setCommandName(commandName)
53+
.setUserId(userId)
54+
.setExecutedAt(Instant.now())
55+
.setSuccess(success)
56+
.setErrorMessage(errorMessage)
57+
.insert());
5458

5559
if (!success && errorMessage != null) {
5660
logger.warn("Command '{}' failed on channel {} with error: {}", commandName, channelId,

application/src/main/resources/db/V16__Add_Analytics_System.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
CREATE TABLE command_usage
22
(
33
id INTEGER PRIMARY KEY AUTOINCREMENT,
4-
channel_id INTEGER NOT NULL,
4+
channel_id BIGINT NOT NULL,
55
command_name TEXT NOT NULL,
6-
user_id INTEGER NOT NULL,
6+
user_id BIGINT NOT NULL,
77
executed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
88
success BOOLEAN NOT NULL DEFAULT TRUE,
99
error_message TEXT

0 commit comments

Comments
 (0)