KouroshKSH / Java-GitHub-Explorer

The Java GitHub Explorer is an Android mobile application designed to help users in discovering and exploring top projects on GitHub using Java.
MIT License
0 stars 1 forks source link

First Attempt #7

Closed KouroshKSH closed 9 months ago

KouroshKSH commented 9 months ago

Task

Implement a basic back-and-forth interaction between the user and the app via the terminal. The user will be asked to either:

  1. log in
  2. sign up

Based on the user's choice:

Structure

  1. User Class:

    • A class representing a user with attributes like username, password, etc.
    • Methods to handle user-related operations like creating, validating, and fetching user details.
  2. Database Handler:

    • A class responsible for interacting with the MongoDB database.
    • Methods to perform database operations like inserting a new user, querying users, etc.
  3. Main Class:

    • A class that contains the main method to interact with users via the terminal.

Steps to Implement

  1. User Class:

    • Create a User class with attributes like username, password, etc.
    • Include methods to create a new user, check if a user exists, and validate passwords.
  2. Database Handler:

    • Implement a class (DatabaseHandler, for instance) to handle interactions with MongoDB using appropriate libraries (like Spring Data MongoDB).
    • Include methods to insert a new user, query for users based on username, etc.
  3. Main Class:

    • Write the main method in a separate class (MainClass, for example).
    • In the main method, create instances of User and DatabaseHandler classes.
    • Use Scanner to get user input from the terminal and provide choices for sign-up or login.
    • Based on the user's choice, prompt for necessary inputs (username, password).
    • Use methods from the User class to handle user-related operations (sign-up, login) and methods from the DatabaseHandler class to interact with the database.

Code Skeleton

Here's a basic skeleton of how the classes might look:

// User Class
public class User {
    private String username;
    private String password;

    // Constructor, getters, setters, etc.

    public void createUser(String username, String password) {
        // Implementation to create a new user
    }

    public boolean userExists(String username) {
        // Check if user exists in the database
    }

    public boolean validatePassword(String username, String password) {
        // Validate user password
    }
}

// Database Handler Class
public class DatabaseHandler {
    // MongoDB connection and setup

    public void insertUser(User user) {
        // Insert a new user into the database
    }

    public User getUserByUsername(String username) {
        // Get user details by username from the database
    }
}

// Main Class
public class MainClass {
    public static void main(String[] args) {
        User user = new User();
        DatabaseHandler dbHandler = new DatabaseHandler();

        // Logic for user interaction, sign-up, and login process
    }
}

This structure provides a basic outline to implement user sign-up, login, and interaction with the database. It's essential to add MongoDB connection setup, handle exceptions, and implement user input validation as needed. Each class is responsible for a specific set of functionalities, ensuring a clean and maintainable codebase.

KouroshKSH commented 9 months ago

To Do:

KouroshKSH commented 9 months ago

To Do:

KouroshKSH commented 9 months ago

In user interaction:

KouroshKSH commented 9 months ago
// in UserInteractionHandler.java
// in signUp()
        DatabaseHandler dbHandler = new DatabaseHandler();

        System.out.println("\n> Printing a list 4 of random repositories:\n");
        List<Document> result = dbHandler.getRandomRepositories(4);
        dbHandler.printRepositories(result);

        System.out.println("\n> Printing the list of repositories that have more than 100'000 stars:\n");
        result = dbHandler.filterReposWithStarsGEQ(100000);
        dbHandler.printRepositories(result);

        System.out.println("\n> Let's see if `awesome-neovim` exists in the database. If so, print its information.\n");
        result = dbHandler.findRepoByTitle("awesome-neovim");
        dbHandler.printRepositories(result);

        System.out.println("\n> Let's see if `lazygit` exists in the database. If so, print its information.\n");
        result = dbHandler.findRepoByTitle("lazygit");
        dbHandler.printRepositories(result);