Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Staehler, Michael committed Apr 4, 2024
1 parent 7def4dd commit 17597ea
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ Select b.user_name, a.match_group, sum(b.points)
}

public Map<String, Integer> sumPointsPerUserForFavoriteCountry(Country favoriteCountry) {
StringBuilder builder = new StringBuilder();
builder.append("Select a.user_name, sum(a.points) ");
builder.append("from bet a join matches b on a.match_id = b.match_id ");
builder.append("where b.country_one = :country or b.country_two = :country ");
builder.append("group by a.user_name ");
final String query = """
Select a.user_name, sum(a.points)
from bet a join matches b on a.match_id = b.match_id
where b.country_one = :country or b.country_two = :country
group by a.user_name
""";

MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("country", favoriteCountry.name());

Map<String, Integer> userPoints = new HashMap<>();
namedParameterJdbcOperations.query(builder.toString(), params, (ResultSet rs) -> {
namedParameterJdbcOperations.query(query, params, (ResultSet rs) -> {
String userName = rs.getString(1);
int points = rs.getInt(2);
if (!fredbetProperties.adminUsername().equals(userName)) {
Expand Down

0 comments on commit 17597ea

Please sign in to comment.