Skip to content

Tatjanas branch#1

Open
TatjanaTrajkovic wants to merge 5 commits intomainfrom
TatjanasBranch
Open

Tatjanas branch#1
TatjanaTrajkovic wants to merge 5 commits intomainfrom
TatjanasBranch

Conversation

@TatjanaTrajkovic
Copy link

@TatjanaTrajkovic TatjanaTrajkovic commented Nov 30, 2025

Summary by CodeRabbit

  • New Features

    • Added login authentication and an interactive menu for moon mission browsing and account management.
  • Documentation

    • Added a deadline badge and clarified that Docker must be running for tests.
  • Tests

    • Exposed an integration-test system property for test runs and added debug output during integration tests.
  • Chores / Style

    • Minor script formatting cleanup.

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

@coderabbitai
Copy link

coderabbitai bot commented Nov 30, 2025

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • src/test/java/com/example/CliAppIT.java

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds a login-gated, Scanner-driven CLI menu for moon-mission and account operations in Main.java; exposes api.version=1.44 to failsafe during integration tests; documents Docker/Testcontainers as a test requirement and adds a deadline badge to README; small mvnw whitespace change and a test debug print.

Changes

Cohort / File(s) Change Summary
Documentation
README.md
Added a GitHub Classroom deadline badge line and an explicit note that Docker/Testcontainers must be running to execute tests.
Build files
mvnw, pom.xml
mvnw: added a blank line after the shebang. pom.xml: configured maven-failsafe-plugin to set systemPropertyVariables.api.version = 1.44 for integration-test executions.
Application logic
src/main/java/com/example/Main.java
Introduced login flow, try-with-resources DB connection handling, and a menu-driven interaction using Scanner. Added public methods: listMoonMissions(Connection), getMissionById(Connection, Scanner), missionsCountByYear(Connection, Scanner), createAccount(Connection, Scanner), updateAccount(Connection, Scanner) and a private deleteAccount(...). Uses java.sql.* and prepared statements for DB operations.
Integration tests
src/test/java/com/example/CliAppIT.java
Added System.out.println(out); to print test output before the existing assertion.

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
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review focus:
    • src/main/java/com/example/Main.java: authentication correctness, input validation, resource/exception management (Connection, PreparedStatement, ResultSet), SQL parameterization and error handling.
    • pom.xml: verify failsafe property placement and test behavior.
    • README.md and CliAppIT.java: ensure documented test requirement is clear and the added debug print is intentional.

Poem

🐰 I hopped in code with eager paws,
A menu formed, with SQL laws.
I guard the login, count the moons,
I plant a badge and print the runes.
Hooray — tests wait while Docker yawns! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title 'Tatjanas branch' is vague and does not describe the actual changes, which include adding login flows, menu-driven interactions, moon mission operations, and account management features. Replace with a descriptive title that summarizes the main changes, such as 'Add login flow and moon mission/account management features' or 'Implement user authentication and mission/account operations'.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

@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: 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.1 does 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. Update junit.jupiter.version to 5.13.4 or 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 ResultSet returned from executeQuery() 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 ResultSet should 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

📥 Commits

Reviewing files that changed from the base of the PR and between e629e94 and 683af62.

📒 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 of api.version system property.

The api.version=1.44 system 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.

Copy link

@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: 4

♻️ Duplicate comments (2)
src/main/java/com/example/Main.java (2)

107-107: Still unhandled: NumberFormatException for 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 NumberFormatException issue 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

📥 Commits

Reviewing files that changed from the base of the PR and between 683af62 and 4ba8a46.

📒 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.

Copy link

@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

♻️ 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: Handle NumberFormatException for menu choice input.

Integer.parseInt() will throw NumberFormatException if 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: Unhandled NumberFormatException for year input.

Integer.parseInt() at line 178 can crash the application on non-numeric input. This was previously flagged. Apply the same pattern used in getMissionById:

     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 of executeUpdate() 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 to updateAccount, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba8a46 and 3c7ca7e.

📒 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 NumberFormatException and re-prompts the user, addressing the previous review concern. Implementation is solid.


197-224: Good fix: name column is now properly populated.

The name column 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".

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