Skip to content

Lab3#5

Closed
johanbriger wants to merge 2 commits intomainfrom
LAB3
Closed

Lab3#5
johanbriger wants to merge 2 commits intomainfrom
LAB3

Conversation

@johanbriger
Copy link
Copy Markdown

@johanbriger johanbriger commented Dec 7, 2025

Summary by CodeRabbit

Release Notes

  • Documentation

    • Added review assignment due date badge to README.
  • New Features

    • Introduced user login and authentication system.
    • Launched interactive menu-driven interface for database operations and management.
    • Added moon mission capabilities: list all missions, view mission details, and count missions by year.
    • Enabled comprehensive account management: create new accounts, update user passwords, and delete accounts.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 7, 2025

Walkthrough

README.md receives a documentation badge update. Main.java undergoes substantial refactoring to introduce database connectivity, user authentication via login, an interactive menu-driven command loop, and comprehensive CRUD operations for moon missions and account management with proper connection lifecycle handling.

Changes

Cohort / File(s) Summary
Documentation Updates
README.md
Added "Review Assignment Due Date" badge line at the top of the file for tracking review deadlines.
Application Logic & Database Integration
src/main/java/com/example/Main.java
Added persistent Scanner and Connection fields; introduced JDBC configuration (URL, user, password) with early validation; implemented login() with username/password validation against account table; added mainMenu() loop dispatching user choices to operations; implemented seven CRUD/query methods: listMoonMissions(), getMoonMissionById(), countMissionsByYear(), createAccount(), updateAccountPassword(), deleteAccount(); added closeConnection() for resource cleanup; expanded imports to include java.sql.\*; refactored main() to delegate to run-based flow with try-finally for connection management.

Sequence Diagram

sequenceDiagram
    participant User
    participant App as Main App
    participant DB as Database

    User->>App: Start Application
    App->>DB: Establish JDBC Connection
    DB-->>App: Connection Ready
    App->>User: Prompt for Login
    User->>App: Enter Username & Password
    App->>DB: Query account table
    DB-->>App: Validate Credentials
    alt Login Success
        App->>User: Display Menu
        loop User Interaction
            User->>App: Select Menu Option
            alt List Missions
                App->>DB: SELECT from moon_mission
                DB-->>App: Mission Data
                App->>User: Display Missions
            else Get Mission by ID
                App->>User: Prompt for mission_id
                User->>App: Provide mission_id
                App->>DB: SELECT by mission_id
                DB-->>App: Mission Details
                App->>User: Display Details
            else CRUD Account Operations
                App->>DB: INSERT/UPDATE/DELETE account
                DB-->>App: Operation Result
                App->>User: Confirm Success
            else Exit
                App->>DB: Close Connection
                DB-->>App: Connection Closed
                App->>User: Goodbye
            end
        end
    else Login Failure
        App->>User: Invalid Login Message
        App->>User: Retry Login
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Areas requiring extra attention:

  • SQL injection vulnerability risk in prepared statement construction across multiple CRUD methods
  • Connection lifecycle management and resource cleanup guarantees in all execution paths
  • Login validation logic and account table schema assumptions
  • Input validation and type conversion for user-provided data (String, long, int)
  • Exception handling coverage for SQLException scenarios across all database operations

Poem

🐰 Hopping through the database deep,
With logins, menus, treasures to keep,
Moon missions logged, accounts all neat,
CRUD operations, oh what a feat!
Connection closed with care and grace,
Interactive joy at every place!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Lab3' is vague and generic, providing no meaningful information about the specific changes made in this pull request. Replace 'Lab3' with a descriptive title that summarizes the main change, such as 'Add database connectivity and user authentication to Main class' or 'Implement moon mission CRUD operations and login system'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/com/example/Main.java (1)

136-186: Query methods for missions are correct; consider deterministic ordering

  • listMoonMissions() selects spacecraft from moon_mission and prints one line per row; this satisfies the “list moon missions” requirement.
  • getMoonMissionById() prompts for mission_id, uses a prepared statement with mission_id = ?, and prints a clear details block or a “not found” message.
  • countMissionsByYear() prompts for year, uses YEAR(launch_date) = ?, and prints the count in a readable sentence.

One small enhancement for test determinism and user experience:

-        String sql = "SELECT spacecraft FROM moon_mission";
+        String sql = "SELECT spacecraft FROM moon_mission ORDER BY mission_id";

This guarantees a stable order if tests or users implicitly rely on the mission listing order.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e629e94 and 8ba1148.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • src/main/java/com/example/Main.java (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/com/example/Main.java (1)
src/main/java/com/example/DevDatabaseInitializer.java (1)
  • DevDatabaseInitializer (6-24)
🔇 Additional comments (5)
README.md (1)

1-1: Badge addition is fine

The new GitHub Classroom due-date badge is well-formed Markdown and doesn’t affect build/runtime. No issues here.

src/main/java/com/example/Main.java (4)

10-11: Connection lifecycle and config resolution look solid

  • Config is read via resolveConfig with system-properties-first precedence, matching the README description.
  • You fail fast on missing DB config and open a single Connection in run(), then close it in a finally block via closeConnection(), which is exactly what we want for this small CLI.
  • Using a single Scanner field on System.in shared across methods is appropriate here; not closing it avoids accidentally closing System.in.

No functional issues spotted in this region.

Also applies to: 22-29, 31-45, 261-270


81-122: Menu loop and input handling are robust

  • mainMenu() uses a standard while (choice != 0) loop, prints the menu each time, and handles InputMismatchException by warning the user and clearing the scanner buffer with nextLine().
  • Because the try covers the entire switch block, InputMismatchException thrown inside sub‑methods that read numbers (e.g., getMoonMissionById, countMissionsByYear, etc.) will also be caught here, which is a nice centralised error handling strategy.
  • On SQLException, you log a clear error and keep the app running so the user can try another operation.

The prompts and menu text align with the README requirements for options 0–6.

Also applies to: 124-134


188-259: Account CRUD operations match the assignment and use JDBC safely

  • createAccount():

    • Prompts for first name, last name, ssn, password as required.
    • Generates a username from firstName[0..3) + lastName[0..3), which is consistent with the example AngFra in the README.
    • Inserts with a prepared statement and prints a clear success/failure message, including the generated username.
  • updateAccountPassword() and deleteAccount():

    • Prompt for user_id and use prepared statements for UPDATE/DELETE.
    • Check rowsAffected and print different messages for “found” vs “not found” – good UX and no SQL injection risk.

The implementations look correct and should satisfy the create/update/delete account tests.


49-77: Align invalid-login message with assignment wording

The overall login flow is correct: it prompts for Username: and Password:, checks account.name + password via a prepared statement, and on failure delegates to handleInvalidLogin() where the user can exit with 0.

The assignment explicitly requires a message containing the word invalid. Your current message uses "Invalid..." (capitalized), which may not match case-sensitive test assertions. Update to:

-        System.out.println("Invalid username or password. Press 0 to exit.");
+        System.out.println("Login invalid. Press 0 to exit.");

After this change, run ./mvnw verify to confirm the login tests pass.

@johanbriger johanbriger closed this Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant