-
Notifications
You must be signed in to change notification settings - Fork 0
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
[7차 세미나] 리펙토링 #8
Open
kim-seonwoo
wants to merge
10
commits into
main
Choose a base branch
from
#7-7rdSeminar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7103195
[Add/#7] 파일 추가
kim-seonwoo 2fb947f
[Feat/#7] SceneDelegate 의존성 주입
kim-seonwoo bb220ae
[Feat/#7] DataSource 구현
kim-seonwoo 9b33e13
[Feat/#7] Repository 구현
kim-seonwoo 28678a3
[Feat/#7] Entity 구현
kim-seonwoo b267f34
[Feat/#7] ContentUseCase 구현
kim-seonwoo abfbc4f
[Fix/#7] DTO 수정
kim-seonwoo 36e9761
[Fix/#7] Presentation 형식에 맞게 수정
kim-seonwoo 69bda45
[Fix/#7] 자잘한 수정
kim-seonwoo 9e7c121
[Add/#7] DIContainer
kim-seonwoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// AppDIContainer.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
final class AppDIContainer { | ||
|
||
func makeContentSceneDIContainer() -> ContentDIContainer { | ||
let dependencies = ContentDIContainer.Dependencies(contentDataSource: ContentDataSource()) | ||
return ContentDIContainer(dependencies: dependencies) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Tving-Clone/Tving-Clone/Application/ContentDIContainer.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,41 @@ | ||
// | ||
// DIConteainer.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
final class ContentDIContainer { | ||
|
||
struct Dependencies { | ||
let contentDataSource: ContentDataSource | ||
} | ||
|
||
private let dependencies: Dependencies | ||
|
||
init(dependencies: Dependencies) { | ||
self.dependencies = dependencies | ||
} | ||
|
||
func makeContentRepository() -> ContentRepository { | ||
return DefaultContentRepository(contentDataSource: dependencies.contentDataSource) | ||
} | ||
|
||
func makeContentUseCase() -> ContentUseCase { | ||
return DefaultContentUseCase(repository: makeContentRepository()) | ||
} | ||
|
||
func makeMainContentViewModel() -> MainContentViewModel { | ||
return MainContentViewModel(contentUseCase: makeContentUseCase()) | ||
} | ||
|
||
func makeMainContentViewController() -> MainContentViewController { | ||
return MainContentViewController(viewModel: makeMainContentViewModel()) | ||
} | ||
|
||
func makeTabBarController() -> TabBarController { | ||
return TabBarController(mainContentViewModel: makeMainContentViewModel()) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,16 +10,19 @@ import UIKit | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
let appDIContainer = AppDIContainer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 의존성 분리 수고하셨습니다!! |
||
|
||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | ||
guard let windowScene = (scene as? UIWindowScene) else { return } | ||
self.window = UIWindow(windowScene: windowScene) | ||
let navigationController = UINavigationController(rootViewController: TabBarController()) | ||
self.window?.rootViewController = navigationController | ||
self.window?.makeKeyAndVisible() | ||
} | ||
|
||
let contentSceneDIContainer = appDIContainer.makeContentSceneDIContainer() | ||
let tabBarController = contentSceneDIContainer.makeTabBarController() | ||
|
||
window = UIWindow(windowScene: windowScene) | ||
window?.rootViewController = UINavigationController(rootViewController: tabBarController) | ||
window?.makeKeyAndVisible() | ||
} | ||
|
||
func sceneDidDisconnect(_ scene: UIScene) { | ||
// Called as the scene is being released by the system. | ||
// This occurs shortly after the scene enters the background, or when its session is discarded. | ||
|
81 changes: 81 additions & 0 deletions
81
Tving-Clone/Tving-Clone/Data/DataSources/ContentDataSource.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,81 @@ | ||
// | ||
// ContentDataSource.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
class ContentDataSource { | ||
private var movieProvider = MoyaProvider<MovieTargetType>(plugins: [MoyaLoggingPlugin()]) | ||
} | ||
|
||
extension ContentDataSource { | ||
func getMovieInfo(completion: @escaping (Result<[Content], Error>) -> Void) { | ||
movieProvider.request(.getMovieData) { result in | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
do { | ||
let networkResult = try self.judgeStatus(by: statusCode, data, MovieResponseDTO.self).toDomain() | ||
completion(.success(networkResult)) | ||
} catch { | ||
completion(.failure(error)) | ||
} | ||
case .failure(let error): | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
func getDetailInfo(code: String, completion: @escaping (Result<ContentDetail, Error>) -> Void) { | ||
movieProvider.request(.getDetailData(code: code)) { result in | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
do { | ||
let networkResult = try self.judgeStatus(by: statusCode, data, DetailResponseDTO.self).toDomain() | ||
completion(.success(networkResult)) | ||
} catch { | ||
completion(.failure(error)) | ||
} | ||
case .failure(let error): | ||
completion(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
private func judgeStatus<T: Codable>(by statusCode: Int, _ data: Data, _ object: T.Type) throws -> T { | ||
switch statusCode { | ||
case 200..<205: | ||
return try isValidData(data: data, T.self) | ||
case 400..<500: | ||
throw NetworkError.requestError | ||
case 500: | ||
throw NetworkError.serverError | ||
default: | ||
throw NetworkError.networkFailure | ||
} | ||
} | ||
|
||
private func isValidData<T: Codable>(data: Data, _ object: T.Type) throws -> T { | ||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(T.self, from: data) else { | ||
print("⛔️ 디코딩 오류가 발생했습니다 ⛔️") | ||
throw NetworkError.decodingError | ||
} | ||
return decodedData | ||
} | ||
} | ||
|
||
enum NetworkError: Error { | ||
case requestError | ||
case serverError | ||
case networkFailure | ||
case decodingError | ||
} |
29 changes: 29 additions & 0 deletions
29
Tving-Clone/Tving-Clone/Data/Repositories/DefaultContentRepository.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,29 @@ | ||
// | ||
// DefaultContentRepository.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import Moya | ||
|
||
final class DefaultContentRepository { | ||
|
||
private let contentDataSource: ContentDataSource | ||
|
||
init(contentDataSource: ContentDataSource) { | ||
self.contentDataSource = contentDataSource | ||
} | ||
} | ||
|
||
extension DefaultContentRepository: ContentRepository { | ||
func getMovieInfo(completion: @escaping (Result<[Content], any Error>) -> Void) { | ||
contentDataSource.getMovieInfo(completion: completion) | ||
} | ||
|
||
func getDetailInfo(code: String, completion: @escaping (Result<ContentDetail, any Error>) -> Void) { | ||
contentDataSource.getDetailInfo(code: code, completion: completion) | ||
} | ||
} |
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,20 @@ | ||
// | ||
// Movie.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Content { | ||
let data: [ContentData] | ||
} | ||
|
||
struct ContentData { | ||
let image: String | ||
var title: String | ||
var maker: String | ||
var subTitle: String | ||
var ratio: String | ||
} |
9 changes: 4 additions & 5 deletions
9
.../Tving-Clone/Models/DetailDataModel.swift → ...Clone/Domain/Entities/ContentDetail.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
13 changes: 13 additions & 0 deletions
13
Tving-Clone/Tving-Clone/Domain/Repositories/ContentRepository.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,13 @@ | ||
// | ||
// ContentRepository.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ContentRepository { | ||
func getMovieInfo(completion: @escaping (Result<[Content], Error>) -> Void) | ||
func getDetailInfo(code: String, completion: @escaping (Result<ContentDetail, Error>) -> Void) | ||
} | ||
Comment on lines
+8
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 프로토콜 선언은 이렇게 하는거군요! 잘 보고 갑니다 :) |
32 changes: 32 additions & 0 deletions
32
Tving-Clone/Tving-Clone/Domain/UseCases/ContentUseCase.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,32 @@ | ||
// | ||
// FetchContentUseCase.swift | ||
// Tving-Clone | ||
// | ||
// Created by Seonwoo Kim on 6/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol ContentUseCase { | ||
func fetchContent(completion: @escaping (Result<[Content], Error>) -> Void) | ||
func fetchContentDetail(code: String, completion: @escaping (Result<ContentDetail, Error>) -> Void) | ||
} | ||
|
||
final class DefaultContentUseCase { | ||
|
||
private let repository: ContentRepository | ||
|
||
init(repository: ContentRepository) { | ||
self.repository = repository | ||
} | ||
} | ||
|
||
extension DefaultContentUseCase: ContentUseCase { | ||
func fetchContent(completion: @escaping (Result<[Content], any Error>) -> Void) { | ||
repository.getMovieInfo(completion: completion) | ||
} | ||
|
||
func fetchContentDetail(code: String, completion: @escaping (Result<ContentDetail, any Error>) -> Void) { | ||
repository.getDetailInfo(code: code, completion: completion) | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와! 의존성분리를 하시다니 진짜 본격적으로 하셧군요! 역시 빡고수,,