Skip to content

Implement CLI application with JDBC + repository pattern#17

Closed
addee1 wants to merge 10 commits intomainfrom
cli-implementation
Closed

Implement CLI application with JDBC + repository pattern#17
addee1 wants to merge 10 commits intomainfrom
cli-implementation

Conversation

@addee1
Copy link
Copy Markdown

@addee1 addee1 commented Dec 12, 2025

  • Complete CLI application interacting with MySQL through JDBC
  • Login validation
  • CUD for accounts
  • Added DataSource implementation
  • Implemented repository pattern
  • Updates main to use repositories

Summary by CodeRabbit

  • New Features
    • User authentication system requiring login at startup
    • Account management: create, update password, and delete accounts
    • Moon mission tracking with options to list spacecraft, query missions by ID, and count missions by year
    • Interactive menu-driven console interface with color-coded output for improved user experience

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR introduces a complete data access layer with JDBC repositories for account and moon mission management, adds a simple DataSource implementation, and expands the Main application with an interactive console-driven menu system for user authentication, account operations, and mission queries.

Changes

Cohort / File(s) Summary
Documentation & Configuration
README.md, todo.txt, pom.xml
Added badge to README; added procedural specification for authentication and menu-driven operations in todo.txt; added slf4j-nop (v2.0.17) dependency to pom.xml.
Domain Model
src/main/java/com/example/Mission.java
New entity class with missionId (long) and spacecraft (String) fields and constructor.
Repository Interfaces
src/main/java/com/example/AccountRepository.java, src/main/java/com/example/MoonMissionRepository.java
Added AccountRepository interface with login, create, updatePassword, delete, exists methods; added MoonMissionRepository interface with listSpacecraft, getMissionById, countByYear methods.
DataSource Implementation
src/main/java/com/example/SimpleDriverManagerDataSource.java
New DataSource implementation wrapping DriverManager with JDBC URL, username, and password; provides getConnection() overloads and standard DataSource method stubs.
Repository Implementations
src/main/java/com/example/JdbcAccountRepository.java, src/main/java/com/example/JdbcMoonMissionRepository.java
Added JDBC implementations of AccountRepository and MoonMissionRepository; JdbcAccountRepository handles account authentication, creation, password updates, deletion, and existence checks; JdbcMoonMissionRepository handles spacecraft listing, mission retrieval by ID, and mission counting by year. Both use try-with-resources and prepared statements.
Application Entry Point
src/main/java/com/example/Main.java
Replaced minimal JDBC block with full interactive console flow: initializes DataSource-backed repositories, adds colorized output constants (RESET, RED, GREEN, YELLOW, BLUE), implements user login authentication, and provides menu-driven session with options for mission listing, retrieval, year-based counting, and account management (create, update password, delete).

Sequence Diagram

sequenceDiagram
    actor User
    participant Main
    participant Scanner as Input Handler
    participant AccountRepo as JdbcAccountRepository
    participant DB as Database
    participant MissionRepo as JdbcMoonMissionRepository

    User->>Main: Start application
    Main->>Scanner: Prompt for username/password
    User->>Scanner: Enter credentials
    Scanner->>Main: Return credentials
    Main->>AccountRepo: login(username, password)
    AccountRepo->>DB: SELECT from accounts table
    DB-->>AccountRepo: Query result
    alt Authentication Success
        AccountRepo-->>Main: true
        Main->>User: Display main menu
        loop Menu Selection
            User->>Scanner: Select option (1-6)
            Scanner->>Main: Return choice
            alt List Missions
                Main->>MissionRepo: listSpacecraft()
                MissionRepo->>DB: SELECT spacecraft FROM moon_mission
                DB-->>MissionRepo: Results
                MissionRepo-->>Main: List<String>
                Main->>User: Display missions
            else Get Mission by ID
                Main->>Scanner: Prompt for mission ID
                User->>Scanner: Enter ID
                Scanner->>Main: Return ID
                Main->>MissionRepo: getMissionById(id)
                MissionRepo->>DB: SELECT mission data by ID
                DB-->>MissionRepo: Mission object
                MissionRepo-->>Main: Mission
                Main->>User: Display mission details
            else Count by Year
                Main->>Scanner: Prompt for year
                User->>Scanner: Enter year
                Scanner->>Main: Return year
                Main->>MissionRepo: countByYear(year)
                MissionRepo->>DB: SELECT COUNT where YEAR(launch_date)=?
                DB-->>MissionRepo: Count
                MissionRepo-->>Main: int count
                Main->>User: Display count
            else Account Operations
                Main->>Scanner: Prompt for account operation details
                User->>Scanner: Enter details
                Scanner->>Main: Return details
                alt Create Account
                    Main->>AccountRepo: create(first, last, ssn, password)
                    AccountRepo->>DB: INSERT into accounts
                    DB-->>AccountRepo: Generated key
                else Update Password
                    Main->>AccountRepo: updatePassword(userId, newPassword)
                    AccountRepo->>DB: UPDATE accounts
                else Delete Account
                    Main->>AccountRepo: delete(userId)
                    AccountRepo->>DB: DELETE from accounts
                end
                AccountRepo-->>Main: Operation result
                Main->>User: Confirmation message
            end
        end
    else Authentication Failure
        AccountRepo-->>Main: false
        Main->>User: Display error, exit
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Main.java: Review interactive menu logic, Scanner handling, repository method calls, and colorized output integration—ensure proper flow control and error handling.
  • JDBC Repository Implementations: Verify SQL correctness, proper use of prepared statements, try-with-resources resource management, and exception handling in both JdbcAccountRepository and JdbcMoonMissionRepository.
  • SimpleDriverManagerDataSource: Confirm DataSource interface compliance, proper delegation to DriverManager, and correct handling of method stubs.
  • New Repository Interfaces & Entity: Validate method signatures and ensure consistency across interface contracts and implementations.

Poem

🐰 A database hop, a moon mission quest,
Where logins authenticate, and accounts rest,
With JDBC springs and DataSource delight,
We list, we count, we update through the night!
The console dances in colors so bright,
All thanks to the repos that get it just right! 🚀✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent 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 2ffe941.

📒 Files selected for processing (10)
  • README.md (1 hunks)
  • pom.xml (1 hunks)
  • src/main/java/com/example/AccountRepository.java (1 hunks)
  • src/main/java/com/example/JdbcAccountRepository.java (1 hunks)
  • src/main/java/com/example/JdbcMoonMissionRepository.java (1 hunks)
  • src/main/java/com/example/Main.java (2 hunks)
  • src/main/java/com/example/Mission.java (1 hunks)
  • src/main/java/com/example/MoonMissionRepository.java (1 hunks)
  • src/main/java/com/example/SimpleDriverManagerDataSource.java (1 hunks)
  • todo.txt (1 hunks)

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.

@addee1 addee1 closed this Dec 12, 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