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

Printing Random Repositories Modification #14

Closed KouroshKSH closed 9 months ago

KouroshKSH commented 9 months ago

Issue

All other methods in the DatabaseHanlder.java file return a list of documents (i.e., repos) that will be later used by the printRepositories(List<Document>) function to be printed elegantly. However, this is not the case with getRandomRepositories(int num).

Fix

To make the code more robust and functional, modify this function to return a list of repositories like other functions so that its content would be neatly printed like the rest (currently, even the _id is being printed).

public List<Document> getRandomRepositories(int num) {
    // Aggregation pipeline for randomly selecting `num` number of documents
    List<Document> randomEntries = reposCollection.aggregate(
        Arrays.asList(
            Aggregates.sample(num)
        )
    ).into(new java.util.ArrayList<>());

    // Return the retrieved documents
    return randomEntries;
}
KouroshKSH commented 9 months ago

now fixed