diff --git a/backend/src/main/java/djmil/cordacheckers/api/LeaderboardController.java b/backend/src/main/java/djmil/cordacheckers/api/LeaderboardController.java new file mode 100644 index 0000000..cd219a1 --- /dev/null +++ b/backend/src/main/java/djmil/cordacheckers/api/LeaderboardController.java @@ -0,0 +1,34 @@ +package djmil.cordacheckers.api; + +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import djmil.cordacheckers.cordaclient.CordaClient; +import djmil.cordacheckers.cordaclient.dao.Rank; +import djmil.cordacheckers.user.HoldingIdentityResolver; + + +@RestController +@RequestMapping("api/leaderboard") +public class LeaderboardController { + + @Autowired + HoldingIdentityResolver holdingIdentityResolver; + + @Autowired + CordaClient cordaClient; + + @GetMapping + public ResponseEntity> getLeaderboard() { + final var hiCustodian = holdingIdentityResolver.getCustodian(); + final Map leaderboard = cordaClient.fetchRanking(hiCustodian); + + return ResponseEntity.ok(leaderboard); + } + +} \ No newline at end of file diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index e3874dc..aa7972a 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -2,7 +2,7 @@ trust.store=classpath:keystore/truststore.p12 trust.store.password=test123 -corda.host=https://localhost +corda.host=https://192.168.10.8 corda.port=8888 corda.root.login=admin corda.root.passw=admin diff --git a/webapp/src/App.js b/webapp/src/App.js index 1915a39..7b86bbb 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -1,17 +1,15 @@ import './App.css'; +import Leaderboard from "./Leaderboard"; import React, { useState, useEffect } from 'react'; function App() { - - const [activeGames, setActiveGames] = useState(null); + const [data, setData] = useState(null); useEffect(() => { - fetch('/api/activegames') + fetch('/api/leaderboard') .then((response) => response.json()) - .then((games) => { - console.log(games.ActiveGames.length); - console.log("games: " +games.ActiveGames); - setActiveGames(games.ActiveGames); + .then((data) => { + setData(data); }) .catch((err) => { console.log(err.message); @@ -21,9 +19,10 @@ function App() { return (
-

- Here is list of your active games: {activeGames ? {activeGames} : Loading...} -

+

Leaderboard

+ { + data ? : Loading... + }
); diff --git a/webapp/src/Leaderboard.js b/webapp/src/Leaderboard.js new file mode 100644 index 0000000..9802bd5 --- /dev/null +++ b/webapp/src/Leaderboard.js @@ -0,0 +1,46 @@ +import React from "react"; + +//const Leaderboard = ({hashmap}) => { + +// var listItems = Object.keys(hashmap).map(playerName => { +// var rank = hashmap[playerName]; + +// return
  • +// {playerName}: played {rank.gamesPlayed}, won {rank.gamesWon}, draw {rank.gamesDraw} +//
  • +// }); + +// return ; + +const Leaderboard = ({ hashmap }) => { + + const tableRows = Object.keys(hashmap).map(playerName => { + var rank = hashmap[playerName]; + + return + {playerName} + {rank.gamesPlayed} + {rank.gamesWon} + {rank.gamesDraw} + + }); + + return
    + + + + + + + + + + + { tableRows } + +
    NamePlayedWonDraw
    +
    +}; + + +export default Leaderboard;