-
Notifications
You must be signed in to change notification settings - Fork 177
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
[동글] 스프링 실습 2단계 미션 제출합니다. #89
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
11b74ef
feat : spring 컨트롤러 작성
mintjordy 3fbcefc
feat : spring 컨트롤러 작성 완료
mintjordy 532326a
refactor : 기존 예외처리 로직 controller에서 service로 이동, 알트 피드백 반영
mintjordy 022da49
fix : 충돌 해결
mintjordy e03422d
style : 자바 컨벤션에 맞도록 코드 수정
mintjordy 0255bd1
fix : 병합 충돌 해결
mintjordy 06f5795
refactor : chess controller view, rest controller 로 분리
mintjordy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/wooteco/chess/controller/SpringChessRestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package wooteco.chess.controller; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
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.RestController; | ||
|
||
import wooteco.chess.service.GameService; | ||
import wooteco.chess.view.dto.requestdto.PositionRequestDto; | ||
import wooteco.chess.view.response.ResponseDto; | ||
|
||
@RestController | ||
@RequestMapping("/chess") | ||
public class SpringChessRestController { | ||
private final GameService gameService; | ||
|
||
public SpringChessRestController(GameService gameService) { | ||
this.gameService = gameService; | ||
} | ||
|
||
@GetMapping("/state") | ||
public ResponseDto findCurrentState() { | ||
return gameService.getCurrentState(); | ||
} | ||
|
||
@PostMapping("/state") | ||
public ResponseDto changeState(@RequestBody String request) { | ||
return gameService.changeState(request); | ||
} | ||
|
||
@GetMapping("/pieces") | ||
public ResponseDto findAllPiecesOnBoard() { | ||
return gameService.findAllPiecesOnBoard(); | ||
} | ||
|
||
@GetMapping("/record") | ||
public ResponseDto calculateScore() { | ||
return gameService.calculateScore(); | ||
} | ||
|
||
@PostMapping("/move") | ||
public ResponseDto move(@RequestBody PositionRequestDto requestDTO) { | ||
return gameService.move(requestDTO); | ||
} | ||
|
||
@GetMapping("/isnotfinish") | ||
public ResponseDto isNotFinish() { | ||
return gameService.isNotFinish(); | ||
} | ||
|
||
@GetMapping("/result") | ||
public ResponseDto findWinner() { | ||
return gameService.getWinner(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,34 +3,33 @@ | |
import static wooteco.chess.domain.piece.Team.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.function.Supplier; | ||
|
||
public enum PieceFactory { | ||
BLACK_PAWN("P", () -> new Pawn(BLACK)), | ||
BLACK_BISHOP("B", () -> new Bishop(BLACK)), | ||
BLACK_KNIGHT("N", () -> new Knight(BLACK)), | ||
BLACK_ROOK("R", () -> new Rook(BLACK)), | ||
BLACK_QUEEN("Q", () -> new Queen(BLACK)), | ||
BLACK_KING("K", () -> new King(BLACK)), | ||
WHITE_PAWN("p", () -> new Pawn(WHITE)), | ||
WHITE_BISHOP("b", () -> new Bishop(WHITE)), | ||
WHITE_KNIGHT("n", () -> new Knight(WHITE)), | ||
WHITE_ROOK("r", () -> new Rook(WHITE)), | ||
WHITE_QUEEN("q", () -> new Queen(WHITE)), | ||
WHITE_KING("k", () -> new King(WHITE)); | ||
BLACK_PAWN("P", new Pawn(BLACK)), | ||
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. 피드백 반영 💯💯 |
||
BLACK_BISHOP("B", new Bishop(BLACK)), | ||
BLACK_KNIGHT("N", new Knight(BLACK)), | ||
BLACK_ROOK("R", new Rook(BLACK)), | ||
BLACK_QUEEN("Q", new Queen(BLACK)), | ||
BLACK_KING("K", new King(BLACK)), | ||
WHITE_PAWN("p", new Pawn(WHITE)), | ||
WHITE_BISHOP("b", new Bishop(WHITE)), | ||
WHITE_KNIGHT("n", new Knight(WHITE)), | ||
WHITE_ROOK("r", new Rook(WHITE)), | ||
WHITE_QUEEN("q", new Queen(WHITE)), | ||
WHITE_KING("k", new King(WHITE)); | ||
|
||
private final String symbol; | ||
private final Supplier<Piece> pieceSupplier; | ||
private final Piece piece; | ||
|
||
PieceFactory(String symbol, Supplier<Piece> pieceSupplier) { | ||
PieceFactory(String symbol, Piece piece) { | ||
this.symbol = symbol; | ||
this.pieceSupplier = pieceSupplier; | ||
this.piece = piece; | ||
} | ||
|
||
public static Piece of(String symbol) { | ||
return Arrays.stream(values()) | ||
.filter(val -> val.symbol.equals(symbol)) | ||
.map(val -> val.pieceSupplier.get()) | ||
.map(val -> val.piece) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("유효한 심볼이 아닙니다. : " + symbol)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
페이지를 render하는 컨트롤러와 API 호출 컨트롤러를 분리해 보는 것은 어떨까요?
/chess
와 관련된 API를 분리한다면 해당 클래스 헤더에@RequestMapping('/chess')
어노테이션으로 중복되는 URL명을 줄일 수 있을 것 같아요😀