Skip to content
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단계] 써머(최혜원) 미션 제출합니다. #474

Merged
merged 56 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
1d6f834
feat: 기존 체스 코드 가져오기
hyewoncc Apr 19, 2022
cc90334
refactor: 체스 코드 합치기
hyewoncc Apr 20, 2022
42f1646
feat: 체스방 입장
hyewoncc Apr 20, 2022
4259ef2
fix: 테스트 수정
hyewoncc Apr 20, 2022
4e6b15d
refactor: player 개념을 room으로 변경
hyewoncc Apr 21, 2022
fcea9ef
feat: 유효하지 않은 이름에 대해 400 에러 처리
hyewoncc Apr 21, 2022
ec2b80e
feat: 더블 레포지토리를 이용한 db 의존하지 않는 테스트 설정 작성
hyewoncc Apr 21, 2022
8a0d883
feat: 게임 불러오기
hyewoncc Apr 22, 2022
71cc5b4
feat: /move 요청 처리
hyewoncc Apr 22, 2022
01dbf9a
feat: /result 요청 처리
hyewoncc Apr 22, 2022
719ba9d
fix: 이미지 이름 수정
hyewoncc Apr 22, 2022
ee08639
feat: /end 요청 처리
hyewoncc Apr 22, 2022
3191d0f
refactor: 응답 데이터를 dto 객체로 래핑
hyewoncc Apr 22, 2022
f1f1ca1
refactor: roomId를 query parameter가 아닌 path variable로 전달
hyewoncc Apr 22, 2022
76a58a8
feat: roomRepositoryImpl에 Spring jdbc 적용 구현
hyewoncc Apr 22, 2022
5fdbb93
fix: 테스트 깨짐 수정
hyewoncc Apr 22, 2022
014f35b
refactor: 상수 처리
hyewoncc Apr 22, 2022
e3b168e
feat: BoardRepositoryImpl에 Spring jdbc 적용 구현
hyewoncc Apr 22, 2022
9c041c4
refactor: PieceRepository를 jdbc 적용으로 교체
hyewoncc Apr 23, 2022
327cb50
refactor: 패키지 변경, 스파크 애플리케이션과 dao 삭제
hyewoncc Apr 23, 2022
197fbd4
refactor: 컨트롤러 분리
hyewoncc Apr 23, 2022
4504416
fix: url 변경으로 인한 테스트 깨짐 수정
hyewoncc Apr 23, 2022
62711d1
feat: 프론트 개선
hyewoncc Apr 24, 2022
1a8d616
fix: 테스트에서 value source를 사용하지 않던 문제
hyewoncc Apr 27, 2022
a5f7460
fix: merge 충돌 해결
hyewoncc Apr 27, 2022
cc78b06
docs: 2단계 요구사항 정리
hyewoncc Apr 27, 2022
88e1c8c
feat: 이름과 비밀번호를 입력해 체스방 생성
hyewoncc Apr 27, 2022
6246c51
feat: 목록에서 체스방 보여주고 클릭 시 입장
hyewoncc Apr 28, 2022
6bb0f2e
feat: 프론트 모달 창 닫기 추가
hyewoncc Apr 28, 2022
d6285d3
feat: 비밀번호 일치 시 방 삭제, 불일치시 거부
hyewoncc Apr 28, 2022
09d3267
feat: 진행중인 게임은 삭제 하지 않음
hyewoncc Apr 28, 2022
1fecb75
refactor: 게임 종료 여부 필드를 String -> boolean 변경
hyewoncc Apr 28, 2022
e6e1321
feat: 보드 테이블에 종료 여부를 판별하는 end 컬럼 추가
hyewoncc Apr 29, 2022
2a7478a
refactor: 콘솔 코드 삭제
hyewoncc Apr 29, 2022
3a56ed9
refactor: 말 이동 요청을 POST -> PATCH 변경
hyewoncc Apr 29, 2022
6d4b739
refactor: 어노테이션 변경 ControllerAdvice -> RestControllerAdvice
hyewoncc Apr 29, 2022
340b480
fix: 메서드 시그니쳐 변경으로 인해 깨진 테스트 정정
hyewoncc Apr 29, 2022
48ba8bc
feat: 체스말 이동 시 점수 바로 갱신
hyewoncc Apr 29, 2022
0938c76
refactor: api url 디자인 개선
hyewoncc Apr 29, 2022
914479b
refactor: board 찾는 api url 수정
hyewoncc Apr 29, 2022
ca1d935
refactor: 기존 repository -> dao 변경, dao를 통해 컬렉션 처리하는 repository 작성
hyewoncc Apr 29, 2022
0d14217
feat: 프론트 css 수정
hyewoncc Apr 30, 2022
b3b75a9
refactor: interface 삭제
hyewoncc Apr 30, 2022
b31b4a2
refactor: 패키지 변경
hyewoncc May 2, 2022
aa83a5a
refactor: GameRepository 에서 바로 Board를 조회
hyewoncc May 2, 2022
07ccfb4
refactor: 컨트롤러에서 Map 대신 Dto 반환
hyewoncc May 2, 2022
b32899d
refactor: 새 게임 저장 시 기존 게임 삭제 책임을 service에서 repository로 이동
hyewoncc May 2, 2022
5064437
refactor: 체스 말 이동 DB 제어 로직을 service -> repository 이동
hyewoncc May 2, 2022
71071e6
refactor: Board 생성자에 turn 추가
hyewoncc May 2, 2022
578ef74
refactor: 새로운 게임 생성 매핑 메서드 변경 get -> post
hyewoncc May 2, 2022
d3d0d3a
refactor: 방 비밀번호 검증을 get 없이 Room 도메인이 실행
hyewoncc May 2, 2022
c4561c4
refactor: 프론트에서 새로운 게임 생성 요청 method 변경 get -> post
hyewoncc May 2, 2022
5e79bf6
refactor: room 관련 db 로직을 Room 객체 이용하도록 개선, 메서드 명 개선
hyewoncc May 3, 2022
b5127af
fix: 컨트롤러 테스트에서 dao를 사용해 예상값 처리
hyewoncc May 3, 2022
5a0c5da
refactor: 인스턴스 필드를 private 지정
hyewoncc May 3, 2022
204c760
refactor: 메서드 순서 변경
hyewoncc May 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 웹 체스

