Skip to content

Commit

Permalink
chore : 병합 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
eeeesong committed May 6, 2021
2 parents 6ba9d53 + d231e62 commit 37b464a
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 14 deletions.
4 changes: 4 additions & 0 deletions iOS/baseball-game/baseball-game.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
AE5C79B426412B830075EBC3 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5C79B326412B830075EBC3 /* Network.swift */; };
AE5C79B7264138E70075EBC3 /* SelectViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5C79B6264138E70075EBC3 /* SelectViewModel.swift */; };
AE7A1542263FE4DE005EBAB9 /* SelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE7A1541263FE4DE005EBAB9 /* SelectionViewController.swift */; };
AEFE32DA2643971B0077AA5F /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEFE32D92643971B0077AA5F /* LoginViewController.swift */; };
E4AA6883263FDDA500139BD6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4AA6882263FDDA500139BD6 /* AppDelegate.swift */; };
E4AA6885263FDDA500139BD6 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4AA6884263FDDA500139BD6 /* SceneDelegate.swift */; };
E4AA6887263FDDA500139BD6 /* GamePlayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4AA6886263FDDA500139BD6 /* GamePlayViewController.swift */; };
Expand Down Expand Up @@ -40,6 +41,7 @@
AE5C79B326412B830075EBC3 /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
AE5C79B6264138E70075EBC3 /* SelectViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectViewModel.swift; sourceTree = "<group>"; };
AE7A1541263FE4DE005EBAB9 /* SelectionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectionViewController.swift; sourceTree = "<group>"; };
AEFE32D92643971B0077AA5F /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
E4AA687F263FDDA500139BD6 /* baseball-game.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "baseball-game.app"; sourceTree = BUILT_PRODUCTS_DIR; };
E4AA6882263FDDA500139BD6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
E4AA6884263FDDA500139BD6 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -84,6 +86,7 @@
AE7A1543263FE4FE005EBAB9 /* Selection */ = {
isa = PBXGroup;
children = (
AEFE32D92643971B0077AA5F /* LoginViewController.swift */,
AE7A1541263FE4DE005EBAB9 /* SelectionViewController.swift */,
AE5C79B6264138E70075EBC3 /* SelectViewModel.swift */,
AE5C79AD2640E8710075EBC3 /* GameCell.swift */,
Expand Down Expand Up @@ -256,6 +259,7 @@
E4FE76DA26412ACD00151B35 /* GameManager.swift in Sources */,
E4FE76DF26438ABC00151B35 /* PitchListTableViewCell.swift in Sources */,
E4FE76D82641242400151B35 /* SelectPitcherViewController.swift in Sources */,
AEFE32DA2643971B0077AA5F /* LoginViewController.swift in Sources */,
AE5C79AF2640E8710075EBC3 /* GameCell.swift in Sources */,
E4FE76ED2643DA3400151B35 /* Turn.swift in Sources */,
AE5C79B2264127300075EBC3 /* Game.swift in Sources */,
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions iOS/baseball-game/baseball-game/AppCycle/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)

let rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "LoginViewController") as LoginViewController

let navigationViewController = UINavigationController(rootViewController: rootViewController)

window?.rootViewController = navigationViewController
}
}

