diff --git a/BE/baseball/.gitignore b/BE/baseball/.gitignore new file mode 100644 index 000000000..497d8cb0a --- /dev/null +++ b/BE/baseball/.gitignore @@ -0,0 +1,41 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### log ### +*.log +**/logs/ diff --git a/BE/baseball/build.gradle b/BE/baseball/build.gradle new file mode 100644 index 000000000..6e2fe07ac --- /dev/null +++ b/BE/baseball/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'org.springframework.boot' version '2.4.5' + id 'io.spring.dependency-management' version '1.0.11.RELEASE' + id 'java' +} + +group = 'com.codesquad' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '1.8' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jdbc' + implementation 'org.springframework.boot:spring-boot-starter-web' + runtimeOnly 'mysql:mysql-connector-java' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +test { + useJUnitPlatform() +} diff --git a/BE/baseball/gradle/wrapper/gradle-wrapper.jar b/BE/baseball/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..e708b1c02 Binary files /dev/null and b/BE/baseball/gradle/wrapper/gradle-wrapper.jar differ diff --git a/BE/baseball/gradle/wrapper/gradle-wrapper.properties b/BE/baseball/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..442d9132e --- /dev/null +++ b/BE/baseball/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/BE/baseball/gradlew b/BE/baseball/gradlew new file mode 100755 index 000000000..4f906e0c8 --- /dev/null +++ b/BE/baseball/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/BE/baseball/gradlew.bat b/BE/baseball/gradlew.bat new file mode 100644 index 000000000..ac1b06f93 --- /dev/null +++ b/BE/baseball/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/BE/baseball/settings.gradle b/BE/baseball/settings.gradle new file mode 100644 index 000000000..c1cccd8ee --- /dev/null +++ b/BE/baseball/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'baseball' diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/BaseballApplication.java b/BE/baseball/src/main/java/com/codesquad/baseball/BaseballApplication.java new file mode 100644 index 000000000..0154e41e4 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/BaseballApplication.java @@ -0,0 +1,13 @@ +package com.codesquad.baseball; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class BaseballApplication { + + public static void main(String[] args) { + SpringApplication.run(BaseballApplication.class, args); + } + +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/GameListDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/GameListDTO.java new file mode 100644 index 000000000..5bb9ce2e0 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/GameListDTO.java @@ -0,0 +1,74 @@ +package com.codesquad.baseball.DTO; + +import com.codesquad.baseball.domain.Team; + +public class GameListDTO { + + private Long gameId; + + private String homeTeamName; + + private Long homeTeamId; + + private String awayTeamName; + + private Long awayTeamId; + + public static GameListDTO of(Long gameId, Team homeTeam, Team awayTeam) { + return new GameListDTO( + gameId, + homeTeam.getName(), + homeTeam.getId(), + awayTeam.getName(), + awayTeam.getId() + ); + } + + public GameListDTO(Long gameId, String homeTeamName, Long homeTeamId, String awayTeamName, Long awayTeamId) { + this.gameId = gameId; + this.homeTeamName = homeTeamName; + this.homeTeamId = homeTeamId; + this.awayTeamName = awayTeamName; + this.awayTeamId = awayTeamId; + } + + public Long getGameId() { + return gameId; + } + + public String getHomeTeamName() { + return homeTeamName; + } + + public String getAwayTeamName() { + return awayTeamName; + } + + public Long getHomeTeamId() { + return homeTeamId; + } + + public Long getAwayTeamId() { + return awayTeamId; + } + + public void setGameId(Long gameId) { + this.gameId = gameId; + } + + public void setHomeTeamName(String homeTeamName) { + this.homeTeamName = homeTeamName; + } + + public void setAwayTeamName(String awayTeamName) { + this.awayTeamName = awayTeamName; + } + + public void setHomeTeamId(Long homeTeamId) { + this.homeTeamId = homeTeamId; + } + + public void setAwayTeamId(Long awayTeamId) { + this.awayTeamId = awayTeamId; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/GameStatusDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/GameStatusDTO.java new file mode 100644 index 000000000..a39c63aa0 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/GameStatusDTO.java @@ -0,0 +1,35 @@ +package com.codesquad.baseball.DTO; + +import com.codesquad.baseball.domain.Game; +import com.codesquad.baseball.domain.Team; + +public class GameStatusDTO { + + private Long gameId; + + private boolean homeTeamStatus; + + private boolean awayTeamStatus; + + private GameStatusDTO(Long gameId, boolean homeTeamStatus, boolean awayTeamStatus) { + this.gameId = gameId; + this.homeTeamStatus = homeTeamStatus; + this.awayTeamStatus = awayTeamStatus; + } + + public static GameStatusDTO of(Game game, Team homeTeam, Team awayTeam) { + return new GameStatusDTO(game.getId(), homeTeam.isPlayable(), awayTeam.isPlayable()); + } + + public Long getGameId() { + return gameId; + } + + public boolean isHomeTeamStatus() { + return homeTeamStatus; + } + + public boolean isAwayTeamStatus() { + return awayTeamStatus; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/TeamDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/TeamDTO.java new file mode 100644 index 000000000..2b71435af --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/TeamDTO.java @@ -0,0 +1,50 @@ +package com.codesquad.baseball.DTO; + +import com.codesquad.baseball.DTO.record.PlayerRecordDTO; +import com.codesquad.baseball.domain.Team; + +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class TeamDTO { + + private Long teamId; + + private String teamName; + + private boolean userSelected; + + private List players; + + private TeamDTO(Long id, String name, List players, boolean userSelected) { + this.teamId = id; + this.teamName = name; + this.players = players; + this.userSelected = userSelected; + } + + public static TeamDTO of(Team team) { + List playerRecords = team.getPlayers().stream() + .map(PlayerRecordDTO::of) + .sorted(Comparator.comparing(PlayerRecordDTO::getId)) + .collect(Collectors.toList()); + return new TeamDTO(team.getId(), team.getName(), playerRecords, team.isUserSelected()); + } + + public Long getTeamId() { + return teamId; + } + + public String getTeamName() { + return teamName; + } + + public List getPlayers() { + return players; + } + + public boolean isUserSelected() { + return userSelected; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/PlayerRecordDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/PlayerRecordDTO.java new file mode 100644 index 000000000..b58d17ea2 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/PlayerRecordDTO.java @@ -0,0 +1,96 @@ +package com.codesquad.baseball.DTO.record; + +import com.codesquad.baseball.domain.Player; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class PlayerRecordDTO { + + private static final int AVERAGE_DECIMAL_PLACES = 3; + + private Long id; + + private String name; + + private int plateAppearance; + + private int hit; + + private int out; + + private BigDecimal average; + + private int battingOrder; + + private int backNumber; + + private boolean isPitcher; + + public static PlayerRecordDTO of(Player player) { + BigDecimal average = (player.getPlateAppearance() > 0) ? + BigDecimal.valueOf(player.getHit() / (double) player.getPlateAppearance()) : BigDecimal.ZERO; + average = average.setScale(AVERAGE_DECIMAL_PLACES, RoundingMode.CEILING); + + return new PlayerRecordDTO( + player.getId(), + player.getName(), + player.getPlateAppearance(), + player.getHit(), + player.getOut(), + average, + player.getBattingOrder(), + player.getBackNumber(), + player.isPitcher() + ); + } + + private PlayerRecordDTO(Long id, String name, int plateAppearance, int hit, int out, BigDecimal average, + int battingOrder, int backNumber, boolean isPitcher) { + this.id = id; + this.name = name; + this.plateAppearance = plateAppearance; + this.hit = hit; + this.out = out; + this.average = average; + this.backNumber = backNumber; + this.battingOrder = battingOrder; + this.isPitcher = isPitcher; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public int getPlateAppearance() { + return plateAppearance; + } + + public int getHit() { + return hit; + } + + public int getOut() { + return out; + } + + public BigDecimal getAverage() { + return average; + } + + public int getBattingOrder() { + return battingOrder; + } + + public int getBackNumber() { + return backNumber; + } + + public boolean isPitcher() { + return isPitcher; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/TeamRecordDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/TeamRecordDTO.java new file mode 100644 index 000000000..23cd9ad1e --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/TeamRecordDTO.java @@ -0,0 +1,24 @@ +package com.codesquad.baseball.DTO.record; + +import com.codesquad.baseball.DTO.TeamDTO; +import com.codesquad.baseball.domain.Team; + +public class TeamRecordDTO { + + private TeamDTO awayTeam; + + private TeamDTO homeTeam; + + public TeamRecordDTO(Team awayTeam, Team homeTeam) { + this.awayTeam = TeamDTO.of(awayTeam); + this.homeTeam = TeamDTO.of(homeTeam); + } + + public TeamDTO getAwayTeam() { + return awayTeam; + } + + public TeamDTO getHomeTeam() { + return homeTeam; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/request/PlayerRecordRequest.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/request/PlayerRecordRequest.java new file mode 100644 index 000000000..b3b84515a --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/record/request/PlayerRecordRequest.java @@ -0,0 +1,28 @@ +package com.codesquad.baseball.DTO.record.request; + +public class PlayerRecordRequest { + + private Long playerId; + + private int plateAppearance; + + private int hit; + + private int out; + + public Long getPlayerId() { + return playerId; + } + + public int getPlateAppearance() { + return plateAppearance; + } + + public int getHit() { + return hit; + } + + public int getOut() { + return out; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/score/GameScoreDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/score/GameScoreDTO.java new file mode 100644 index 000000000..7271ed34c --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/score/GameScoreDTO.java @@ -0,0 +1,38 @@ +package com.codesquad.baseball.DTO.score; + +import com.codesquad.baseball.domain.Game; + +public class GameScoreDTO { + + private Long gameId; + + private TeamScoreDTO homeTeam; + + private TeamScoreDTO awayTeam; + + public static GameScoreDTO of(Game game, TeamScoreDTO homeTeam, TeamScoreDTO awayTeam) { + return new GameScoreDTO( + game.getId(), + homeTeam, + awayTeam + ); + } + + private GameScoreDTO(Long gameId, TeamScoreDTO homeTeam, TeamScoreDTO awayTeam) { + this.gameId = gameId; + this.homeTeam = homeTeam; + this.awayTeam = awayTeam; + } + + public Long getGameId() { + return gameId; + } + + public TeamScoreDTO getHomeTeam() { + return homeTeam; + } + + public TeamScoreDTO getAwayTeam() { + return awayTeam; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/DTO/score/TeamScoreDTO.java b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/score/TeamScoreDTO.java new file mode 100644 index 000000000..27ecbb3e2 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/DTO/score/TeamScoreDTO.java @@ -0,0 +1,49 @@ +package com.codesquad.baseball.DTO.score; + +import com.codesquad.baseball.domain.Score; +import com.codesquad.baseball.domain.Team; + +import java.util.List; + +public class TeamScoreDTO { + + private Long teamId; + + private String teamName; + + private boolean userSelected; + + private List scores; + + public static TeamScoreDTO of(Team team) { + return new TeamScoreDTO( + team.getId(), + team.getName(), + team.isUserSelected(), + team.getSortedScores() + ); + } + + public TeamScoreDTO(Long teamId, String teamName, boolean userSelected, List scores) { + this.teamId = teamId; + this.teamName = teamName; + this.userSelected = userSelected; + this.scores = scores; + } + + public Long getTeamId() { + return teamId; + } + + public String getTeamName() { + return teamName; + } + + public boolean isUserSelected() { + return userSelected; + } + + public List getScores() { + return scores; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/controller/GameController.java b/BE/baseball/src/main/java/com/codesquad/baseball/controller/GameController.java new file mode 100644 index 000000000..11abe24d6 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/controller/GameController.java @@ -0,0 +1,39 @@ +package com.codesquad.baseball.controller; + +import com.codesquad.baseball.DTO.GameListDTO; +import com.codesquad.baseball.DTO.record.TeamRecordDTO; +import com.codesquad.baseball.DTO.score.GameScoreDTO; +import com.codesquad.baseball.service.GameService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/baseball") +public class GameController { + + private final GameService gameService; + + public GameController(GameService gameService) { + this.gameService = gameService; + } + + @GetMapping("/games") + public List browseGames() { + return gameService.browseAllGames(); + } + + @GetMapping("/game/{gameId}/players") + public TeamRecordDTO browseTeamPlayers(@PathVariable Long gameId) { + return gameService.browseTeamPlayersByGameId(gameId); + } + + @GetMapping("/game/{gameId}/score") + public GameScoreDTO browseAllScore(@PathVariable Long gameId) { + return gameService.browseGameScoreByGameId(gameId); + } + +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/controller/GlobalExceptionHandler.java b/BE/baseball/src/main/java/com/codesquad/baseball/controller/GlobalExceptionHandler.java new file mode 100644 index 000000000..bc607bb8b --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/controller/GlobalExceptionHandler.java @@ -0,0 +1,24 @@ +package com.codesquad.baseball.controller; + +import com.codesquad.baseball.error.ErrorResponse; +import com.codesquad.baseball.error.exception.NotFoundException; +import com.codesquad.baseball.error.exception.TeamNotPlayableException; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(NotFoundException.class) + public ResponseEntity handleNotFoundException(NotFoundException e) { + ErrorResponse response = ErrorResponse.of(e.getErrorCode()); + return new ResponseEntity<>(response, response.getStatus()); + } + + @ExceptionHandler(TeamNotPlayableException.class) + public ResponseEntity handleTeamNotPlayableException(TeamNotPlayableException e) { + ErrorResponse response = ErrorResponse.of(e.getErrorCode()); + return new ResponseEntity<>(response, response.getStatus()); + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/controller/TeamController.java b/BE/baseball/src/main/java/com/codesquad/baseball/controller/TeamController.java new file mode 100644 index 000000000..a485cd12b --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/controller/TeamController.java @@ -0,0 +1,36 @@ +package com.codesquad.baseball.controller; + +import com.codesquad.baseball.DTO.TeamDTO; +import com.codesquad.baseball.DTO.record.request.PlayerRecordRequest; +import com.codesquad.baseball.domain.Score; +import com.codesquad.baseball.service.TeamService; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/baseball") +public class TeamController { + + private final TeamService teamService; + + public TeamController(TeamService teamService) { + this.teamService = teamService; + } + + @GetMapping("/games/{teamId}") + public TeamDTO browseTeamStatus(@PathVariable Long teamId) { + return teamService.browseTeamStatus(teamId); + } + + @PostMapping("/play/{teamId}/score") + @ResponseStatus(HttpStatus.NO_CONTENT) + public void addScore(@PathVariable Long teamId, @RequestBody Score score) { + teamService.addScore(teamId, score); + } + + @PatchMapping("/play/{teamId}/record") + @ResponseStatus(HttpStatus.NO_CONTENT) + public void updatePlayerRecord(@PathVariable Long teamId, @RequestBody PlayerRecordRequest record) { + teamService.updatePlayerRecord(teamId, record); + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/domain/Game.java b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Game.java new file mode 100644 index 000000000..825b873e8 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Game.java @@ -0,0 +1,38 @@ +package com.codesquad.baseball.domain; + +import org.springframework.data.annotation.Id; + +public class Game { + + @Id + private Long id; + + private Long homeTeamId; + + private Long awayTeamId; + + public Game(Long homeTeamId, Long awayTeamId) { + this.homeTeamId = homeTeamId; + this.awayTeamId = awayTeamId; + } + + public Long getId() { + return id; + } + + public Long getHomeTeamId() { + return homeTeamId; + } + + public Long getAwayTeamId() { + return awayTeamId; + } + + public void setHomeTeamId(Long homeTeamId) { + this.homeTeamId = homeTeamId; + } + + public void setAwayTeamId(Long awayTeamId) { + this.awayTeamId = awayTeamId; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/domain/Player.java b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Player.java new file mode 100644 index 000000000..880c2d713 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Player.java @@ -0,0 +1,119 @@ +package com.codesquad.baseball.domain; + +import org.springframework.data.annotation.Id; + +import java.util.Objects; + +public class Player { + + @Id + private Long id; + + private String name; + + private int hit; + + private int out; + + private int plateAppearance; + + private int battingOrder; + + private int backNumber; + + private boolean isPitcher; + + public Player(String name, int battingOrder, int backNumber, boolean isPitcher) { + this.name = name; + this.battingOrder = battingOrder; + this.backNumber = backNumber; + this.isPitcher = isPitcher; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public int getHit() { + return hit; + } + + public int getOut() { + return out; + } + + public int getPlateAppearance() { + return plateAppearance; + } + + public int getBattingOrder() { + return battingOrder; + } + + public int getBackNumber() { + return backNumber; + } + + public boolean isPitcher() { + return isPitcher; + } + + public void setName(String name) { + this.name = name; + } + + public void setHit(int hit) { + this.hit = hit; + } + + public void setOut(int out) { + this.out = out; + } + + public void setPlateAppearance(int plateAppearance) { + this.plateAppearance = plateAppearance; + } + + public void setBattingOrder(int battingOrder) { + this.battingOrder = battingOrder; + } + + public void setBackNumber(int backNumber) { + this.backNumber = backNumber; + } + + public void setPitcher(boolean pitcher) { + isPitcher = pitcher; + } + + public void updateRecord(int plateAppearance, int hit, int out) { + this.plateAppearance = plateAppearance; + this.hit = hit; + this.out = out; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Player player = (Player) o; + return Objects.equals(id, player.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return "Player{" + + "id=" + id + + ", name='" + name + '\'' + + '}'; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/domain/Score.java b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Score.java new file mode 100644 index 000000000..855e755ee --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Score.java @@ -0,0 +1,20 @@ +package com.codesquad.baseball.domain; + +public class Score { + + private int inning; + private int score; + + public Score(int inning, int score) { + this.inning = inning; + this.score = score; + } + + public int getInning() { + return inning; + } + + public int getScore() { + return score; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/domain/Team.java b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Team.java new file mode 100644 index 000000000..74971141c --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/domain/Team.java @@ -0,0 +1,126 @@ +package com.codesquad.baseball.domain; + +import com.codesquad.baseball.error.exception.PlayerNotFoundException; +import org.springframework.data.annotation.Id; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class Team { + + @Id + private Long id; + + private String name; + + private boolean isHome; + + private boolean isPlayable; + + private Long pitcherId; + + private boolean userSelected; + + private Set players = new HashSet<>(); + + private Set scores = new HashSet<>(); + + public Team(String name, boolean isHome, boolean isPlayable) { + this.name = name; + this.isHome = isHome; + this.isPlayable = isPlayable; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public boolean isHome() { + return isHome; + } + + public boolean isPlayable() { + return isPlayable; + } + + public Long getPitcherId() { + return pitcherId; + } + + public boolean isUserSelected() { + return userSelected; + } + + public Set getPlayers() { + return players; + } + + public Set getScores() { + return scores; + } + + public void setName(String name) { + this.name = name; + } + + public void setHome(boolean home) { + isHome = home; + } + + public void setPlayable(boolean playable) { + isPlayable = playable; + } + + public void setPitcherId(Long pitcherId) { + this.pitcherId = pitcherId; + } + + public Team setUserSelected(boolean userSelected) { + this.userSelected = userSelected; + return this; + } + + public void addPlayer(Player player) { + players.add(player); + } + + public void updatePlayerSet(Player player) { + players.remove(getPlayerById(player.getId())); + addPlayer(player); + } + + public Player getPlayerById(Long id) { + for (Player player : players) { + if (id.equals(player.getId())) { + return player; + } + } + throw new PlayerNotFoundException(); + } + + public void addScore(Score score) { + scores.add(score); + } + + public List getSortedScores() { + return scores.stream() + .sorted(Comparator.comparingInt(Score::getInning)) + .collect(Collectors.toList()); + } + + @Override + public String toString() { + return "Team{" + + "id=" + id + + ", name='" + name + '\'' + + ", players=" + players + + '}'; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/ErrorCode.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/ErrorCode.java new file mode 100644 index 000000000..96a1519b3 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/ErrorCode.java @@ -0,0 +1,27 @@ +package com.codesquad.baseball.error; + +import org.springframework.http.HttpStatus; + +public enum ErrorCode { + // NotFoundExceptions + GAME_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당하는 게임을 찾을 수 없습니다."), + TEAM_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당하는 팀을 찾을 수 없습니다."), + PLAYER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당하는 선수를 찾을 수 없습니다."), + TEAM_NOT_PLAYABLE_EXCEPTION(HttpStatus.BAD_REQUEST, "해당하는 팀은 이미 선점되어 있습니다."); + + private final HttpStatus status; + private final String message; + + ErrorCode(HttpStatus status, String message) { + this.status = status; + this.message = message; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/ErrorResponse.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/ErrorResponse.java new file mode 100644 index 000000000..0c0385dec --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/ErrorResponse.java @@ -0,0 +1,27 @@ +package com.codesquad.baseball.error; + +import org.springframework.http.HttpStatus; + +public class ErrorResponse { + + private HttpStatus status; + + private String message; + + private ErrorResponse(ErrorCode errorCode) { + this.status = errorCode.getStatus(); + this.message = errorCode.getMessage(); + } + + public static ErrorResponse of(ErrorCode errorCode) { + return new ErrorResponse(errorCode); + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/GameNotFoundException.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/GameNotFoundException.java new file mode 100644 index 000000000..8983c7205 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/GameNotFoundException.java @@ -0,0 +1,10 @@ +package com.codesquad.baseball.error.exception; + +import com.codesquad.baseball.error.ErrorCode; + +public class GameNotFoundException extends NotFoundException { + + public GameNotFoundException() { + super(ErrorCode.GAME_NOT_FOUND_EXCEPTION); + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/NotFoundException.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/NotFoundException.java new file mode 100644 index 000000000..50f9e5d8d --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/NotFoundException.java @@ -0,0 +1,17 @@ +package com.codesquad.baseball.error.exception; + +import com.codesquad.baseball.error.ErrorCode; + +public class NotFoundException extends RuntimeException { + + private final ErrorCode errorCode; + + public NotFoundException(ErrorCode errorCode) { + super(errorCode.getMessage()); + this.errorCode = errorCode; + } + + public ErrorCode getErrorCode() { + return errorCode; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/PlayerNotFoundException.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/PlayerNotFoundException.java new file mode 100644 index 000000000..647c5ed9a --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/PlayerNotFoundException.java @@ -0,0 +1,10 @@ +package com.codesquad.baseball.error.exception; + +import com.codesquad.baseball.error.ErrorCode; + +public class PlayerNotFoundException extends NotFoundException { + + public PlayerNotFoundException() { + super(ErrorCode.PLAYER_NOT_FOUND_EXCEPTION); + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/TeamNotFoundException.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/TeamNotFoundException.java new file mode 100644 index 000000000..51f4bde68 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/TeamNotFoundException.java @@ -0,0 +1,10 @@ +package com.codesquad.baseball.error.exception; + +import com.codesquad.baseball.error.ErrorCode; + +public class TeamNotFoundException extends NotFoundException { + + public TeamNotFoundException() { + super(ErrorCode.TEAM_NOT_FOUND_EXCEPTION); + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/TeamNotPlayableException.java b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/TeamNotPlayableException.java new file mode 100644 index 000000000..98bb49180 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/error/exception/TeamNotPlayableException.java @@ -0,0 +1,17 @@ +package com.codesquad.baseball.error.exception; + +import com.codesquad.baseball.error.ErrorCode; + +public class TeamNotPlayableException extends RuntimeException { + + private final ErrorCode errorCode; + + public TeamNotPlayableException(){ + super(ErrorCode.TEAM_NOT_FOUND_EXCEPTION.getMessage()); + this.errorCode = ErrorCode.TEAM_NOT_PLAYABLE_EXCEPTION; + } + + public ErrorCode getErrorCode() { + return errorCode; + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/repository/GameRepository.java b/BE/baseball/src/main/java/com/codesquad/baseball/repository/GameRepository.java new file mode 100644 index 000000000..44bc60c80 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/repository/GameRepository.java @@ -0,0 +1,20 @@ +package com.codesquad.baseball.repository; + +import com.codesquad.baseball.DTO.GameListDTO; +import com.codesquad.baseball.domain.Game; +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; + +import java.util.List; + +public interface GameRepository extends CrudRepository { + + @Query("select game.id as gameId,\n" + + "(Select team.name from game left join team on game.home_team_id = team.id where game.id = gameId) as homeTeamName,\n" + + "game.home_team_id as homeTeamId,\n" + + "(Select team.name from game left join team on game.away_team_id = team.id where game.id = gameId) as awayTeamName,\n" + + "game.away_team_id as awayTeamId\n" + + "From game;") // 게임이 가진 홈팀, 원정팀 아이디로 team 테이블에서 해당 팀의 이름까지 가져오게 했습니다. + List browseAllGames(); + +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/repository/TeamRepository.java b/BE/baseball/src/main/java/com/codesquad/baseball/repository/TeamRepository.java new file mode 100644 index 000000000..11f8ecbb4 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/repository/TeamRepository.java @@ -0,0 +1,7 @@ +package com.codesquad.baseball.repository; + +import com.codesquad.baseball.domain.Team; +import org.springframework.data.repository.CrudRepository; + +public interface TeamRepository extends CrudRepository { +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/service/GameService.java b/BE/baseball/src/main/java/com/codesquad/baseball/service/GameService.java new file mode 100644 index 000000000..77fbdc1ee --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/service/GameService.java @@ -0,0 +1,64 @@ +package com.codesquad.baseball.service; + +import com.codesquad.baseball.DTO.GameListDTO; +import com.codesquad.baseball.DTO.record.TeamRecordDTO; +import com.codesquad.baseball.DTO.score.GameScoreDTO; +import com.codesquad.baseball.DTO.score.TeamScoreDTO; +import com.codesquad.baseball.domain.Game; +import com.codesquad.baseball.domain.Team; +import com.codesquad.baseball.error.exception.GameNotFoundException; +import com.codesquad.baseball.error.exception.TeamNotFoundException; +import com.codesquad.baseball.repository.GameRepository; +import com.codesquad.baseball.repository.TeamRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class GameService { + + private final GameRepository gameRepository; + private final TeamRepository teamRepository; + + @Autowired + public GameService(GameRepository gameRepository, TeamRepository teamRepository) { + this.gameRepository = gameRepository; + this.teamRepository = teamRepository; + } + + public Game save(Game game) { + return gameRepository.save(game); + } + + public List browseAllGames() { + Iterable games = gameRepository.findAll(); + List gameList = new ArrayList<>(); + for (Game game : games) { + Long id = game.getId(); + gameList.add(GameListDTO.of(id, findHomeTeamByGameId(id), findAwayTeamByGameId(id))); + } + return gameList; + } + + public Game findGameById(Long id) { + return gameRepository.findById(id).orElseThrow(GameNotFoundException::new); + } + + public Team findHomeTeamByGameId(Long id) { + return teamRepository.findById(findGameById(id).getHomeTeamId()).orElseThrow(TeamNotFoundException::new); + } + + public Team findAwayTeamByGameId(Long id) { + return teamRepository.findById(findGameById(id).getAwayTeamId()).orElseThrow(TeamNotFoundException::new); + } + + public TeamRecordDTO browseTeamPlayersByGameId(Long id) { + return new TeamRecordDTO(findAwayTeamByGameId(id), findHomeTeamByGameId(id)); + } + + public GameScoreDTO browseGameScoreByGameId(Long id) { + return GameScoreDTO.of(findGameById(id), TeamScoreDTO.of(findHomeTeamByGameId(id)), TeamScoreDTO.of(findAwayTeamByGameId(id))); + } +} diff --git a/BE/baseball/src/main/java/com/codesquad/baseball/service/TeamService.java b/BE/baseball/src/main/java/com/codesquad/baseball/service/TeamService.java new file mode 100644 index 000000000..30272dc66 --- /dev/null +++ b/BE/baseball/src/main/java/com/codesquad/baseball/service/TeamService.java @@ -0,0 +1,58 @@ +package com.codesquad.baseball.service; + +import com.codesquad.baseball.DTO.TeamDTO; +import com.codesquad.baseball.DTO.record.request.PlayerRecordRequest; +import com.codesquad.baseball.DTO.score.TeamScoreDTO; +import com.codesquad.baseball.domain.Player; +import com.codesquad.baseball.domain.Score; +import com.codesquad.baseball.domain.Team; +import com.codesquad.baseball.error.exception.TeamNotFoundException; +import com.codesquad.baseball.error.exception.TeamNotPlayableException; +import com.codesquad.baseball.repository.TeamRepository; +import org.springframework.stereotype.Service; + +@Service +public class TeamService { + + private final TeamRepository teamRepository; + + public TeamService(TeamRepository teamRepository) { + this.teamRepository = teamRepository; + } + + public Team save(Team team) { + return teamRepository.save(team); + } + + public Team browseTeamById(Long id) { + return teamRepository.findById(id).orElseThrow(TeamNotFoundException::new); + } + + public TeamDTO browseTeamStatus(Long id) { + Team team = browseTeamById(id); + if (!team.isPlayable()) { + throw new TeamNotPlayableException(); + } + save(team.setUserSelected(true)); + return TeamDTO.of(team); + } + + public void addScore(Long id, Score score) { + Team team = browseTeamById(id); + team.addScore(score); + save(team); + } + + public void updatePlayerRecord(Long teamId, PlayerRecordRequest playerRecord) { + Team team = browseTeamById(teamId); + Player player = team.getPlayerById(playerRecord.getPlayerId()); + player.updateRecord(playerRecord.getPlateAppearance(), playerRecord.getHit(), playerRecord.getOut()); + team.updatePlayerSet(player); + save(team); + } + + public TeamScoreDTO browseTeamScore(Long teamId) { + Team team = browseTeamById(teamId); + return TeamScoreDTO.of(team); + } +} diff --git a/BE/baseball/src/main/resources/application.properties b/BE/baseball/src/main/resources/application.properties new file mode 100644 index 000000000..d825bfa82 --- /dev/null +++ b/BE/baseball/src/main/resources/application.properties @@ -0,0 +1,9 @@ +# DB +spring.datasource.url=jdbc:mysql://localhost:3306/baseball?serverTimezone=UTC&characterEncoding=UTF-8 +spring.datasource.username=root +spring.datasource.password=root +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.initialization-mode=always + +logging.level.org.springframework.jdbc.core.JdbcTemplate=debug +Logging.file.path=logs diff --git a/BE/baseball/src/main/resources/data.sql b/BE/baseball/src/main/resources/data.sql new file mode 100644 index 000000000..5803515d0 --- /dev/null +++ b/BE/baseball/src/main/resources/data.sql @@ -0,0 +1,6 @@ +INSERT INTO `team`(name, is_home, is_playable) VALUES ('Captain', 1, 1), ('Marvel', 0, 0), ('Tigers', 1, 1), ('Giants', 0, 1), ('team5', 1, 1), ('team6', 0, 1); + +INSERT INTO `game`(home_team_id, away_team_id) VALUES (1, 2), (3, 4), (5, 6); + +INSERT INTO `player`(name, team, batting_order, back_number, is_pitcher) +VALUES ('p1', 1, 1, 1, 1), ('p2', 1, 2, 2, 0), ('p3', 1, 3, 3, 0), ('p4', 2, 4, 4, 0), ('p5', 2, 5, 5, 0), ('p6', 2, 6, 6, 0); diff --git a/BE/baseball/src/main/resources/schema.sql b/BE/baseball/src/main/resources/schema.sql new file mode 100644 index 000000000..33bf63ceb --- /dev/null +++ b/BE/baseball/src/main/resources/schema.sql @@ -0,0 +1,42 @@ +# use baseball; +DROP TABLE IF EXISTS score; +DROP TABLE IF EXISTS game; +DROP TABLE IF EXISTS player; +DROP TABLE IF EXISTS team; + +CREATE TABLE IF NOT EXISTS `baseball`.`team` ( + `id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(45) NOT NULL, + `is_home` TINYINT(1) NOT NULL, + `is_playable` TINYINT(1), + `user_selected` TINYINT(1) DEFAULT 0, + `pitcher_id` BIGINT +); + +CREATE TABLE IF NOT EXISTS `baseball`.`game` ( + `id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `home_team_id` BIGINT, + `away_team_id` BIGINT, + FOREIGN KEY (`home_team_id`) REFERENCES `team`(`id`), + FOREIGN KEY (`away_team_id`) REFERENCES `team`(`id`) +); + +CREATE TABLE IF NOT EXISTS `baseball`.`player` ( + `id` BIGINT PRIMARY KEY AUTO_INCREMENT, + `name` VARCHAR(45) NOT NULL, + `plate_appearance` INT DEFAULT 0, + `hit` INT DEFAULT 0, + `out` INT DEFAULT 0, + `batting_order` INT, + `back_number` INT, + `is_pitcher` TINYINT(1), + `team` BIGINT, + FOREIGN KEY (`team`) REFERENCES `team`(`id`) +); + +CREATE TABLE IF NOT EXISTS `baseball`.`score` ( + `inning` INT, + `score` INT, + `team` BIGINT, + FOREIGN KEY (`team`) REFERENCES `team`(`id`) +); diff --git a/BE/baseball/src/test/java/com/codesquad/baseball/BaseballApplicationTests.java b/BE/baseball/src/test/java/com/codesquad/baseball/BaseballApplicationTests.java new file mode 100644 index 000000000..91057559a --- /dev/null +++ b/BE/baseball/src/test/java/com/codesquad/baseball/BaseballApplicationTests.java @@ -0,0 +1,13 @@ +package com.codesquad.baseball; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class BaseballApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/FE/init b/FE/init new file mode 100644 index 000000000..e69de29bb