|
1 | 1 | package org.togetherjava.tjbot.features.analytics; |
2 | 2 |
|
3 | 3 | import org.jetbrains.annotations.Nullable; |
4 | | -import org.jooq.impl.DSL; |
5 | 4 | import org.slf4j.Logger; |
6 | 5 | import org.slf4j.LoggerFactory; |
7 | 6 |
|
8 | 7 | import org.togetherjava.tjbot.db.Database; |
| 8 | +import org.togetherjava.tjbot.db.generated.tables.CommandUsage; |
| 9 | + |
| 10 | +import java.time.Instant; |
9 | 11 |
|
10 | 12 | /** |
11 | 13 | * Service for tracking and recording command usage analytics. |
@@ -45,12 +47,14 @@ public AnalyticsService(Database database) { |
45 | 47 | public void recordCommandExecution(long channelId, String commandName, long userId, |
46 | 48 | boolean success, @Nullable String errorMessage) { |
47 | 49 |
|
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()); |
54 | 58 |
|
55 | 59 | if (!success && errorMessage != null) { |
56 | 60 | logger.warn("Command '{}' failed on channel {} with error: {}", commandName, channelId, |
|
0 commit comments