71 changes: 68 additions & 3 deletions iOS/baseball-game/baseball-game/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="bc6-zR-OBT">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
Expand All @@ -8,10 +8,53 @@
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Login View Controller-->
<scene sceneID="vgB-wA-gkL">
<objects>
<viewController storyboardIdentifier="LoginViewController" id="acG-MO-tPJ" customClass="LoginViewController" customModule="baseball_game" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Rbm-Wg-nXP">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="ump-1U-kn2">
<rect key="frame" x="106" y="287" width="202" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="로그인 해보시지" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zsQ-El-PkC">
<rect key="frame" x="82" y="87" width="250" height="87"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="26"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fnZ-6B-4DN">
<rect key="frame" x="161" y="358" width="92" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<state key="normal" title="확인"/>
<connections>
<action selector="okButtonTouched:" destination="acG-MO-tPJ" eventType="touchUpInside" id="jde-2f-lwj"/>
</connections>
</button>
</subviews>
<viewLayoutGuide key="safeArea" id="usz-km-bvy"/>
<color key="backgroundColor" systemColor="systemGray6Color"/>
</view>
<navigationItem key="navigationItem" id="aMp-h1-3sO"/>
<connections>
<outlet property="IDTextField" destination="ump-1U-kn2" id="0Xr-ng-afF"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="XGK-4h-xgL" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="84.057971014492765" y="114.50892857142857"/>
</scene>
<!--Selection View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="SelectionViewController" customModule="baseball_game" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="SelectionViewController" id="BYZ-38-t0r" customClass="SelectionViewController" customModule="baseball_game" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -56,19 +99,41 @@
<constraint firstItem="TEj-De-JFw" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="sdR-iG-9cO"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="pCT-Ol-cD7"/>
<connections>
<outlet property="backgroundView" destination="TEj-De-JFw" id="msw-kk-e3V"/>
<outlet property="gameListTableView" destination="Qom-Qz-GeO" id="3md-l4-Ihh"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="131.8840579710145" y="114.50892857142857"/>
<point key="canvasLocation" x="1042.0289855072465" y="114.50892857142857"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="V5N-W2-hhL">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="bc6-zR-OBT" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="CfT-9w-1yW">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="acG-MO-tPJ" kind="relationship" relationship="rootViewController" id="5nd-sF-m8A"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iIS-6P-iFA" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-826.08695652173924" y="114.50892857142857"/>
</scene>
</scenes>
<resources>
<systemColor name="systemGray5Color">
<color red="0.89803921568627454" green="0.89803921568627454" blue="0.91764705882352937" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGray6Color">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
31 changes: 31 additions & 0 deletions iOS/baseball-game/baseball-game/Network/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,35 @@ class NetworkManager {
})
.eraseToAnyPublisher()
}

static func post<T: Codable>(url: URL, data: T) -> AnyPublisher<Void, Error> {

return Just(data)
.encode(encoder: JSONEncoder())
.mapError { error -> Error in
print(error)
return error
}
.map { data -> URLRequest in
var request = URLRequest(url: url)
request.httpMethod = "post"
request.httpBody = data
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue(String(data.count), forHTTPHeaderField: "Content-Length")

return request
}
.flatMap { request in
return URLSession.shared.dataTaskPublisher(for: request)
.tryMap { element -> Void in
guard let httpResponse = element.response as? HTTPURLResponse,
httpResponse.statusCode == 200 else {
throw NetworkError.BadURL
}
return
}
}
.eraseToAnyPublisher()
}

}
20 changes: 13 additions & 7 deletions iOS/baseball-game/baseball-game/Selection/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@

import Foundation

