-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Spring 체스 - 2단계] 연로그(권시연) 미션 제출합니다. #422
Changes from all commits
1626014
cfbc8b8
e85a315
df55b8a
b67bcef
0767b5c
3798222
3739f01
e15b345
0add4bb
326213f
dabd1cf
5b4db87
cf3a525
9b887de
d81084c
5e21666
1d6024a
64e05f2
981ba51
35e47f3
5c71f71
6bfc2fa
c601e33
6becd9a
cfc7204
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# 웹 체스 | ||
> (e): Exception 처리 | ||
|
||
### 1단계 요구 사항 | ||
- 스프링 애플리케이션으로 체스 실행 | ||
- Spring MVC를 활용 (Spark 대체) | ||
- JdbcTemplate 활용 (기존의 Connection 직접 생성 로직 대체) | ||
- 요청 받기: @Controller / @RestController 활용 | ||
|
||
### 2단계 요구 사항 | ||
- 체스방 생성 | ||
- 제목, 비밀번호 입력받기 | ||
- 생성 시 만들어지는 고유값은 url에 활용 | ||
- 체스방 목록 조회 | ||
- 제목 클릭 시 체스방 참가 | ||
- 삭제 버튼 클릭 시 체스방 삭제 | ||
- 비밀번호 입력받기 | ||
- (e) 진행중인 체스방은 삭제 불가능 | ||
- 동일한 비밀번호라면 삭제 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
CREATE TABLE game | ||
( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
title VARCHAR(30) NOT NULL, | ||
password VARCHAR(30) NOT NULL, | ||
running BOOLEAN NOT NULL DEFAULT true, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE event | ||
( | ||
game_id BIGINT NOT NULL, | ||
type VARCHAR(20) NOT NULL, | ||
game_id BIGINT NOT NULL, | ||
type VARCHAR(20) NOT NULL, | ||
description VARCHAR(20) | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package chess.controller; | ||
|
||
import org.springframework.boot.web.servlet.error.ErrorController; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
public class CustomErrorController implements ErrorController { | ||
|
||
@RequestMapping("/error") | ||
public String handleError() { | ||
return "error"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
package chess.controller; | ||
|
||
import chess.domain.event.MoveEvent; | ||
import chess.domain.event.MoveRoute; | ||
import chess.dto.CreateGameDto; | ||
import chess.dto.CreateGameRequest; | ||
import chess.dto.CreateGameResponse; | ||
import chess.dto.DeleteGameRequest; | ||
import chess.dto.GameDto; | ||
import chess.dto.MoveRouteDto; | ||
import chess.service.ChessService; | ||
import chess.util.ResponseUtil; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
|
@@ -27,8 +31,9 @@ public GameController(ChessService chessService) { | |
} | ||
|
||
@PostMapping("/new") | ||
public CreateGameDto createGame() { | ||
return chessService.initGame(); | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public CreateGameResponse createGame(@RequestBody CreateGameRequest createGameRequest) { | ||
return chessService.initGame(createGameRequest); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
|
@@ -38,10 +43,17 @@ public ModelAndView findGame(@PathVariable int id) { | |
} | ||
|
||
@PostMapping("/{id}") | ||
public ModelAndView playGame(@PathVariable int id, | ||
@RequestBody MoveRoute moveRoute) { | ||
chessService.playGame(id, new MoveEvent(moveRoute)); | ||
public ModelAndView playGame(@PathVariable int id | ||
, @RequestBody MoveRouteDto moveRoute) { | ||
chessService.playGame(id, moveRoute); | ||
GameDto gameDto = chessService.findGame(id); | ||
return ResponseUtil.createModelAndView(HTML_TEMPLATE_PATH, gameDto); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
@ResponseStatus(HttpStatus.NON_AUTHORITATIVE_INFORMATION) | ||
public void delete(@PathVariable int id | ||
,@RequestBody DeleteGameRequest deleteGameRequest) { | ||
Comment on lines
+46
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존 내용이 컨벤션처럼 보이는데 컨벤션이 바뀌었을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 아니요ㅠㅠ 값을 수정하다 미처 확인을 못한 것 같습니다😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아하..! 그럴 수 있져 ㅎ_ㅎ.. |
||
chessService.deleteGame(id, deleteGameRequest); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package chess.dao; | ||
|
||
import chess.domain.event.Event; | ||
import chess.entity.EventEntity; | ||
import java.util.List; | ||
import org.springframework.jdbc.core.RowMapper; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
|
@@ -17,17 +17,17 @@ public EventDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { | |
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; | ||
} | ||
|
||
private final RowMapper<Event> eventRowMapper = (resultSet, rowNum) -> | ||
Event.of(resultSet.getString("type"), | ||
private final RowMapper<EventEntity> eventRowMapper = (resultSet, rowNum) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테이블과 일대일 매핑되는 entity라는 클래스를 별도로 분리했습니다! |
||
new EventEntity(resultSet.getString("type"), | ||
resultSet.getString("description")); | ||
|
||
public List<Event> findAllByGameId(int gameId) { | ||
public List<EventEntity> findAllByGameId(int gameId) { | ||
final String sql = "SELECT type, description FROM event WHERE game_id = :game_id"; | ||
SqlParameterSource paramSource = new MapSqlParameterSource("game_id", gameId); | ||
return namedParameterJdbcTemplate.query(sql, paramSource, eventRowMapper); | ||
} | ||
|
||
public void save(int gameId, Event event) { | ||
public void save(int gameId, EventEntity event) { | ||
final String sql = "INSERT INTO event (game_id, type, description)" | ||
+ "VALUES (:game_id, :type, :description)"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package chess.domain.game; | ||
|
||
import chess.domain.board.Board; | ||
import chess.domain.event.Event; | ||
import chess.domain.game.statistics.GameResult; | ||
import chess.dto.GameDto; | ||
import chess.domain.game.statistics.GameState; | ||
|
||
public interface Game { | ||
|
||
|
@@ -12,5 +13,7 @@ public interface Game { | |
|
||
GameResult getResult(); | ||
|
||
GameDto toDtoOf(int gameId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 도메인에서 dto를 생성한다 = dto 가 수정되면 도메인을 수정해야한다 라고 생각해서 약간의 로직을 바꿨습니다! |
||
Board getBoard(); | ||
|
||
GameState getState(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
인스턴스 생성 or Builder 둘 중 하나로 통일하는 건 어떨까요?