-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GameViewModel & GameListViewModel 작성 및 Network 추가
- Loading branch information
1 parent
73a75dd
commit 7efc2cd
Showing
11 changed files
with
379 additions
and
43 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// GameEntity.swift | ||
// Baseball | ||
// | ||
// Created by 심영민 on 2021/05/06. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GameList: Decodable { | ||
var gameNumber: Int | ||
var home: String | ||
var away: String | ||
} | ||
|
||
struct Game: Decodable { | ||
var home: Team | ||
var away: Team | ||
var homeScore: Int | ||
var awayScore: Int | ||
var inning: Int // 몇회 | ||
var status: String // 초, 말 | ||
var ballCount: [BallCount] | ||
} | ||
|
||
struct Team: Decodable { | ||
var name: String | ||
var players: [Player] | ||
} | ||
|
||
struct Player: Decodable { | ||
var name: String | ||
var position: String // 포지션 | ||
var atBat: String // 타석 | ||
var hits: Int // 안타 | ||
var out: Int // 아웃 | ||
var battingAverage: Double // 타율 | ||
var numberOfPitches: Int // 투구수 | ||
} | ||
|
||
struct BallCount: Decodable { | ||
enum ball: Int, Decodable { | ||
case strike = 0 | ||
case ball = 1 | ||
case hit = 2 | ||
} | ||
var ballCount: [ball] | ||
var hit: Bool | ||
} | ||
|
||
struct Score { | ||
var home: [Int] | ||
var away: [Int] | ||
} |
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,36 @@ | ||
// | ||
// FetchGame.swift | ||
// Baseball | ||
// | ||
// Created by 심영민 on 2021/05/06. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
class FetchGame { | ||
|
||
private var network: Network | ||
private var requestable: Requestable | ||
private var subscriptions = Set<AnyCancellable>() | ||
|
||
init() { | ||
self.network = Network() | ||
self.requestable = GameAPIEndpoint(path: "", httpMethod: .get) | ||
} | ||
|
||
func fetchGame(completion: @escaping (GameDTO)->Void) { | ||
network.request(with: requestable, dataType: GameDTO.self) | ||
.sink { (result) in | ||
switch result { | ||
case .failure(let error): | ||
print(error) | ||
case .finished: | ||
break | ||
} | ||
} receiveValue: { (game) in | ||
completion(game) | ||
} | ||
.store(in: &subscriptions) | ||
} | ||
} |
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,37 @@ | ||
// | ||
// FetchGameList.swift | ||
// Baseball | ||
// | ||
// Created by 심영민 on 2021/05/06. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
class FetchGameList { | ||
|
||
private var network: Network | ||
private var requestable: Requestable | ||
private var subscriptions = Set<AnyCancellable>() | ||
|
||
init() { | ||
self.network = Network() | ||
self.requestable = GameAPIEndpoint(path: "", httpMethod: .get) | ||
} | ||
|
||
func fetchGameList(completion: @escaping (GameListDTO)->Void) { | ||
network.request(with: requestable, dataType: GameListDTO.self) | ||
.sink { (result) in | ||
switch result { | ||
case .failure(let error): | ||
print(error) | ||
case .finished: | ||
break | ||
} | ||
} receiveValue: { (gameList) in | ||
completion(gameList) | ||
} | ||
.store(in: &subscriptions) | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// EndPoint.swift | ||
// Baseball | ||
// | ||
// Created by 심영민 on 2021/05/06. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol Requestable { | ||
var baseURL: String { get } | ||
var path: String { get } | ||
var httpMethod: HttpMethod { get } | ||
func url() -> URL? | ||
} | ||
|
||
public struct GameAPIEndpoint: Requestable { | ||
|
||
public let baseURL = "" | ||
public let path: String | ||
public let httpMethod: HttpMethod | ||
|
||
init(path: String, httpMethod: HttpMethod) { | ||
self.path = path | ||
self.httpMethod = httpMethod | ||
} | ||
|
||
public func url() -> URL? { | ||
return URL(string: baseURL + path) | ||
} | ||
} |
Oops, something went wrong.