Skip to content

Commit

Permalink
[Jinsujin/issue-tracker] #28 Feat: NewIssueModel에 service 전체 대신, 필요한 …
Browse files Browse the repository at this point in the history
…클로저만 environment로 주입
  • Loading branch information
bibi6666667 committed Jul 21, 2022
1 parent d791820 commit aaf1c2f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions IssueTracker/IssueTracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@
983E66C4285B204600C9B975 /* Storage */,
985CAB45285C19D0005E709D /* Extension */,
985CAB4A28603AD3005E709D /* GitHub */,
983E66CA285B2AD300C9B975 /* Entity */,
985CAB5128606898005E709D /* Login */,
9844C191286C802000D0CFC9 /* Repos */,
983E66CA285B2AD300C9B975 /* Entity */,
000B92BF286D67C6009EB2D8 /* NewIssue */,
981BD438285B123A00DDDE64 /* Issue */,
000B92BF286D67C6009EB2D8 /* NewIssue */,
000B92C5286D6F85009EB2D8 /* OptionSelect */,
988510D528572B8700CC2DA9 /* AppDelegate.swift */,
988510DE28572B8900CC2DA9 /* Assets.xcassets */,
Expand Down
2 changes: 1 addition & 1 deletion IssueTracker/IssueTracker/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Container {
let viewController = IssueViewController(model: model, repo: selectedRepo) // Issue -> Issues
return viewController
case .newIssue(let repo):
let model = NewIssueModel(service: service)
let model = NewIssueModel(environment: .init(createIssue: environment.issueService.createIssue(title:repo:content:label:milestone:assignee:completion:)))
return NewIssueViewController(repo: repo, model: model)
case .optionSelect(let option, let repo):
let model = OptionSelectModel(service: service)
Expand Down
12 changes: 8 additions & 4 deletions IssueTracker/IssueTracker/NewIssue/Model/NewIssueModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import Foundation

class NewIssueModel {

private let service: IssueService
private let environment: NewIssueModelEnvironment

init(service: IssueService) {
self.service = service
init(environment: NewIssueModelEnvironment) {
self.environment = environment
}

func createIssue(title: String, repo: Repository, content: String, label: Label?, milestone: Milestone?, assignee: Assignee?, completion: @escaping (Bool) -> Void) {
service.createIssue(title: title, repo: repo, content: content, label: label, milestone: milestone, assignee: assignee) { boolResult in
environment.createIssue(title, repo, content, label, milestone, assignee) { boolResult in
completion(boolResult)
}
}
}

struct NewIssueModelEnvironment {
let createIssue: (String, Repository, String, Label?, Milestone?, Assignee?, @escaping (Bool) -> Void) -> Void
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class NewIssueViewController: UIViewController {
required convenience init?(coder: NSCoder) {

let owner = Owner(login: "")
let service = IssueService(token: "")
let model = NewIssueModel(service: service)
let modelEnvironment = NewIssueModelEnvironment(createIssue: { _, _, _, _, _, _, _ in
})
let model = NewIssueModel(environment: modelEnvironment)
self.init(repo: Repository(name: "",
owner: owner),
model: model)
Expand Down
7 changes: 0 additions & 7 deletions IssueTracker/IssueTracker/Repos/ReposViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ class ReposViewController: UIViewController {
setupViews()
// 뷰컨 자신에 대한 셋팅 코드는 뷰컨을 만드는 Container에서 해준다 (추후 Coordinator로 분리)
self.view.backgroundColor = .white
// self.title = "Repos"
// model.fetchViewData()
// model.updated = { [weak self] repos in
// DispatchQueue.main.async {
// self?.tableView.reloadData()
// }
// }
}

func reloadTableView() {
Expand Down

0 comments on commit aaf1c2f

Please sign in to comment.