-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api v2 #30
base: main
Are you sure you want to change the base?
api v2 #30
Conversation
WalkthroughThis pull request updates components that interact with the Kiai API. In the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant K as Kiai API Handler
participant A as Kiai API
C->>K: Invoke getUser(guildId, userId)
K->>A: Send HTTP request (endpoint without "/guild/" prefix)
A-->>K: Return JSON response with user data
K->>K: Parse JSON using Gson into User object
K-->>C: Return CompletableFuture<User>
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (4)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (3)
src/main/java/com/buape/kiaimc/api/User.java (1)
3-14
: Add constructor and field validations.Consider the following improvements:
- Add a constructor to initialize fields.
- Add
@Nullable
annotation for potentially nullable fields likerankCardBackground
.- Add validation for numeric fields to ensure they are non-negative.
+import javax.annotation.Nullable; + public class User { private String id; private String guildId; private int currentLevel; private int nextLevel; private int nextLevelXp; private int xp; private int messagesSent; private int voiceMinutes; + @Nullable private String rankCardBackground; private int currentXpStreak; private boolean streakDoneToday; + + public User(String id, String guildId, int currentLevel, int nextLevel, + int nextLevelXp, int xp, int messagesSent, int voiceMinutes, + @Nullable String rankCardBackground, int currentXpStreak, + boolean streakDoneToday) { + this.id = id; + this.guildId = guildId; + this.currentLevel = validateNonNegative(currentLevel, "currentLevel"); + this.nextLevel = validateNonNegative(nextLevel, "nextLevel"); + this.nextLevelXp = validateNonNegative(nextLevelXp, "nextLevelXp"); + this.xp = validateNonNegative(xp, "xp"); + this.messagesSent = validateNonNegative(messagesSent, "messagesSent"); + this.voiceMinutes = validateNonNegative(voiceMinutes, "voiceMinutes"); + this.rankCardBackground = rankCardBackground; + this.currentXpStreak = validateNonNegative(currentXpStreak, "currentXpStreak"); + this.streakDoneToday = streakDoneToday; + } + + private static int validateNonNegative(int value, String fieldName) { + if (value < 0) { + throw new IllegalArgumentException(fieldName + " cannot be negative"); + } + return value; + }src/main/java/com/buape/kiaimc/api/Kiai.java (1)
12-12
: Configure Gson for robust JSON handling.Consider configuring Gson with custom type adapters and null handling:
- private static final Gson gson = new Gson(); + private static final Gson gson = new GsonBuilder() + .serializeNulls() + .setDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") + .create();src/main/java/com/buape/kiaimc/KiaiMC.java (1)
47-47
: Add base URL validation and version change logging.Consider adding URL validation and logging the API version change:
- baseUrl = "https://api.kiai.app/v2"; + baseUrl = validateBaseUrl("https://api.kiai.app/v2"); + logger.info("Using Kiai API v2"); + private String validateBaseUrl(String url) { + if (!url.matches("^https?://[^\\s/$.?#].[^\\s]*$")) { + throw new IllegalArgumentException("Invalid base URL format"); + } + return url; + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/buape/kiaimc/KiaiMC.java
(1 hunks)src/main/java/com/buape/kiaimc/api/Kiai.java
(3 hunks)src/main/java/com/buape/kiaimc/api/User.java
(1 hunks)
🔇 Additional comments (1)
src/main/java/com/buape/kiaimc/api/User.java (1)
16-58
: LGTM!The getter methods are well-implemented, following Java naming conventions and providing clean access to the private fields.
…paper:paper-api' to 1.21.4-R0.1-SNAPSHOT & update paper-api dependency url
Summary by CodeRabbit