struct Game: Hashable, Decodable {
let id: Int
let home: Team
let away: Team
struct Game: Codable, Hashable {
var id: Int = 0
var home: Team = Team()
var away: Team = Team()
}

struct Team: Hashable, Decodable {
let team: String
let status: String
struct Team: Codable, Hashable {
var team: String = ""
var status: String = ""
}

struct GameInfo: Codable {
var userID: String = ""
var gameID: Int = 0
var team: String = ""
}
29 changes: 28 additions & 1 deletion iOS/baseball-game/baseball-game/Selection/GameCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ class GameCell: UITableViewCell {
static let reuseIdentifier = "GameCell"
static let nib = UINib(nibName: GameCell.reuseIdentifier, bundle: nil)

private var viewModel: SelectViewModel!

@IBOutlet weak var gameIdLabel: UILabel!
@IBOutlet weak var awayTeamButton: UIButton!
@IBOutlet weak var homeTeamButton: UIButton!

private var gameInfo = GameInfo()
private var awayTeam: String!
private var homeTeam: String!

Expand All @@ -23,13 +26,37 @@ class GameCell: UITableViewCell {
super.awakeFromNib()
}

func fill(state: Game) {
func fill(_ viewModel: SelectViewModel, state: Game) {
self.viewModel = viewModel
self.gameInfo = GameInfo(userID: viewModel.gameInfo.userID, gameID: state.id)

self.gameIdLabel.text = "GAME \(state.id)"
self.awayTeamButton.setTitle(state.away.team, for: .normal)
self.homeTeamButton.setTitle(state.home.team, for: .normal)
self.setIsEnabled(state: state)

self.awayTeam = state.away.team
self.homeTeam = state.home.team
}

private func setIsEnabled(state: Game) {
if state.away.status == "selected" { self.awayTeamButton.isEnabled = false }
if state.home.status == "selected" { self.homeTeamButton.isEnabled = false }
}

@IBAction func awayButtonTouched(_ sender: UIButton) {
self.gameInfo.team = self.awayTeam
self.viewModel.setModel(with: self.gameInfo)
self.viewModel.postSelection(with: self.gameInfo)
self.awayTeamButton.isEnabled = false

}

@IBAction func homeButtonTouched(_ sender: UIButton) {
self.gameInfo.team = self.homeTeam
self.viewModel.setModel(with: self.gameInfo)
self.viewModel.postSelection(with: self.gameInfo)
self.homeTeamButton.isEnabled = false
}

}
6 changes: 6 additions & 0 deletions iOS/baseball-game/baseball-game/Selection/GameCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@
<state key="normal" title="Captin">
<color key="titleColor" systemColor="labelColor"/>
</state>
<connections>
<action selector="awayButtonTouched:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="Bye-JP-eFE"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bGM-8n-Dyj">
<rect key="frame" x="201" y="46" width="168" height="67"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="28"/>
<state key="normal" title="Marvel">
<color key="titleColor" systemColor="labelColor"/>
</state>
<connections>
<action selector="homeButtonTouched:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="l5H-pZ-3eP"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// LoginViewController.swift
// baseball-game
//
// Created by Lia on 2021/05/06.
//

import UIKit

class LoginViewController: UIViewController {

@IBOutlet weak var IDTextField: UITextField!

@IBAction func okButtonTouched(_ sender: UIButton) {
let gameInfo = GameInfo(userID: IDTextField.text ?? "", team: "")

guard let nextVC = storyboard?.instantiateViewController(withIdentifier: "SelectionViewController") as? SelectionViewController else { return }
nextVC.viewModel.setModel(with: gameInfo)
self.navigationController?.pushViewController(nextVC, animated: false)
}

}
21 changes: 21 additions & 0 deletions iOS/baseball-game/baseball-game/Selection/SelectViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ import Foundation
import Combine

class SelectViewModel {
private(set) var gameInfo: GameInfo!
private var cancellable = Set<AnyCancellable>()


func setModel(with gameInfo: GameInfo) {
self.gameInfo = gameInfo
}

//MARK: GET

func request() {
NetworkManager.request(type: [Game].self, url: EndPoint.url(path: "")!)
.receive(on: DispatchQueue.main)
Expand All @@ -33,6 +41,19 @@ class SelectViewModel {
completion(userInfo["games"] ?? [])
}.store(in: &cancellable)
}

//MARK: POST
func postSelection(with gameInfo: GameInfo) {
NetworkManager.post(url: EndPoint.url(path: "")!, data: gameInfo)
.receive(on: DispatchQueue.main)
.sink { error in
print(error)
} receiveValue: { _ in
print("success")
}
.store(in: &cancellable)
}

}

enum NotificationName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class SelectionViewController: UIViewController {
@IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var gameListTableView: UITableView!

let gradientLayer: CAGradientLayer = CAGradientLayer()
private let gradientLayer: CAGradientLayer = CAGradientLayer()

private var viewModel = SelectViewModel()
var viewModel = SelectViewModel()
private var dataSource: UITableViewDiffableDataSource<Section, Game>!


Expand Down Expand Up @@ -55,7 +55,7 @@ extension SelectionViewController {
self.dataSource = UITableViewDiffableDataSource.init(tableView: self.gameListTableView) { (tableView, indexPath, game) -> UITableViewCell in

let cell = self.gameListTableView.dequeueReusableCell(withIdentifier: GameCell.reuseIdentifier) as! GameCell
cell.fill(state: game)
cell.fill(self.viewModel, state: game)

return cell
}
Expand Down

0 comments on commit 37b464a

Please sign in to comment.