Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

박스오피스 [Step2-3] Toy,Morgan #123

Open
wants to merge 8 commits into
base: ic_10_morgan
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.DS_Store
BoxOffice.xcodeproj/project.xcworkspace/xcuserdata/kimwoohyeon.xcuserdatad/UserInterfaceState.xcuserstate
64 changes: 50 additions & 14 deletions BoxOffice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,23 @@
objects = {

/* Begin PBXBuildFile section */
3C3E80152B148FBC002AF4A2 /* MovieDataDecoerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C3E80142B148FBC002AF4A2 /* MovieDataDecoerTests.swift */; };
3C4D67212B15848900B8926A /* BoxOffice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4D67202B15848900B8926A /* BoxOffice.swift */; };
3C6A18D22B18790400E1DBC2 /* Movie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6A18D12B18790400E1DBC2 /* Movie.swift */; };
3C6A18D42B18832E00E1DBC2 /* MovieURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6A18D32B18832E00E1DBC2 /* MovieURL.swift */; };
3C8280862B29AE7C0083DD64 /* BoxOfficeData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C8280852B29AE7C0083DD64 /* BoxOfficeData.swift */; };
3CAFE2012B2AE9FC006DF36E /* MovieDetailData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CAFE2002B2AE9FC006DF36E /* MovieDetailData.swift */; };
3CB861712B21E824003113C1 /* DateGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB861702B21E824003113C1 /* DateGenerator.swift */; };
3CFF21642B28551C006B7A36 /* URLError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CFF21632B28551C006B7A36 /* URLError.swift */; };
3CFF21662B285567006B7A36 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CFF21652B285567006B7A36 /* Endpoint.swift */; };
3CFF21682B28558A006B7A36 /* HTTPHeaderField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CFF21672B28558A006B7A36 /* HTTPHeaderField.swift */; };
3CFF216A2B2855A7006B7A36 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CFF21692B2855A7006B7A36 /* HTTPMethod.swift */; };
63DF20EF2970E1A0005DF7D1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63DF20EE2970E1A0005DF7D1 /* AppDelegate.swift */; };
63DF20F12970E1A0005DF7D1 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63DF20F02970E1A0005DF7D1 /* SceneDelegate.swift */; };
63DF20F32970E1A0005DF7D1 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63DF20F22970E1A0005DF7D1 /* ViewController.swift */; };
63DF20F62970E1A0005DF7D1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 63DF20F42970E1A0005DF7D1 /* Main.storyboard */; };
63DF20F82970E1A1005DF7D1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 63DF20F72970E1A1005DF7D1 /* Assets.xcassets */; };
63DF20FB2970E1A1005DF7D1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 63DF20F92970E1A1005DF7D1 /* LaunchScreen.storyboard */; };
9239D0472B148D400008DE9F /* excuteError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9239D0462B148D400008DE9F /* excuteError.swift */; };
9239D0472B148D400008DE9F /* NetworkManagerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9239D0462B148D400008DE9F /* NetworkManagerError.swift */; };
926CEE4E2B1C5787002B3FFE /* Key.swift in Sources */ = {isa = PBXBuildFile; fileRef = 926CEE4D2B1C5787002B3FFE /* Key.swift */; };
92882BDF2B171A7F007AEA40 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92882BDE2B171A7F007AEA40 /* NetworkManager.swift */; };
92AC83F82B21C30400D10264 /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92AC83F72B21C30400D10264 /* API.swift */; };
Expand All @@ -36,11 +41,16 @@

