Skip to content

Commit

Permalink
[무늬] 체스 스프링 3단계 미션 제출합니다. (#143)
Browse files Browse the repository at this point in the history
* [스티치] 체스 스프링 실습 1단계 미션 제출입니다 (#37)

* feat : 기존 Chess 코드 추가

* refactor : 기존 Chess 코드의 Application과 Controller 명명 수정

* refactor : JdbcTemplate 명명 수정 및 Spring Bean 등록

- 기존 JdbcTemplate 라이브러리와 충돌로 인한 명명 수정
- Dao, Service, ConnectionManager를 Spring Bean 등록

* feat : SpringChessController 추가

* feat : SpringChessController 구현

* refactor : controller 피드백 리팩토링

* refactor : database package 리팩토링

- ConnectionManager를 DataSource로 명명 수정.
- CustomJdbcTemplate을 JdbcTemplate으로 명명 수정, 별칭 지정.
- MySqlConnectionManager를 MySqlDataSource로 명명 수정, 별칭 지정.

* refactor : 접근 지정자 수정 및 상수 추출

* refactor : BlackPawnStrategy와 WhitePawnStrategy를 PawnStrategy로 추상화

* [스티치] 체스 스프링 실습 2단계 미션 제출입니다 (#87)

* feat : Spring Data JDBC 적용

- Spring Data JDBC 적용을 위한 GameRoomRepository 구현
- schema.sql 구현

* feat : GameHistory, GameRoom Entity 구현

* refactor : Spring Application에 불필요한 클래스 및 테스트 삭제

* refactor : 불필요한 util 패키지 및 클래스 삭제, GameHistory 클래스 내 CreatedTime 필드 삭제

Co-authored-by: Junyoung Lee <[email protected]>
  • Loading branch information
JinJuMoon and lxxjn0 authored May 4, 2020
1 parent 3db28a9 commit 94c1e84
Show file tree
Hide file tree
Showing 41 changed files with 314 additions and 1,625 deletions.
37 changes: 0 additions & 37 deletions src/main/java/wooteco/chess/ConsoleChessApplication.java

This file was deleted.

36 changes: 0 additions & 36 deletions src/main/java/wooteco/chess/SparkChessApplication.java

This file was deleted.

67 changes: 0 additions & 67 deletions src/main/java/wooteco/chess/controller/ChessController.java

This file was deleted.

86 changes: 0 additions & 86 deletions src/main/java/wooteco/chess/controller/SparkChessController.java

This file was deleted.

52 changes: 35 additions & 17 deletions src/main/java/wooteco/chess/controller/SpringChessController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import wooteco.chess.service.ChessService;
import wooteco.chess.service.dto.ChessBoardDto;
import wooteco.chess.service.dto.ChessGameDto;
import wooteco.chess.service.dto.ChessStatusDtos;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

@Controller
public class SpringChessController {

Expand All @@ -21,36 +24,52 @@ public SpringChessController(final ChessService chessService) {
}

@GetMapping("/")
public String start() {
public String index(Model model) {
model.addAttribute("gameNames", chessService.showAllGames());
return "index";
}

@GetMapping("/chess")
public String loadChessGame(final Model model) {
final ChessGameDto chessGameDto = chessService.loadChessGame();
@PostMapping("/game/new")
public String createGame(@RequestParam("name") final String name, final Model model, HttpServletResponse response) {
ChessGameDto chessGameDto = chessService.createChessGame(name);
Cookie cookie = new Cookie("gameId", String.valueOf(chessGameDto.getId()));

cookie.setPath("/");
response.addCookie(cookie);
return renderGame(chessGameDto, model);
}

@PostMapping("/chess_play")
public String playChessGame(@RequestParam final String sourcePosition, @RequestParam final String targetPosition,
final Model model) {
final ChessGameDto chessGameDto = chessService.playChessGame(sourcePosition.trim(), targetPosition.trim());
@PostMapping("/game")
public String showGame(@RequestParam("name") final String name, final Model model, HttpServletResponse response) {
ChessGameDto chessGameDto = chessService.loadChessGameByName(name);
Long gameId = chessGameDto.getId();

if (chessGameDto.isEndState()) {
if (chessService.isEndGame(gameId)) {
return renderResult(chessGameDto, model);
}

Cookie cookie = new Cookie("gameId", String.valueOf(gameId));
cookie.setPath("/");
response.addCookie(cookie);
return renderGame(chessGameDto, model);
}

@PostMapping("/chess_new")
public String newChessGame(final Model model) {
return renderGame(chessService.createChessGame(), model);
@PostMapping("/game/play")
public String playChessGame(@CookieValue("gameId") Cookie gameIdCookie, @RequestParam final String sourcePosition,
@RequestParam final String targetPosition, final Model model) {
final Long gameId = Long.parseLong(gameIdCookie.getValue());
final ChessGameDto chessGameDto = chessService.playChessGame(gameId, sourcePosition.trim(),
targetPosition.trim());

if (chessGameDto.isEndState()) {
return renderResult(chessGameDto, model);
}
return renderGame(chessGameDto, model);
}

@PostMapping("/chess_end")
public String endChessGame(final Model model) {
final ChessGameDto chessGameDto = chessService.endChessGame();
@PostMapping("/game/end")
public String endChessGame(@CookieValue("gameId") Long gameId, final Model model) {
final ChessGameDto chessGameDto = chessService.endChessGame(gameId);
return renderResult(chessGameDto, model);
}

Expand All @@ -74,5 +93,4 @@ private String renderResult(final ChessGameDto chessGameDto, final Model model)
model.addAttribute("status", chessStatusDtos.getChessStatusDtos());
return "result";
}

}
15 changes: 0 additions & 15 deletions src/main/java/wooteco/chess/dao/ChessGameDao.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/wooteco/chess/dao/ChessHistoryDao.java

This file was deleted.

Loading

0 comments on commit 94c1e84

Please sign in to comment.