Skip to content

G level#11

Open
jesperlarsson1910 wants to merge 5 commits intomainfrom
GLevel
Open

G level#11
jesperlarsson1910 wants to merge 5 commits intomainfrom
GLevel

Conversation

@jesperlarsson1910
Copy link

@jesperlarsson1910 jesperlarsson1910 commented Dec 11, 2025

All test pass, but missing comments and can be improved

Summary by CodeRabbit

  • New Features

    • Added interactive login system with authentication
    • Implemented menu-driven interface for mission and account management
    • Added account operations: create accounts, update passwords, delete accounts
    • Added mission queries: list missions, view mission details, count by year
    • Added input validation for all user entries
  • Documentation

    • Updated README with review assignment information

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

github-classroom bot and others added 5 commits December 3, 2025 13:53
Signed-off-by: Jesper Larsson <jesper.larsson@iths.se>
Signed-off-by: Jesper Larsson <jesper.larsson@iths.se>
Signed-off-by: Jesper Larsson <jesper.larsson@iths.se>
Signed-off-by: Jesper Larsson <jesper.larsson@iths.se>
@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

The PR adds a header badge to README.md and substantially refactors Main.java to introduce an interactive application with login authentication, menu-driven operations for moon mission management, and account administration features backed by database queries using PreparedStatement.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added a header badge for Review Assignment Due Date; all other content unchanged.
Core Application
src/main/java/com/example/Main.java
Refactored to introduce interactive application flow: added run() instance method with persistent Scanner, login/authentication via prepared statement, interactive menu for moon mission queries and account management (create, update, delete accounts), input validation helpers (name, SSN, password, integer parsing), expanded imports including java.sql.*, and integrated control flow with authorization checks and operation handlers.

Sequence Diagram

sequenceDiagram
    actor User
    participant App as Main<br/>(Application)
    participant DB as Database
    
    User->>App: Launch Application
    activate App
    
    App->>User: Prompt for Login
    User->>App: Enter Credentials
    
    App->>DB: Verify Username & Password<br/>(PreparedStatement)
    DB-->>App: Auth Result
    
    alt Authentication Failed
        App->>User: Invalid Credentials
        App->>User: Retry or Exit?
        User->>App: Retry
        App->>User: Prompt for Login
    else Authentication Successful
        App->>User: Login Successful
        
        loop Interactive Menu
            App->>User: Display Menu Options<br/>(List, Get, Count, Create, Update, Delete)
            User->>App: Select Operation
            
            alt Query Operations
                App->>DB: Execute Query<br/>(List Missions / Get Mission / Count by Year)
                DB-->>App: ResultSet
                App->>User: Display Results
            else Write Operations
                App->>User: Prompt for Input
                User->>App: Provide Details<br/>(validated)
                App->>DB: INSERT/UPDATE/DELETE<br/>(PreparedStatement)
                DB-->>App: Confirmation
                App->>User: Operation Confirmation
            end
            
            App->>User: Continue or Exit?
        end
        
        App->>User: Goodbye
    end
    
    deactivate App
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

  • Login/authentication logic with PreparedStatement interaction and retry loop—verify credential handling and SQL injection prevention
  • Multiple operation handlers (listMissions, getMission, missionsCountYear, createAccount, updatePassword, deleteAccount)—each requires separate logic verification
  • Input validation suite (getValidInt, getValidName, getValidSSN, getValidPassword)—check correctness of constraints, formatting, and edge cases
  • Control flow refactoring from static main() to instance-based run()—ensure proper Scanner lifecycle and state management
  • Database interaction patterns across multiple queries and updates—verify all PreparedStatement usage and ResultSet handling

Poem

🐰 A login path now guards the gate,
With menus bright to navigate,
Moon missions tracked with SQL's care,
Accounts created, passwords fair—
The warren's reach extends so far! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'G level' is vague and does not convey meaningful information about the changes. It appears to refer to a branch name rather than describing the actual changeset modifications. Revise the title to clearly describe the main changes, such as 'Add interactive login and menu-driven account management system' or 'Implement user authentication and account operations in Main.java'.
✅ 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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/com/example/Main.java (1)