### step2 요구 기능 목록

- [x] 체스방 만들기 버튼을 누르면 제목과 비밀번호를 입력할 수 있는 팝업이 뜬다
- [x] 제목과 비밀번호를 입력하면 새로운 체스판이 만들어진다
- [x] 메인 페이지에서 체스방 목록을 볼 수 있다
- [x] 목록에서 체스방을 클릭하면 방에 입장한다
- [x] 삭제 버튼을 누르면 비밀번호 입력 팝업이 뜬다
- [x] 비밀번호가 일치하면 방이 삭제된다
- [x] 비밀번호가 불일치하면 방이 삭제되지 않는다
- [x] 게임이 진행중인 상황이면 방이 삭제되지 않는다

20 changes: 11 additions & 9 deletions docker/db/mysql/init/init.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
create table room
(
id int not null auto_increment primary key,
name varchar(16) not null
id int not null auto_increment primary key,
name varchar(16) not null,
password varchar(16) not null
);

create table board
(
id int not null auto_increment primary key,
room_id int not null,
turn varchar(5) not null,
foreign key (room_id) references room(id)
id int not null auto_increment primary key,
room_id int not null,
turn varchar(5) not null,
end tinyint(1) not null,
foreign key (room_id) references room (id) on delete cascade
);

create table piece
(
id int not null auto_increment primary key,
board_id int not null,
id int not null auto_increment primary key,
board_id int not null,
position varchar(2) not null,
color varchar(5) not null,
role varchar(1) not null,
foreign key (board_id) references board(id) on delete cascade
foreign key (board_id) references board (id) on delete cascade
);
8 changes: 0 additions & 8 deletions src/main/java/chess/console/ConsoleApplication.java

