Skip to content

Commit

Permalink
[#6] feat: Create requestDTO
Browse files Browse the repository at this point in the history
1. 현재 만든 API 요청을 json body로 읽기위한 request DTO 생성했습니다.
2. GameController에서 json body를 읽도록 수정
  • Loading branch information
isaac56 committed May 7, 2021
1 parent 858a04d commit 0b10fcf
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team9.baseball.DTO.request;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CreateGameDTO {
private int away_team_id;
private int home_team_id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package team9.baseball.DTO.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import team9.baseball.domain.enums.Venue;

import javax.validation.constraints.NotNull;

@Getter
@AllArgsConstructor
public class JoinGameDTO {
private int game_id;

@NotNull
private Venue my_venue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package team9.baseball.DTO.request;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import team9.baseball.domain.enums.PitchResult;

@Getter
@Setter
@NoArgsConstructor
public class PitchResultDTO {
private PitchResult pitch_result;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import team9.baseball.DTO.request.CreateGameDTO;
import team9.baseball.DTO.request.JoinGameDTO;
import team9.baseball.DTO.request.PitchResultDTO;
import team9.baseball.DTO.response.ApiResult;
import team9.baseball.domain.enums.PitchResult;
import team9.baseball.domain.enums.Venue;
import team9.baseball.service.GameService;

import javax.validation.Valid;

@RestController
@RequestMapping("/game")
public class ApiGameController {
Expand All @@ -23,14 +26,14 @@ public ApiResult getGameDescriptions() {
}

@PostMapping
public ApiResult createGame() {
gameService.createNewGame(1l, 1, 2);
public ApiResult createGame(@RequestBody CreateGameDTO createGameDTO) {
gameService.createNewGame(1l, createGameDTO.getAway_team_id(), createGameDTO.getHome_team_id());
return ApiResult.succeed("OK");
}

@PostMapping("/joining")
public ApiResult joinGame() {
gameService.joinGame(1l, 1, Venue.HOME);
public ApiResult joinGame(@Valid @RequestBody JoinGameDTO joinGameDTO) {
gameService.joinGame(1l, joinGameDTO.getGame_id(), joinGameDTO.getMy_venue());
return ApiResult.succeed("OK");
}

Expand All @@ -39,9 +42,9 @@ public ApiResult getCurrentGameStatus() {
return ApiResult.succeed(gameService.getCurrentGameStatus(1l));
}

@PutMapping("/status")
public ApiResult pitch(PitchResult pitchResult) {
gameService.applyPitchResult(1l, pitchResult);
@PostMapping("/status/pitch-result")
public ApiResult pitch(@RequestBody PitchResultDTO pitchResultDTO) {
gameService.applyPitchResult(1l, pitchResultDTO.getPitch_result());
return ApiResult.succeed("OK");
}

Expand Down
4 changes: 3 additions & 1 deletion BE/baseball/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ INSERT INTO player (team_id, name, uniform_number) VALUES (2, '크롱', 3);
INSERT INTO player (team_id, name, uniform_number) VALUES (2, '세라', 4);
INSERT INTO player (team_id, name, uniform_number) VALUES (2, '헤드', 5);

INSERT INTO `user` (email) VALUES ('[email protected]');
INSERT INTO `user` (email) VALUES ('[email protected]');
INSERT INTO `user` (email) VALUES ('[email protected]');
INSERT INTO `user` (email) VALUES ('[email protected]');

0 comments on commit 0b10fcf

Please sign in to comment.