Graph database Analysis of the Steam Network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

  1. package net.jrtechs.www.server;
  2. import com.google.gson.Gson;
  3. import com.google.gson.reflect.TypeToken;
  4. import net.jrtechs.www.graphDB.SteamGraph;
  5. import net.jrtechs.www.model.Game;
  6. import net.jrtechs.www.model.Player;
  7. import java.lang.reflect.Type;
  8. import java.util.List;
  9. import static spark.Spark.*;
  10. /**
  11. * Quick and dirty web server to serve as an API backend to
  12. * the graph interface.
  13. *
  14. * @author Jeffery Russell 7-12-20
  15. */
  16. public class WebServer
  17. {
  18. private SteamGraph graph;
  19. private Gson gson;
  20. public static String GET_PLAYER = "/player";
  21. public static String GET_GAMES = "/games";
  22. public WebServer()
  23. {
  24. this.graph = new SteamGraph();
  25. this.gson = new Gson();
  26. Type typePlayer = new TypeToken<Player>(){}.getType();
  27. Type typeGames = new TypeToken<List<Game>>(){}.getType();
  28. staticFileLocation("/website");
  29. get("/player/:id", (req, res) ->
  30. gson.toJson(
  31. graph.getPlayer(req.params(":id")), typePlayer));
  32. get("/games/:id", (req, res) ->
  33. gson.toJson(
  34. graph.getGameList(req.params(":id")), typeGames));
  35. System.out.println("Finished starting web server");
  36. }
  37. public static void main(String[] arguments)
  38. {
  39. new WebServer();
  40. }
  41. }