Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. 💤 Files selected but had no reviewable changes (1)
You can disable this status message by setting the WalkthroughAdds a login-gated, Scanner-driven CLI menu for moon-mission and account operations in Main.java; exposes Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as Main (CLI)
participant DB as Database
User->>CLI: Launch app
CLI->>DB: open Connection
CLI->>User: prompt username/password
User->>CLI: submit credentials
CLI->>DB: SELECT user WHERE username=... (auth)
DB-->>CLI: auth result
alt auth success
CLI->>User: show menu
loop user selects actions
User->>CLI: choose action
alt List missions
CLI->>DB: SELECT * FROM missions
DB-->>CLI: missions list
else Get mission by id
CLI->>DB: SELECT * FROM missions WHERE id=?
DB-->>CLI: mission row
else Count missions by year
CLI->>DB: SELECT COUNT(*) FROM missions WHERE year=?
DB-->>CLI: count
else Create account
CLI->>DB: INSERT INTO accounts (...)
DB-->>CLI: result
else Update account
CLI->>DB: UPDATE accounts SET ... WHERE id=?
DB-->>CLI: result
else Delete account
CLI->>DB: DELETE FROM accounts WHERE id=?
DB-->>CLI: result
end
CLI->>User: display results
end
else auth failure
CLI->>User: show error and exit
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pom.xml (1)
14-14: Correct JUnit Jupiter version to a valid release.The version
6.0.1does not exist. The latest stable release is JUnit Jupiter 5.13.4 (released July 21, 2025). Only preview milestones (e.g., 6.0.0-M2) exist for the 6.x line. Updatejunit.jupiter.versionto5.13.4or another valid stable release version to avoid dependency resolution failures.
🧹 Nitpick comments (4)
src/main/java/com/example/Main.java (3)
76-90: Security: Plaintext password storage and comparison.Passwords are stored and compared in plaintext. For a production application, passwords should be hashed (e.g., bcrypt, Argon2). Given this appears to be a classroom assignment with tests expecting specific credentials, this may be acceptable for now, but note it as a security gap.
150-150: ResultSet not explicitly closed in try-with-resources.The
ResultSetreturned fromexecuteQuery()should be managed in a try-with-resources block or explicitly closed to avoid potential resource leaks.try(PreparedStatement ps = connection.prepareStatement(sql)){ ps.setInt(1, missionId); - ResultSet rs = ps.executeQuery(); - - if (rs.next()) { + try (ResultSet rs = ps.executeQuery()) { + if (rs.next()) { + // ... print details + } else { + System.out.println(" No mission found with ID: " + missionId); + } + }
84-84: ResultSet not explicitly closed.Similar to other methods, the
ResultSetshould be in a try-with-resources block.src/test/java/com/example/CliAppIT.java (1)
210-210: Debug print statement in test.This
System.out.println(out)appears to be debug output. For cleaner test output, consider removing it or using a logging framework. If retained for debugging purposes during development, this is acceptable but may clutter CI logs.String out = runMainWithInput(input); - System.out.println(out); assertThat(out)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md(1 hunks)mvnw(1 hunks)pom.xml(1 hunks)src/main/java/com/example/Main.java(3 hunks)src/test/java/com/example/CliAppIT.java(1 hunks)
🔇 Additional comments (3)
mvnw (1)
2-2: LGTM!Trivial formatting change with no functional impact.
README.md (1)
1-1: LGTM!Standard GitHub Classroom deadline badge addition for assignment tracking.
pom.xml (1)
61-65: Verify usage ofapi.versionsystem property.The
api.version=1.44system property is configured but its consumption in the codebase could not be verified. If this is intended for future use, consider adding a comment explaining its purpose, or remove it if unused.
There was a problem hiding this comment.
Actionable comments posted: 4
♻️ Duplicate comments (2)
src/main/java/com/example/Main.java (2)
107-107: Still unhandled:NumberFormatExceptionfor menu choice.This issue from the previous review remains unresolved. Non-numeric input will crash the application.
Apply this diff to add exception handling:
System.out.println("Enter an option: "); - int choice = Integer.parseInt(sc.nextLine().trim()); + int choice; + try { + choice = Integer.parseInt(sc.nextLine().trim()); + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a number."); + continue; + }
177-196: Good fixes, but still missing exception handling.Nice work fixing the prompt text (line 178) and the typo (line 191) from the previous review. However, the
NumberFormatExceptionissue at line 179 remains unaddressed.Apply this diff to handle invalid input:
System.out.println("Launch year:"); - int launchYear = Integer.parseInt(sc.nextLine().trim()); + int launchYear; + try { + launchYear = Integer.parseInt(sc.nextLine().trim()); + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a valid year."); + return; + }Or consider reusing a helper method similar to the pattern in
getMissionById(lines 144-149) for consistency.
🧹 Nitpick comments (1)
src/main/java/com/example/Main.java (1)
198-225: Excellent fix for the name field issue!Great work adding the name generation (lines 207-208) and including it in the INSERT statement (lines 211, 216). This resolves the critical issue from the previous review where new accounts couldn't log in.
Optional improvement: Consider adding basic validation for SSN format and password strength requirements for better data integrity and security.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/example/Main.java(3 hunks)
🔇 Additional comments (2)
src/main/java/com/example/Main.java (2)
123-137: LGTM!Clean implementation using PreparedStatement with proper resource management via try-with-resources.
139-175: Excellent fix for input validation!Great job adding the try-catch loop (lines 144-149) to handle
NumberFormatException. This properly addresses the previous review concern and ensures the application won't crash on invalid input.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (3)
src/main/java/com/example/Main.java (3)
69-90: Password security concern remains unaddressed.Passwords are still compared in plain text. This was flagged in a previous review. Consider implementing password hashing (e.g., BCrypt) before production use.
105-106: HandleNumberFormatExceptionfor menu choice input.
Integer.parseInt()will throwNumberFormatExceptionif the user enters non-numeric input, causing the application to crash. This issue was previously flagged.System.out.println("Enter an option: "); - int choice = Integer.parseInt(sc.nextLine().trim()); + int choice; + try { + choice = Integer.parseInt(sc.nextLine().trim()); + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a number."); + continue; + }
176-178: UnhandledNumberFormatExceptionfor year input.
Integer.parseInt()at line 178 can crash the application on non-numeric input. This was previously flagged. Apply the same pattern used ingetMissionById:public void missionsCountByYear(Connection connection, Scanner sc) throws SQLException{ System.out.println("Launch year:"); - int launchYear = Integer.parseInt(sc.nextLine().trim()); + int launchYear; + try { + launchYear = Integer.parseInt(sc.nextLine().trim()); + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a valid year."); + return; + }
🧹 Nitpick comments (2)
src/main/java/com/example/Main.java (2)
226-252: Good fix: Input validation now handles non-numeric user ID.The try-catch properly handles
NumberFormatException. Consider checking the return value ofexecuteUpdate()to provide feedback when no account matches the given ID:- ps.executeUpdate(); + int rowsAffected = ps.executeUpdate(); + if (rowsAffected == 0) { + System.out.println("No account found with ID: " + userId); + return; + } } System.out.println("Password updated");
254-275: Good fix: Input validation handles non-numeric user ID.The try-catch properly handles
NumberFormatException. Similar toupdateAccount, consider checking affected rows and optionally adding a confirmation prompt before permanent deletion:- ps.executeUpdate(); + int rowsAffected = ps.executeUpdate(); + if (rowsAffected == 0) { + System.out.println("No account found with ID: " + userId); + return; + } } System.out.println("Account deleted");
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/com/example/Main.java(3 hunks)
🔇 Additional comments (4)
src/main/java/com/example/Main.java (4)
28-37: Good improvement: Scanner now uses try-with-resources.The Scanner is properly managed with try-with-resources alongside the Connection, which addresses the previous resource leak concern. The login flow is cleanly integrated.
122-136: LGTM!Clean implementation with proper resource management via try-with-resources.
138-174: Good fix: Input validation now handles non-numeric input.The loop with try-catch properly handles
NumberFormatExceptionand re-prompts the user, addressing the previous review concern. Implementation is solid.
197-224: Good fix:namecolumn is now properly populated.The
namecolumn is correctly derived from first/last name (lines 206-207) and included in the INSERT statement, addressing the previous critical issue.Minor nit: Consider capitalizing "account created" to "Account created" for consistency with other messages like "Password updated" and "Account deleted".
Summary by CodeRabbit
New Features
Documentation
Tests
Chores / Style
✏️ Tip: You can customize this high-level summary in your review settings.