Skip to content

Commit

Permalink
🎉 Created method for get order from ranking.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurr0 committed Oct 2, 2021
1 parent 1d4c38c commit fc32982
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.ReplaceOptions;
import com.mongodb.client.model.Sorts;
import eu.okaeri.injector.annotation.Inject;
import org.bson.Document;
import pl.minecodes.mineeconomy.data.configuration.Configuration;
Expand Down Expand Up @@ -59,4 +60,14 @@ public void connect() {
mongoCollection = mongoDatabase.getCollection("economyUsers");
this.logger.info("Successfully connected to MongoDb database.");
}

@Override
public Profile order(int order) {
int i = 1;
for (Document document : mongoCollection.find().sort(Sorts.descending("balance"))) {
if (i == order) return new Profile(UUID.fromString(document.getString("uniqueId")), document.getDouble("balance"));
i++;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void saveData(Profile profile) {
preparedStatement.setString(1, profile.getUniqueId().toString());
preparedStatement.setDouble(2, profile.getBalance());
preparedStatement.executeUpdate();
this.logger.info("Successfully updated profile by uniqueId " + profile.getUniqueId() + " to MySQL data.");
} catch (SQLException exception) {
this.logger.severe("There was an unexpected incident, while trying to save profile with id " + profile.getUniqueId());
exception.printStackTrace();
Expand Down Expand Up @@ -70,6 +69,11 @@ public void connect() {
}
}

@Override
public Profile order(int order) {
return null;
}

private Connection getConnection() throws SQLException {
if (connection == null || connection.isClosed()) {
connection = dataSource.getConnection();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.minecodes.mineeconomy.data.database.element.model;


import pl.minecodes.mineeconomy.profile.Profile;

import java.util.UUID;
Expand All @@ -14,4 +13,6 @@ public interface DataService {
void deleteData(Profile profile);

void connect();

Profile order(int order);
}

0 comments on commit fc32982

Please sign in to comment.