13-18: Critical: Missing public modifier on main method.

The main method must be declared public for the JVM to invoke it as the application entry point. Without it, running java com.example.Main will fail with "Error: Main method not found in class".

-    static void main(String[] args) {
+    public static void main(String[] args) {
🧹 Nitpick comments (7)
src/main/java/com/example/Main.java (7)

5-5: Unused import.

Comparator is imported but never used in this file.

-import java.util.Comparator;

11-11: Consider making the Scanner field private.

The field has package-private access by default. For better encapsulation, mark it private.

-    Scanner scanner = new Scanner(System.in);
+    private final Scanner scanner = new Scanner(System.in);

34-53: Remove commented-out code and consider retry logic.

Line 35 has leftover commented code that should be removed. Additionally, after a failed login, the user is stuck in an infinite loop with only the exit option (0). Consider whether retry attempts should be allowed.

         while(true) {
-            //Scanner scanner = new Scanner(System.in);
             boolean authorized = login(connection);

87-99: Improve ResultSet handling and column reference.

  1. The ResultSet should be explicitly closed (use try-with-resources or alias in query)
  2. Using count(*) as the column name is fragile; prefer a column alias or index
  3. COUNT(*) always returns exactly one row, so if (rs.next()) is clearer than while
-        String accQuery = "select count(*) from account where binary name = ? and binary password = ?";
+        String accQuery = "SELECT COUNT(*) AS cnt FROM account WHERE BINARY name = ? AND BINARY password = ?";
         try(PreparedStatement statement = connection.prepareStatement(accQuery)){
             statement.setString(1, unm);
             statement.setString(2, pw);

-            ResultSet rs = statement.executeQuery();
-            while(rs.next()) {
-                if(rs.getInt("count(*)") == 1){return true;}
+            try (ResultSet rs = statement.executeQuery()) {
+                return rs.next() && rs.getInt("cnt") == 1;
             }
-            return false;
         } catch (SQLException e) {
             throw new RuntimeException(e);
         }

118-126: Close ResultSet explicitly.

The ResultSet should be closed via try-with-resources to ensure proper resource cleanup.

         try(PreparedStatement statement = connection.prepareStatement(spaceshipQuery)){
-            ResultSet rs = statement.executeQuery();
-            while(rs.next()) {
-                System.out.println(rs.getString("spacecraft"));
+            try (ResultSet rs = statement.executeQuery()) {
+                while(rs.next()) {
+                    System.out.println(rs.getString("spacecraft"));
+                }
             }
         } catch (SQLException e) {

The same pattern should be applied to getMission, missionsCountYear, and createAccount methods.


219-228: Prefer explicit column list in INSERT statement.

Using INSERT INTO account VALUES (0, ?, ...) relies on column order and assumes the first column is auto-increment. Explicitly listing columns improves clarity and resilience to schema changes.

-        String newAccQuery = "insert into account values (0, ?, ?, ?, ?, ?)";
+        String newAccQuery = "INSERT INTO account (name, password, first_name, last_name, ssn) VALUES (?, ?, ?, ?, ?)";

250-252: Consider checking affected row count.

executeUpdate() returns the number of affected rows. If user_id doesn't exist, this prints "updated" even though nothing changed. Consider providing feedback when no rows are affected.

-            statement.executeUpdate();
-
-            System.out.println("updated");
+            int rowsAffected = statement.executeUpdate();
+            if (rowsAffected > 0) {
+                System.out.println("updated");
+            } else {
+                System.out.println("No account found with that ID");
+            }

The same applies to deleteAccount().

📜 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 16d6c42.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • src/main/java/com/example/Main.java (2 hunks)
🔇 Additional comments (3)
README.md (1)

1-1: LGTM!

Standard GitHub Classroom badge addition for tracking assignment due dates.

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

280-345: LGTM!

The input validation helpers are well-structured with clear prompts and appropriate validation logic. Good use of Pattern.matches() for SSN format validation and proper handling of edge cases.


348-373: Existing utility methods remain correct.

The isDevMode and resolveConfig methods are unchanged and continue to work correctly with the new interactive flow.

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