Skip to content

Commit

Permalink
[빙봉] 체스 스프링 실습 2단계 제출합니다. (#91)
Browse files Browse the repository at this point in the history
* [디디] 체스 스프링 실습 1단계 제출합니다. (#12)

* initial commit

* fix : build.gradle mysql 의존성 추가

* refactor : 왕이 죽었을 때 게임이 종료 안되는 버그 수정

* refactor : 버튼으로 방에 입장할 수 있도록 함

* refactor : 방을 삭제하고 나서 새로고침해야 적용되던 문제 수정

* feat : 방에 입장하자마자 게임을 바로 불러오도록 하고 못 불러왔을 시 게임을 초기화하는 기능 추가, refactor : 불러왔을 때 현재 Turn이 나오지 않는 문제 수정

* refactor, style : tab 공백을 space로 변경, 익명 객체 람다식으로 수정

* feat : Spring room Controller 구현
- 방 제목 empty 에 대한 validation 추가
- default 요청시 바로 방 목록을 불러오도록 수정

* feat, refactor : Dto 생성 방식 수정, 게임 컨트롤러 구현

- 게임 초기화 기능 구현

Co-authored-by: aegis <[email protected]>

* [디디] 체스 - 스프링 실습 2단계 제출합니다. (#73)

* refactor : 사용하지 않는 클래스 삭제

* refactor : 디폴트 생성자 접근제어자 수정

* refactor : 디폴트 생성자 접근제어자 수정

* refactor : 디폴트 생성자 접근제어자 수정

* refactor : Object 객체 타입 파라미터 반영하도록 수정

* refactor : 필드간 공백 추가

* refactor : 사용하지 않는 메서드 삭제

* refactor : 필드 접근제어자 추가

* style : 공백 추가

* feat : gameController init, movablePosition 구현

- todo : move시 에러

* feat : move 예외 처리 작업중

* refactor : spring MVC 구조에 맞게 refactor

- GameController 예외 알맞게 처리
- DAO 클래스 Repository로 설정
- Service의 DAO를 bean으로 주입

* docs : README.md 추가

* test : domain test 메서드 추가

* refactor : 사용하지 않은 메서드 삭제 및 공백 수정

* refactor, fix : Spark Application과 Spring Application 이 모두 동작하도록 수정, 점수가 제대로 나오지 않는 버그 수정

* style : 공백 삭제

* refactor : move 메서드가 Post방식의 Json으로 요청을 받도록 수정

- front의 request uri 수정
- MoveManagerDTO 클래스로 request 매핑

* refactor : 불필요한 attribute 삭제

* refactor : move 메서드 리턴 타입 수정, 클래스명 수정

* refactor : 서비스 메서드 불필요한 동작 수정

Co-authored-by: aegis <[email protected]>

Co-authored-by: DD <[email protected]>
  • Loading branch information
aegis1920 and fucct authored Apr 27, 2020
1 parent 69f6b54 commit 5002980
Show file tree
Hide file tree
Showing 43 changed files with 1,681 additions and 727 deletions.
41 changes: 20 additions & 21 deletions src/main/java/wooteco/chess/SparkChessApplication.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
package wooteco.chess;

import wooteco.chess.controller.SparkGameController;
import wooteco.chess.controller.SparkRoomController;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import wooteco.chess.sparkcontroller.SparkGameController;
import wooteco.chess.sparkcontroller.SparkRoomController;

import static spark.Spark.*;
import static spark.Spark.exception;

public class SparkChessApplication {
public static void main(String[] args) {
port(4567);
staticFiles.location("/static");
externalStaticFileLocation("src/main/resources/templates");

// get(SparkRoomController.BASIC_URL, SparkRoomController.getAllRoom);
// get(SparkRoomController.CREATE_ROOM_URL, SparkRoomController.createRoom);
// get(SparkRoomController.REMOVE_ROOM_URL, SparkRoomController.removeRoom);
// get(SparkRoomController.ENTER_ROOM_URL, SparkRoomController.enterRoom);
//
// get(SparkGameController.INIT_URL, SparkGameController::initGame);
// post(SparkGameController.MOVE_URL, SparkGameController::movePiece);
// get(SparkGameController.STATUS_URL, SparkGameController::showStatus);
// get(SparkGameController.LOAD_URL, SparkGameController::loadGame);
// get(SparkGameController.GET_URL, SparkGameController::getMovablePositions);
//
// exception(IllegalArgumentException.class, (e, req, res) -> {
// Gson gson = new Gson();
// JsonObject object = new JsonObject();
//
// object.addProperty("errorMessage", e.getMessage());
// res.body(gson.toJson(object));
// });
get(SparkRoomController.BASIC_URL, SparkRoomController.getAllRoom);
get(SparkRoomController.CREATE_ROOM_URL, SparkRoomController.createRoom);
get(SparkRoomController.REMOVE_ROOM_URL, SparkRoomController.removeRoom);
get(SparkRoomController.ENTER_ROOM_URL, SparkRoomController.enterRoom);

get(SparkGameController.INIT_URL, SparkGameController::initGame);
post(SparkGameController.MOVE_URL, SparkGameController::movePiece);
get(SparkGameController.STATUS_URL, SparkGameController::showStatus);
get(SparkGameController.LOAD_URL, SparkGameController::loadGame);
get(SparkGameController.GET_URL, SparkGameController::getMovablePositions);

exception(IllegalArgumentException.class, (e, req, res) -> {
Gson gson = new Gson();
JsonObject object = new JsonObject();

object.addProperty("errorMessage", e.getMessage());
res.body(gson.toJson(object));
});
}
}
7 changes: 3 additions & 4 deletions src/main/java/wooteco/chess/SpringChessApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@SpringBootApplication
public class SpringChessApplication {

public static void main(String[] args) {
SpringApplication.run(SpringChessApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(SpringChessApplication.class, args);
}
}
97 changes: 0 additions & 97 deletions src/main/java/wooteco/chess/controller/SparkGameController.java

This file was deleted.

55 changes: 0 additions & 55 deletions src/main/java/wooteco/chess/controller/SparkRoomController.java

This file was deleted.

58 changes: 21 additions & 37 deletions src/main/java/wooteco/chess/controller/SpringGameController.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
package wooteco.chess.controller;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import spark.Request;
import spark.Response;
import wooteco.chess.domain.Color;
import wooteco.chess.domain.GameManager;
import wooteco.chess.dto.GameManagerDTO;
import wooteco.chess.dto.MovablePositionDTO;
import wooteco.chess.dto.MovePositionDTO;
import wooteco.chess.service.GameService;
import wooteco.chess.dto.MoveResponseDTO;
import wooteco.chess.dto.GameStatusDTO;
import wooteco.chess.dto.MoveRequestDTO;
import wooteco.chess.service.SpringGameService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/game")
public class SpringGameController {

@Autowired
private GameService gameService;
private final SpringGameService gameService;

public SpringGameController(final SpringGameService gameService) {
this.gameService = gameService;
}

@GetMapping("/init")
public GameManagerDTO init(@RequestParam(value = "roomId") Integer roomId) throws SQLException {
public MoveResponseDTO init(@RequestParam Integer roomId) throws SQLException {
return gameService.initialize(roomId);
}

@PostMapping("/move")
public GameManagerDTO move(HttpServletRequest request) throws SQLException {
int roomId = Integer.parseInt(request.getParameter("roomId"));
String sourcePosition = request.getParameter("sourcePosition");
String targetPosition = request.getParameter("targetPosition");

GameManagerDTO gameManagerDTO = gameService.createDTO(roomId);
public ResponseEntity<MoveResponseDTO> move(@RequestBody MoveRequestDTO requestDTO) throws SQLException {
try {
gameService.movePiece(roomId, sourcePosition, targetPosition);
return gameService.createDTO(roomId);
return ResponseEntity.status(HttpStatus.OK).body(gameService.move(requestDTO));
} catch (IllegalArgumentException e) {
gameManagerDTO.setErrorMessage(e.getMessage());
return gameManagerDTO;
MoveResponseDTO moveResponseDTO = gameService.createMoveResponseDTO(requestDTO.getRoomId());
moveResponseDTO.setErrorMessage(e.getMessage());
return ResponseEntity.status(HttpStatus.OK).body(moveResponseDTO);
}
}

@GetMapping("/status")
public Model showStatus(@RequestParam Integer roomId, Model model) throws SQLException {
double whiteScore = gameService.getScore(roomId, Color.WHITE);
double blackScore = gameService.getScore(roomId, Color.BLACK);

model.addAttribute("whiteScore", whiteScore);
model.addAttribute("blackScore", blackScore);

return model;
public GameStatusDTO showStatus(@RequestParam Integer roomId) throws SQLException {
return new GameStatusDTO(gameService.getScore(roomId, Color.WHITE), gameService.getScore(roomId, Color.BLACK));
}

@GetMapping("/load")
public GameManagerDTO load(@RequestParam Integer roomId) throws SQLException {
return gameService.createDTO(roomId);
public MoveResponseDTO load(@RequestParam Integer roomId) throws SQLException {
return gameService.createMoveResponseDTO(roomId);
}

@GetMapping("/get")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package wooteco.chess.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import wooteco.chess.domain.room.Room;
import wooteco.chess.service.RoomService;
import wooteco.chess.dto.RoomName;
import wooteco.chess.service.SpringRoomService;

import javax.validation.Valid;
import java.sql.SQLException;
Expand All @@ -18,9 +18,9 @@
@RequestMapping("/rooms")
public class SpringRoomController {

private final RoomService roomService;
private final SpringRoomService roomService;

private SpringRoomController(final RoomService roomService) {
private SpringRoomController(final SpringRoomService roomService) {
this.roomService = roomService;
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/wooteco/chess/dao/GameDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import wooteco.chess.domain.piece.PieceMapper;
import wooteco.chess.domain.piece.Pieces;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/wooteco/chess/dao/RoomDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import wooteco.chess.domain.Color;
import wooteco.chess.domain.room.Room;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand Down
Loading

0 comments on commit 5002980

Please sign in to comment.