Browse Source

add createGame to ServerApp

feat-serverGameRepresentation
Steffen Nitschke 4 years ago
parent
commit
b48d704edf
  1. 13
      fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java
  2. 12
      fh.fd.ci.server/src/main/java/de/fd/fh/server/game/web/GameController.java

13
fh.fd.ci.server/src/main/java/de/fd/fh/ServerApp.java

@ -4,6 +4,9 @@ import de.fd.fh.server.access.AccessContextEventListener;
import de.fd.fh.server.access.AccessRepository;
import de.fd.fh.server.access.AccessService;
import de.fd.fh.server.access.web.AccessController;
import de.fd.fh.server.game.GameRepository;
import de.fd.fh.server.game.GameService;
import de.fd.fh.server.game.web.GameController;
import de.fd.fh.server.user.UserContextEventListener;
import de.fd.fh.server.user.web.UserController;
import de.fd.fh.server.user.UserRepository;
@ -21,9 +24,11 @@ public class ServerApp
{
private static AccessRepository accessRepository;
private static UserRepository userRepository;
private static GameRepository gameRepository;
private static AccessController accessController;
private static UserController userController;
private static GameController gameController;
private static final Set<Observer> listeners = new HashSet<>();
@ -38,6 +43,7 @@ public class ServerApp
addListeners(new AccessService(accessRepository)));
userController = new UserController((UserService)
addListeners(new UserService(userRepository)));
gameController = new GameController(new GameService(gameRepository));
}
before("/*", (req, res) -> accessController.before(req));
@ -50,17 +56,21 @@ public class ServerApp
get("/users", userController::getCompleteUser);
get("/users/:user_id", userController::getUser);
post("/games", gameController::createGame);
get("/hello", (req, res) -> "Hello World");
}
public static void initController(
final AccessController accessController,
final UserController userController
final UserController userController,
final GameController gameController
)
{
ServerApp.userController = userController;
ServerApp.accessController = accessController;
ServerApp.gameController = gameController;
}
private static Object addListeners(Observable service)
@ -80,5 +90,6 @@ public class ServerApp
{
accessRepository = new AccessRepository();
userRepository = new UserRepository();
gameRepository = new GameRepository();
}
}

12
fh.fd.ci.server/src/main/java/de/fd/fh/server/game/web/GameController.java

@ -21,7 +21,7 @@ public class GameController
private final GameService service;
public void createGame(final Request request, final Response response) throws IOException
public Response createGame(final Request request, final Response response) throws IOException
{
final CreateGameRequest createRequest = objectMapper.readValue(request.body(), CreateGameRequest.class);
@ -39,9 +39,11 @@ public class GameController
response.body(objectMapper.writeValueAsString(gameId));
response.status(201);
}
return response;
}
public void findGameById(final Request request, final Response response) throws JsonProcessingException
public Response findGameById(final Request request, final Response response) throws JsonProcessingException
{
final GameId gameId = GameId.of(request.params(":game_id"));
@ -56,9 +58,11 @@ public class GameController
response.body(objectMapper.writeValueAsString(game));
response.status(200);
}
return response;
}
public void findRunningGamesOfUser(final Request request, final Response response) throws JsonProcessingException
public Response findRunningGamesOfUser(final Request request, final Response response) throws JsonProcessingException
{
final UserId userId = UserId.of(request.params(":user_id"));
@ -73,5 +77,7 @@ public class GameController
response.body(objectMapper.writeValueAsString(games));
response.status(200);
}
return response;
}
}
Loading…
Cancel
Save