-
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.
feat: GamePlayView 엔티티, 네트워크, 유즈케이스, 뷰모델 구현
- Loading branch information
Jun Ho JANG
authored and
Jun Ho JANG
committed
May 12, 2021
1 parent
a4c9090
commit e62041d
Showing
13 changed files
with
294 additions
and
13 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
50 changes: 50 additions & 0 deletions
50
Baseball/Baseball/Data/Network/DataMapping/GamePlayDTO+Mapping.swift
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,50 @@ | ||
// | ||
// GamePlayDTO+Mapping.swift | ||
// Baseball | ||
// | ||
// Created by Jun Ho JANG on 2021/05/12. | ||
// | ||
|
||
import Foundation | ||
|
||
/* | ||
{"matchId":13, | ||
"away":"awayteam to string", | ||
"home":"hometeam to string", | ||
"inning":1, | ||
"offenseTeam":"offenseTeam to String" | ||
"firstBase":[], | ||
"secondBase":[], | ||
"thirdBase":[], | ||
"pitcher":"kim", | ||
"batter":"dong", | ||
"strike":0, | ||
"ball":0, | ||
"out":0, | ||
"homePoint":0, | ||
"awayPoint":0} | ||
*/ | ||
|
||
|
||
|
||
struct GamePlayDTO: Decodable { | ||
private let matchId: Int | ||
private let away: String | ||
private let home: String | ||
private let inning: Int | ||
private let offenseTeam: String | ||
private let firstBase: [String] | ||
private let secondBase: [String] | ||
private let thirdBase: [String] | ||
private let pitcher: String | ||
private let batter: String | ||
private let strike: Int | ||
private let ball: Int | ||
private let out: Int | ||
private let homePoint: Int | ||
private let awayPoint: Int | ||
|
||
func toDomain() -> GamePlay { | ||
return .init(matchId: matchId, away: away, home: home, inning: inning, offenseTeam: offenseTeam, firstBase: firstBase, secondBase: secondBase, thirdBase: thirdBase, pitcher: pitcher, batter: batter, strike: strike, ball: ball, out: out, homePoint: homePoint, awayPoint: awayPoint) | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
Baseball/Baseball/Data/Repository/GamePlayRepository.swift
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,42 @@ | ||
// | ||
// GamePlayRepository.swift | ||
// Baseball | ||
// | ||
// Created by Jun Ho JANG on 2021/05/12. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
protocol GamePlayRepository { | ||
func fetchGamePlayData(matchId: Int, completion: @escaping (Result<GamePlay, NetworkError>) -> Void) | ||
} | ||
|
||
class DefaultGamePlayRepository: GamePlayRepository { | ||
|
||
private let networkService: NetworkService | ||
private var subscriptions = Set<AnyCancellable>() | ||
|
||
init(networkService: NetworkService) { | ||
self.networkService = networkService | ||
} | ||
|
||
func fetchGamePlayData(matchId: Int, completion: @escaping (Result<GamePlay, NetworkError>) -> Void) { | ||
let path = String(matchId) | ||
let endpoint = GamePlayEndPoint(httpMethod: .get, path: path) | ||
|
||
self.networkService.request(with: endpoint, dataType: GamePlayDTO.self) | ||
.sink { result in | ||
switch result { | ||
case .failure(let error): | ||
completion(.failure(error)) | ||
case .finished: | ||
break | ||
} | ||
} receiveValue: { gamePlayDTO in | ||
let gamePlayData = gamePlayDTO.toDomain() | ||
completion(.success(gamePlayData)) | ||
} | ||
.store(in: &self.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,26 @@ | ||
// | ||
// GamePlay.swift | ||
// Baseball | ||
// | ||
// Created by Jun Ho JANG on 2021/05/12. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GamePlay { | ||
var matchId: Int | ||
var away: String | ||
var home: String | ||
var inning: Int | ||
var offenseTeam: String | ||
var firstBase: [String] | ||
var secondBase: [String] | ||
var thirdBase: [String] | ||
var pitcher: String | ||
var batter: String | ||
var strike: Int | ||
var ball: Int | ||
var out: Int | ||
var homePoint: Int | ||
var awayPoint: Int | ||
} |
26 changes: 26 additions & 0 deletions
26
Baseball/Baseball/Domain/UseCase/FetchGamePlayUseCase.swift
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,26 @@ | ||
// | ||
// FetchGamePlayUseCase.swift | ||
// Baseball | ||
// | ||
// Created by Jun Ho JANG on 2021/05/12. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol FetchGamePlayUseCase { | ||
func execute(matchId: Int, completion: @escaping(Result<GamePlay,NetworkError>) -> Void) | ||
} | ||
|
||
class DefaultFetchGamePlayUseCase: FetchGamePlayUseCase { | ||
private let gamePlayRepository: GamePlayRepository | ||
|
||
init(gamePlayRepository: GamePlayRepository) { | ||
self.gamePlayRepository = gamePlayRepository | ||
} | ||
|
||
func execute(matchId : Int, completion: @escaping (Result<GamePlay,NetworkError>) -> Void) { | ||
gamePlayRepository.fetchGamePlayData(matchId: matchId) { result in | ||
completion(result) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.