This file was deleted.

71 changes: 0 additions & 71 deletions src/main/java/chess/console/GameMachine.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/chess/console/view/InputView.java

This file was deleted.

84 changes: 0 additions & 84 deletions src/main/java/chess/console/view/OutputView.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package chess.web;
package chess.controller;

import chess.dto.BoardDto;
import chess.dto.CommendDto;
import chess.dto.ResultDto;
import chess.service.GameService;
import chess.web.dto.BoardDto;
import chess.web.dto.CommendDto;
import chess.web.dto.ResultDto;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
@RequestMapping("/boards")
public class BoardController {

Expand All @@ -22,18 +23,23 @@ public BoardController(GameService gameService) {
this.gameService = gameService;
}

@PostMapping(value = "/{boardId}", params = "command=move")
@GetMapping
public ResponseEntity<BoardDto> findBoard(@RequestParam int roomId) {
return ResponseEntity.ok(gameService.loadGame(roomId));
}

@PatchMapping(value = "/{boardId}")
public ResponseEntity<BoardDto> movePiece(@PathVariable int boardId, @RequestBody CommendDto commendDto) {
gameService.move(boardId, commendDto);
return ResponseEntity.ok(gameService.gameStateAndPieces(boardId));
}

@GetMapping(value = "/{boardId}", params = "command=result")
@GetMapping(value = "/{boardId}/result")
public ResponseEntity<ResultDto> result(@PathVariable int boardId) {
return ResponseEntity.ok(gameService.gameResult(boardId));
}

@GetMapping(value = "/{boardId}", params = "command=end")
@GetMapping(value = "/{boardId}/end")
public ResponseEntity<ResultDto> end(@PathVariable int boardId) {
return ResponseEntity.ok(gameService.gameFinalResult(boardId));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package chess.web;
package chess.controller;

import chess.web.dto.ErrorMessageDto;
import chess.dto.ErrorMessageDto;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@ControllerAdvice
@RestControllerAdvice
public class ExceptionAdviser {

@ExceptionHandler(IllegalArgumentException.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package chess.web;
package chess.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package chess.web;
package chess.controller;

import chess.dto.BoardDto;
import chess.dto.RoomDto;
import chess.dto.RoomResponseDto;
import chess.service.GameService;
import chess.service.RoomService;
import chess.web.dto.BoardDto;
import chess.web.dto.RoomDto;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
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;
Expand All @@ -24,10 +27,14 @@ public RoomController(RoomService roomService, GameService gameService) {
this.gameService = gameService;
}

@GetMapping
public ResponseEntity<List<RoomResponseDto>> findRooms() {
return ResponseEntity.ok(roomService.findRooms());
}

@PostMapping
public String createRoom(@RequestParam String name) {
RoomDto roomDto = roomService.create(name);
return "redirect:/rooms/" + roomDto.getId();
public ResponseEntity<RoomResponseDto> createRoom(RoomDto roomDto) {
return ResponseEntity.ok(roomService.create(roomDto));
}

@GetMapping("/{roomId}")
Expand All @@ -36,13 +43,14 @@ public String board(@PathVariable int roomId) {
return "/board.html";
}

@GetMapping(value = "/{roomId}", params = "command=start")
public ResponseEntity<BoardDto> startNewGame(@PathVariable int roomId) {
return ResponseEntity.ok(gameService.startNewGame(roomId));
@DeleteMapping("/{roomId}")
public ResponseEntity<Void> deleteRoom(@PathVariable int roomId, @RequestParam String password) {
roomService.delete(roomId, password);
return ResponseEntity.noContent().build();
}

@GetMapping(value = "/{roomId}", params = "command=load")
public ResponseEntity<BoardDto> loadGame(@PathVariable int roomId) {
return ResponseEntity.ok(gameService.loadGame(roomId));
@PostMapping(value = "/{roomId}/new")
public ResponseEntity<BoardDto> startNewGame(@PathVariable int roomId) {
return ResponseEntity.ok(gameService.newBoard(roomId));
}
}