/* Begin PBXFileReference section */
3C3E80122B148FBC002AF4A2 /* MovieDataDecoerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MovieDataDecoerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3C3E80142B148FBC002AF4A2 /* MovieDataDecoerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDataDecoerTests.swift; sourceTree = "<group>"; };
3C4D67202B15848900B8926A /* BoxOffice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxOffice.swift; sourceTree = "<group>"; };
3C6A18D12B18790400E1DBC2 /* Movie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Movie.swift; sourceTree = "<group>"; };
3C6A18D32B18832E00E1DBC2 /* MovieURL.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieURL.swift; sourceTree = "<group>"; };
3C8280852B29AE7C0083DD64 /* BoxOfficeData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BoxOfficeData.swift; sourceTree = "<group>"; };
3CAFE2002B2AE9FC006DF36E /* MovieDetailData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailData.swift; sourceTree = "<group>"; };
3CB861702B21E824003113C1 /* DateGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateGenerator.swift; sourceTree = "<group>"; };
3CFF21632B28551C006B7A36 /* URLError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLError.swift; sourceTree = "<group>"; };
3CFF21652B285567006B7A36 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
3CFF21672B28558A006B7A36 /* HTTPHeaderField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPHeaderField.swift; sourceTree = "<group>"; };
3CFF21692B2855A7006B7A36 /* HTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = "<group>"; };
63DF20EB2970E1A0005DF7D1 /* BoxOffice.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BoxOffice.app; sourceTree = BUILT_PRODUCTS_DIR; };
63DF20EE2970E1A0005DF7D1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
63DF20F02970E1A0005DF7D1 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -49,7 +59,7 @@
63DF20F72970E1A1005DF7D1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
63DF20FA2970E1A1005DF7D1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
63DF20FC2970E1A1005DF7D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9239D0462B148D400008DE9F /* excuteError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = excuteError.swift; sourceTree = "<group>"; };
9239D0462B148D400008DE9F /* NetworkManagerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManagerError.swift; sourceTree = "<group>"; };
926CEE4D2B1C5787002B3FFE /* Key.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Key.swift; sourceTree = "<group>"; };
92882BDE2B171A7F007AEA40 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
92AC83F72B21C30400D10264 /* API.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -82,30 +92,34 @@
path = Model;
sourceTree = "<group>";
};
3C3E80132B148FBC002AF4A2 /* MovieDataDecoerTests */ = {
3C8280842B29AD2A0083DD64 /* HTTP */ = {
isa = PBXGroup;
children = (
3C3E80142B148FBC002AF4A2 /* MovieDataDecoerTests.swift */,
3CFF21672B28558A006B7A36 /* HTTPHeaderField.swift */,
3CFF21692B2855A7006B7A36 /* HTTPMethod.swift */,
);
path = MovieDataDecoerTests;
path = HTTP;
sourceTree = "<group>";
};
3CD5DDAD2B171CF30013E5C0 /* Network */ = {
isa = PBXGroup;
children = (
928029CD2B2AEFBA007D604E /* NameSpace */,
928029CC2B2AEF94007D604E /* Data */,
3C8280842B29AD2A0083DD64 /* HTTP */,
3CB861702B21E824003113C1 /* DateGenerator.swift */,
92882BDE2B171A7F007AEA40 /* NetworkManager.swift */,
3C6A18D32B18832E00E1DBC2 /* MovieURL.swift */,
926CEE4D2B1C5787002B3FFE /* Key.swift */,
3CFF21652B285567006B7A36 /* Endpoint.swift */,
92AC83F72B21C30400D10264 /* API.swift */,
3CB861702B21E824003113C1 /* DateGenerator.swift */,
);
path = Network;
sourceTree = "<group>";
};
3CD5DDAE2B1722810013E5C0 /* Error */ = {
isa = PBXGroup;
children = (
9239D0462B148D400008DE9F /* excuteError.swift */,
9239D0462B148D400008DE9F /* NetworkManagerError.swift */,
3CFF21632B28551C006B7A36 /* URLError.swift */,
);
path = Error;
sourceTree = "<group>";
Expand Down Expand Up @@ -133,7 +147,6 @@
isa = PBXGroup;
children = (
63DF20ED2970E1A0005DF7D1 /* BoxOffice */,
3C3E80132B148FBC002AF4A2 /* MovieDataDecoerTests */,
63DF20EC2970E1A0005DF7D1 /* Products */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -161,6 +174,24 @@
path = BoxOffice;
sourceTree = "<group>";
};
928029CC2B2AEF94007D604E /* Data */ = {
isa = PBXGroup;
children = (
3C8280852B29AE7C0083DD64 /* BoxOfficeData.swift */,
3CAFE2002B2AE9FC006DF36E /* MovieDetailData.swift */,
);
path = Data;
sourceTree = "<group>";
};
928029CD2B2AEFBA007D604E /* NameSpace */ = {
isa = PBXGroup;
children = (
3C6A18D32B18832E00E1DBC2 /* MovieURL.swift */,
926CEE4D2B1C5787002B3FFE /* Key.swift */,
);
path = NameSpace;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -262,7 +293,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3C3E80152B148FBC002AF4A2 /* MovieDataDecoerTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -271,10 +301,16 @@
buildActionMask = 2147483647;
files = (
3CB861712B21E824003113C1 /* DateGenerator.swift in Sources */,
3C8280862B29AE7C0083DD64 /* BoxOfficeData.swift in Sources */,
92AC83F82B21C30400D10264 /* API.swift in Sources */,
9239D0472B148D400008DE9F /* excuteError.swift in Sources */,
3CFF21642B28551C006B7A36 /* URLError.swift in Sources */,
3CFF21662B285567006B7A36 /* Endpoint.swift in Sources */,
9239D0472B148D400008DE9F /* NetworkManagerError.swift in Sources */,
926CEE4E2B1C5787002B3FFE /* Key.swift in Sources */,
3CAFE2012B2AE9FC006DF36E /* MovieDetailData.swift in Sources */,
3C6A18D42B18832E00E1DBC2 /* MovieURL.swift in Sources */,
3CFF21682B28558A006B7A36 /* HTTPHeaderField.swift in Sources */,
3CFF216A2B2855A7006B7A36 /* HTTPMethod.swift in Sources */,
63DF20F32970E1A0005DF7D1 /* ViewController.swift in Sources */,
63DF20EF2970E1A0005DF7D1 /* AppDelegate.swift in Sources */,
92882BDF2B171A7F007AEA40 /* NetworkManager.swift in Sources */,
Expand Down
Binary file not shown.
Binary file not shown.
61 changes: 13 additions & 48 deletions BoxOffice/Controllers/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,24 @@
import UIKit

class ViewController: UIViewController {

private var networkManager = NetworkManager()
private let data = BoxOfficeData()
private let detail = MovieDetailData(value: "20190324")

override func viewDidLoad() {
super.viewDidLoad()
networkTest()
boxOfiiceData()
movieDetailData()
}

func networkTest() {
let dailyBoxOfficeAPI = API(schema: MovieURL.schema, host: MovieURL.movieHost, path: MovieURL.boxofficePath)

let dailyBoxOfficeAPIAdditionalQueryItems: [URLQueryItem] = [
URLQueryItem(name: "targetDt", value: DateGenerator.fetchTodayDate())
]

let apiKey = Key.movieDataApiKey

var movieCode = ""

let group = DispatchGroup()

group.enter()
networkManager.executeRequest(api: dailyBoxOfficeAPI, apiKey: apiKey, queryItems: dailyBoxOfficeAPIAdditionalQueryItems, type: BoxOffice.self, complitionHandler: { result in
defer {group.leave()}

switch result {
case .success(let safeData):
let data = safeData.boxOfficeResult.dailyBoxOfficeList
data.forEach {dump($0)}
movieCode = data[0].movieCode
case .failure(let error):
print("\(error)에러발생")
}
})


group.notify(queue: .main) {
let movieDetailAPI = API(schema: MovieURL.schema, host: MovieURL.movieHost, path: MovieURL.movieDetailPath)

let movieDetailAPIAdditionalQueryItems: [URLQueryItem] = [
URLQueryItem(name: "movieCd", value: movieCode)
]

self.networkManager.executeRequest(api: movieDetailAPI, apiKey: apiKey, queryItems: movieDetailAPIAdditionalQueryItems, type: Movie.self) { result in
switch result {
case .success(let safeData):
let data = safeData.infomationResult.movieInfomation
print(data)

case .failure(let error):
print("\(error)에러발생")
}
}
private func boxOfiiceData() {
data.getBoxOfficeData { result in
result.forEach { dump($0) }
}
}

private func movieDetailData() {
detail.getMovieDetailData { movie in
dump(movie)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
//
// DecodingError.swift
// NetworkManagerError.swift
// BoxOffice
//
// Created by Toy, Morgan on 11/27/23.
//

import Foundation

enum ExecuteRequestError: Error {
case invalidURL
enum NetworkManagerError: Error {
case urlSessionError
case responseError
case invalidData
case decodeError
}

extension ExecuteRequestError: LocalizedError {
extension NetworkManagerError: LocalizedError {
var errorDescription: String? {
switch self {
case .invalidURL:
return "유효하지 않은 URL"
case .urlSessionError:
return "URLSession에 대한"
case .responseError:
Expand Down
21 changes: 21 additions & 0 deletions BoxOffice/Error/URLError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// URLError.swift
// BoxOffice
//
// Created by Toy, Morgan on 12/12/23.
//

import Foundation

enum URLError: Error {
case invalidURL
}

extension URLError: LocalizedError {
var errorDescription: String? {
switch self {
case .invalidURL:
return "유효하지 않은 URL"
}
}
}
8 changes: 4 additions & 4 deletions BoxOffice/Network/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// API.swift
// BoxOffice
//
// Created by hyunMac on 12/7/23.
// Created by Toy, Morgan on 12/7/23.
//

import Foundation

struct API {
let schema: String
let host: String
let path: String
private let schema: String
private let host: String
private let path: String

init(schema: String, host: String, path: String) {
self.schema = schema
Expand Down
30 changes: 30 additions & 0 deletions BoxOffice/Network/Data/BoxOfficeData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DataManager.swift
// BoxOffice
//
// Created by Toy, Morgan on 12/13/23.
//

import Foundation

struct BoxOfficeData {
private let networkManager = NetworkManager()
private let boxofficeAPI = API(schema: MovieURL.schema, host: MovieURL.movieHost, path: MovieURL.boxofficePath)
private let boxOfficeAPIAdditionalQueryItems = [ URLQueryItem(name: "targetDt", value: DateGenerator.fetchTodayDate()) ]

private var getEndpoint: Endpoint {
Endpoint(api: boxofficeAPI, queryItems: boxOfficeAPIAdditionalQueryItems, httpMethod: .get, httpHeaderField: .contentType)
}

func getBoxOfficeData(complitionHandler: @escaping ([DailyBoxOfficeItem]) -> Void) {
networkManager.executeRequest(endponit: getEndpoint, type: BoxOffice.self) { result in
switch result {
case .success(let safeData):
let data = safeData.boxOfficeResult.dailyBoxOfficeList
complitionHandler(data)
case .failure(let error):
print("\(error)에러발생")
}
}
}
}
43 changes: 43 additions & 0 deletions BoxOffice/Network/Data/MovieDetailData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// MovieDetailData.swift
// BoxOffice
//
// Created by Toy, Morgan on 12/14/23.
//

import Foundation

//endpoint
//
//api: API,
//queryItems:[URLQueryItem],
//var request = URLRequest(url: url)
//request.httpMethod = "GET"
//request.addValue("application/json", forHTTPHeaderField: "Content-Type")
//json

struct MovieDetailData {
private let networkManager = NetworkManager()
private let movieDetailAPI = API(schema: MovieURL.schema, host: MovieURL.movieHost, path: MovieURL.movieDetailPath)
private var movieDetailAPIAdditionalQueryItems: [URLQueryItem]

private var getEndpoint: Endpoint {
Endpoint(api: movieDetailAPI, queryItems: movieDetailAPIAdditionalQueryItems, httpMethod: .get, httpHeaderField: .contentType)
}

init(value: String) {
movieDetailAPIAdditionalQueryItems = [ URLQueryItem(name: "movieCd", value: value) ]
}

func getMovieDetailData(complitionHandler: @escaping (MovieInfomation) -> Void) {
networkManager.executeRequest(endponit: getEndpoint, type: Movie.self) { result in
switch result {
case .success(let safeData):
let data = safeData.infomationResult.movieInfomation
complitionHandler(data)
case .failure(let error):
print("\(error)에러발생")
}
}
}
}
2 changes: 1 addition & 1 deletion BoxOffice/Network/DateGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// DateGenerator.swift
// BoxOffice
//
// Created by on 12/7/23.
// Created by Toy, Morgan on 12/7/23.
//

import Foundation
Expand Down
Loading