Skip to content

Commit

Permalink
#6 Data fetch & BallCountView
Browse files Browse the repository at this point in the history
  • Loading branch information
zzisun committed May 13, 2021
1 parent c75b42d commit a01d372
Show file tree
Hide file tree
Showing 20 changed files with 495 additions and 68 deletions.
24 changes: 24 additions & 0 deletions iOS/baseballApp/baseballApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
76619ABC2643A355004D31C6 /* GameViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76619ABB2643A355004D31C6 /* GameViewModel.swift */; };
76619AC22643AE83004D31C6 /* GameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76619AC12643AE83004D31C6 /* GameCell.swift */; };
76619B062644EE37004D31C6 /* StadiumView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76619B052644EE37004D31C6 /* StadiumView.swift */; };
76855AC7264BE17600068E77 /* BallCountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76855AC6264BE17600068E77 /* BallCountView.swift */; };
7691F9A526491ADB00C56E11 /* PlayStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7691F9A426491ADB00C56E11 /* PlayStoryboard.storyboard */; };
76A7E3A6264CB9010028B08A /* PlayInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3A5264CB9010028B08A /* PlayInfo.swift */; };
76A7E3A8264CBD510028B08A /* PlayDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3A7264CBD510028B08A /* PlayDTO.swift */; };
76A7E3AA264CC4B60028B08A /* PlayViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3A9264CC4B60028B08A /* PlayViewModel.swift */; };
76A7E3AC264CD2F20028B08A /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3AB264CD2F20028B08A /* Constant.swift */; };
76A7E3EA264CF9B50028B08A /* BallCount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76A7E3E9264CF9B50028B08A /* BallCount.swift */; };
76AA2694264A73F500600D45 /* ScoreStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 76AA2693264A73F500600D45 /* ScoreStoryboard.storyboard */; };
76AF2BC4264B7D9900DC7782 /* GameViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76AF2BC3264B7D9900DC7782 /* GameViewModelType.swift */; };
76AF2BC7264BA5F600DC7782 /* BallListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76AF2BC5264BA5F600DC7782 /* BallListCell.swift */; };
Expand Down Expand Up @@ -85,7 +91,13 @@
76619ABB2643A355004D31C6 /* GameViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewModel.swift; sourceTree = "<group>"; };
76619AC12643AE83004D31C6 /* GameCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCell.swift; sourceTree = "<group>"; };
76619B052644EE37004D31C6 /* StadiumView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StadiumView.swift; sourceTree = "<group>"; };
76855AC6264BE17600068E77 /* BallCountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallCountView.swift; sourceTree = "<group>"; };
7691F9A426491ADB00C56E11 /* PlayStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = PlayStoryboard.storyboard; sourceTree = "<group>"; };
76A7E3A5264CB9010028B08A /* PlayInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayInfo.swift; sourceTree = "<group>"; };
76A7E3A7264CBD510028B08A /* PlayDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayDTO.swift; sourceTree = "<group>"; };
76A7E3A9264CC4B60028B08A /* PlayViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayViewModel.swift; sourceTree = "<group>"; };
76A7E3AB264CD2F20028B08A /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; };
76A7E3E9264CF9B50028B08A /* BallCount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallCount.swift; sourceTree = "<group>"; };
76AA2693264A73F500600D45 /* ScoreStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ScoreStoryboard.storyboard; sourceTree = "<group>"; };
76AF2BC3264B7D9900DC7782 /* GameViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewModelType.swift; sourceTree = "<group>"; };
76AF2BC5264BA5F600DC7782 /* BallListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BallListCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -156,6 +168,7 @@
7650A1B02640E3A9006C1E5F /* Assets.xcassets */,
7650A1B22640E3A9006C1E5F /* LaunchScreen.storyboard */,
7650A1B52640E3A9006C1E5F /* Info.plist */,
76A7E3AB264CD2F20028B08A /* Constant.swift */,
);
path = baseballApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -202,6 +215,7 @@
children = (
76619ABB2643A355004D31C6 /* GameViewModel.swift */,
76AF2BC3264B7D9900DC7782 /* GameViewModelType.swift */,
76A7E3A9264CC4B60028B08A /* PlayViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand All @@ -223,6 +237,7 @@
76619B052644EE37004D31C6 /* StadiumView.swift */,
76AF2BC5264BA5F600DC7782 /* BallListCell.swift */,
76AF2BC6264BA5F600DC7782 /* BallListCell.xib */,
76855AC6264BE17600068E77 /* BallCountView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -250,6 +265,8 @@
7650A1E6264138A0006C1E5F /* Player.swift */,
7650A1E82641418B006C1E5F /* Record.swift */,
76619AA626437476004D31C6 /* Game.swift */,
76A7E3A5264CB9010028B08A /* PlayInfo.swift */,
76A7E3E9264CF9B50028B08A /* BallCount.swift */,
);
path = Entity;
sourceTree = "<group>";
Expand Down Expand Up @@ -285,6 +302,7 @@
isa = PBXGroup;
children = (
76619AB326439866004D31C6 /* GameDTO.swift */,
76A7E3A7264CBD510028B08A /* PlayDTO.swift */,
);
path = DataMapping;
sourceTree = "<group>";
Expand Down Expand Up @@ -559,15 +577,21 @@
7650A1A82640E3A8006C1E5F /* AppDelegate.swift in Sources */,
76AF2BC4264B7D9900DC7782 /* GameViewModelType.swift in Sources */,
76619AC22643AE83004D31C6 /* GameCell.swift in Sources */,
76A7E3EA264CF9B50028B08A /* BallCount.swift in Sources */,
7650A1AA2640E3A8006C1E5F /* SceneDelegate.swift in Sources */,
7650A1E126411A51006C1E5F /* HomeViewController.swift in Sources */,
76619ABC2643A355004D31C6 /* GameViewModel.swift in Sources */,
76619AB426439866004D31C6 /* GameDTO.swift in Sources */,
7650A1E92641418B006C1E5F /* Record.swift in Sources */,
76619AB2264385BB004D31C6 /* APIService.swift in Sources */,
76A7E3AA264CC4B60028B08A /* PlayViewModel.swift in Sources */,
76A7E3A8264CBD510028B08A /* PlayDTO.swift in Sources */,
76A7E3AC264CD2F20028B08A /* Constant.swift in Sources */,
7650A1E7264138A0006C1E5F /* Player.swift in Sources */,
76A7E3A6264CB9010028B08A /* PlayInfo.swift in Sources */,
7650A1E526411A78006C1E5F /* ScoreViewController.swift in Sources */,
76619AA726437476004D31C6 /* Game.swift in Sources */,
76855AC7264BE17600068E77 /* BallCountView.swift in Sources */,
76619B062644EE37004D31C6 /* StadiumView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "baseball_player.png",
"filename" : "baseball_player-2.png",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
12 changes: 12 additions & 0 deletions iOS/baseballApp/baseballApp/Constant.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Constant.swift
// baseballApp
//
// Created by 김지선 on 2021/05/13.
//

import Foundation

struct Notification {
static let sendGame = "sendGame"
}
7 changes: 7 additions & 0 deletions iOS/baseballApp/baseballApp/Data/Network/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class APIService {
}
return getAndDecode(url)
}

func requestPlay(gameID: Int, inningID: Int) throws -> Observable<PlayDTO> {
guard let url = Endpoint.getGames(path: "baseball/\(gameID)/inning/\(inningID)") else {
throw APIError.urlNotSupport
}
return getAndDecode(url)
}

private func getAndDecode<T: Codable>(_ url: URL) -> Observable<T> {
return Observable.create { observer in
Expand Down
29 changes: 29 additions & 0 deletions iOS/baseballApp/baseballApp/Data/Network/DataMapping/PlayDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Foundation

struct PlayDTO: Codable {
let inningID: Int
let inning: Int
let attackTeamID: Int
let ballCount: [String]
let outCount: Int
let pitcher: Player
let batter: Player
let baseStatus: [Int]
let homeTeamScore: Int
let awayTeamScore: Int

enum CodingKeys: String, CodingKey {
case inningID = "inning_id"
case inning = "inning"
case attackTeamID = "attack_team_id"
case ballCount = "ball_count"
case outCount = "out_count"
case pitcher = "pitcher"
case batter = "batter"
case baseStatus = "base_status"
case homeTeamScore = "home_team_score"
case awayTeamScore = "away_team_score"
}
}


17 changes: 17 additions & 0 deletions iOS/baseballApp/baseballApp/Domain/Entity/BallCount.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation

class BallCount {
private var strike: Int
private var ball: Int

init() {
self.strike = 0
self.ball = 0
}

func addBall(_ ballType: String) -> (Int, Int) {
strike += ballType == "S" ? 1 : 0
ball += ballType == "B" ? 1: 0
return (strike, ball)
}
}
4 changes: 2 additions & 2 deletions iOS/baseballApp/baseballApp/Domain/Entity/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Game: Codable {
let awayID: Int
let away: String
let awayScore: Int
let inning: Int
let inningID: Int

enum CodingKeys: String, CodingKey {
case id = "game_id"
Expand All @@ -18,6 +18,6 @@ struct Game: Codable {
case awayID = "away_team_id"
case away = "away_team"
case awayScore = "away_team_score"
case inning = "now_inning_id"
case inningID = "now_inning_id"
}
}
2 changes: 2 additions & 0 deletions iOS/baseballApp/baseballApp/Domain/Entity/PlayInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Foundation

3 changes: 1 addition & 2 deletions iOS/baseballApp/baseballApp/Domain/Entity/Player.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation

struct Player {
struct Player: Codable {
let name: String
let backNumber: Int
let record: Record
}
Loading

0 comments on commit a01d372

Please sign in to comment.