Merge branch 'develop' into frontend/kathy

This commit is contained in:
Katharina Will 2019-04-08 14:50:27 +02:00
commit 7613fee705
2 changed files with 15 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package hhn.labsw.bugageocaching.controller;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import hhn.labsw.bugageocaching.entities.*;
import hhn.labsw.bugageocaching.exceptions.IllegalParameterException;
import hhn.labsw.bugageocaching.repositories.*;
@ -10,10 +11,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
@RestController
@ -297,7 +295,18 @@ public class Controller {
@RequestMapping("/api/getRankingList")
@ResponseBody
public ResponseEntity getRankingList() {
return ResponseEntity.status(200).body(new Gson().toJson(userRepository.getRankingList()));
List<User> sendBackUsers = new LinkedList<>();
List<Object[]> rankingUsers = userRepository.getRankingList();
for (Object[] obj : rankingUsers) {
User u = new User();
u.setId((int) obj[0]);
u.setUsername((String) obj[1]);
u.setRankingPointsSum((int) obj[2]);
sendBackUsers.add(u);
}
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose

View File

@ -10,6 +10,6 @@ import java.util.List;
public interface UserRepository extends CrudRepository<User, Integer> {
User findByUsername(String username);
@Query(value = "SELECT u.id u.username, u.ranking_points_sum from user u order by ranking_points_sum DESC", nativeQuery = true)
@Query(value = "SELECT u.id, u.username, u.ranking_points_sum from user u order by ranking_points_sum DESC", nativeQuery = true)
List<Object[]> getRankingList();
}