-
Notifications
You must be signed in to change notification settings - Fork 69
[Team-11] 새로운 이슈 만들기 기능 추가, DIContainer 에 대한 고찰 #243
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
base: team-11
Are you sure you want to change the base?
Changes from 11 commits
aea9a63
ed0be9c
3611e1a
3c6694a
7753233
60069e4
fb53b06
a17829e
d14a0d7
09d8f7e
b425f41
547ac43
d494374
43aefc6
e24536b
c200084
a30d281
4ec1a9f
48e7ceb
94700a7
f4b1f07
3200b4f
bc006c4
5e8b77a
d2675b2
b398019
b86ec49
1ddb879
d5c4855
709b78b
cf39c51
94f6cb2
2cf9ed0
c5bca22
f1dc0ce
d791820
aaf1c2f
7e9b7ba
3dce5a4
2aa67de
da4fa97
4d2672b
a54d231
7eb9168
50e1cb4
c43f970
7bf8c02
1065a7b
93724ce
300373e
7170c83
9f80da2
e3a03eb
c94cb85
6f7ac28
7e2c599
cf7c960
00867fb
5865265
75a66ca
264ed97
d37d8c9
55b3b87
0d2db84
6e2fcec
448b9dd
f44007b
c5d1b0b
13517eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // | ||
| // Repository.swift | ||
| // IssueTracker | ||
| // | ||
| // Created by Bibi on 2022/06/27. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
|
|
||
| struct Repository: Codable { | ||
| let name: String | ||
| let owner: Owner | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,6 @@ final class IssueViewController: UIViewController { | |
| })) | ||
| button.setImage(UIImage(systemName: "plus"), for: .normal) | ||
|
|
||
| // button.layer.cornerRadius = 50 / 2 | ||
|
|
||
| return button | ||
| }() | ||
|
|
||
|
|
@@ -48,7 +46,7 @@ final class IssueViewController: UIViewController { | |
| setupViews() | ||
| model.requestIssue() | ||
| model.updatedIssues = { [weak self] issues in | ||
| DispatchQueue.main.async { [weak self] in | ||
| DispatchQueue.main.async { [weak self] in | ||
| self?.collectionView.reloadData() | ||
| } | ||
| } | ||
|
|
@@ -64,7 +62,14 @@ final class IssueViewController: UIViewController { | |
| } | ||
|
|
||
| @objc func touchedAddButton() { | ||
| self.navigationController?.pushViewController(Container().buildViewController(.newIssue), animated: true) | ||
| guard let appdelegate = UIApplication.shared.delegate as? AppDelegate else { | ||
|
||
| return | ||
| } | ||
| guard let viewController = appdelegate.container.buildViewController(.newIssue) as? NewIssueViewController else { | ||
| return | ||
| } | ||
| self.navigationController?.pushViewController(viewController, animated: true) | ||
| viewController.delegate = self | ||
|
||
| } | ||
|
|
||
| private func setupNavigationBar() { | ||
|
|
@@ -149,3 +154,9 @@ extension IssueViewController: UICollectionViewDelegateFlowLayout { | |
| return CGSize(width: collectionView.frame.width, height: 200) | ||
| } | ||
| } | ||
|
|
||
| extension IssueViewController: NewIssueCreateDelegate { | ||
| func created() { | ||
| model.requestIssue() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,43 @@ | |
| // | ||
|
|
||
| import UIKit | ||
| import SwiftUI | ||
|
|
||
| protocol NewIssueCreateDelegate: AnyObject { | ||
| func created() | ||
| } | ||
|
|
||
| class NewIssueViewController: UIViewController { | ||
|
|
||
| weak var delegate: NewIssueCreateDelegate? | ||
|
|
||
| private let service = IssueService() | ||
|
|
||
| private let optionList = Option.allCases | ||
| private var selectedList = Array<String>(repeating: "", count: Option.allCases.count) | ||
|
|
||
| private var selectedRepo: Repository? | ||
|
|
||
| enum Option: CaseIterable { | ||
| case repository | ||
| case label | ||
| case milestone | ||
| case assignee | ||
|
|
||
| var description: String { | ||
| switch self { | ||
| case .repository: | ||
| return "저장소" | ||
| case .label: | ||
| return "레이블" | ||
| case .milestone: | ||
| return "마일스톤" | ||
| case .assignee: | ||
| return "담당자" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private lazy var navSegmentedControl: UISegmentedControl = { | ||
| let buttonList = ["마크다운", "미리보기"] | ||
| var control = UISegmentedControl(items: buttonList) | ||
|
|
@@ -38,7 +72,6 @@ class NewIssueViewController: UIViewController { | |
| return devider | ||
| }() | ||
|
|
||
| private let optionList = ["저장소", "레이블", "마일스톤", "담당자"] | ||
| private let optionTableCellIdentifier = "optionTableCellIdentifier" | ||
|
|
||
| private lazy var optionTable: UITableView = { | ||
|
|
@@ -109,7 +142,6 @@ class NewIssueViewController: UIViewController { | |
| make.top.equalTo(horizontalDevider.snp.bottom) | ||
| make.leading.trailing.equalTo(self.view.safeAreaLayoutGuide) | ||
| make.bottom.equalTo(optionTable.snp.top) | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -129,18 +161,53 @@ class NewIssueViewController: UIViewController { | |
| }() | ||
|
|
||
| private func touchedCreateButton() { | ||
| // TODO: 이슈생성 | ||
| //1. api 호출 | ||
| //2. api 가 성공적으로 응답을 보내줬다면 => | ||
| //2-1. 이전 화면으로 돌아가고 | ||
| //2-2. 이슈 목록 조회 다시해서 보여주기 | ||
| //3. api 가 실패했다면 => issue 생성실패 얼럿띄우기 | ||
|
|
||
| guard let token = GithubUserDefaults.getToken(), | ||
| let selectedRepo = selectedRepo else { | ||
| return | ||
| } | ||
| guard let titleString = self.titleField.text, | ||
| !titleString.isEmpty else { | ||
| // TODO: - 타이틀 입력 값이 없다 => 얼럿 | ||
| return | ||
| } | ||
|
|
||
| service.createIssue(title: titleString, repo: selectedRepo, accessToken: token) { boolResult in | ||
| if boolResult { | ||
| self.navigationController?.popViewController(animated: true) | ||
| self.delegate?.created() | ||
| } | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| extension NewIssueViewController: UITableViewDelegate { | ||
|
|
||
| func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
| switch optionList[indexPath.row] { | ||
| case .repository: | ||
| // TODO: issueService의 requestRepos() 연결해서 저장소목록 보여주기 | ||
| guard let appdelegate = UIApplication.shared.delegate as? AppDelegate, | ||
| let token = GithubUserDefaults.getToken() else { | ||
| return | ||
| } | ||
|
|
||
| service.requestRepos(accessToken: token) { result in | ||
| switch result { | ||
| case .success(let repositoryList): | ||
| guard let viewController = appdelegate.container.buildViewController(.optionSelect(token: token, repositories: repositoryList)) as? OptionSelectViewController else { | ||
| return | ||
| } | ||
| self.navigationController?.pushViewController(viewController, animated: true) | ||
| viewController.delegate = self | ||
| case .failure(let error): | ||
| print(error) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| default: | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension NewIssueViewController: UITableViewDataSource { | ||
|
|
@@ -152,8 +219,8 @@ extension NewIssueViewController: UITableViewDataSource { | |
| let cell = tableView.dequeueReusableCell(withIdentifier: optionTableCellIdentifier, | ||
| for: indexPath) | ||
| var sidebarCell = UIListContentConfiguration.sidebarCell() | ||
| sidebarCell.text = optionList[indexPath.item] | ||
| sidebarCell.secondaryText = "선택내용" | ||
| sidebarCell.text = optionList[indexPath.item].description | ||
| sidebarCell.secondaryText = selectedList[indexPath.item] | ||
| sidebarCell.prefersSideBySideTextAndSecondaryText = true | ||
|
|
||
| cell.contentConfiguration = sidebarCell | ||
|
|
@@ -162,3 +229,11 @@ extension NewIssueViewController: UITableViewDataSource { | |
| } | ||
|
|
||
| } | ||
|
|
||
| extension NewIssueViewController: OptionSelectDelegate { | ||
| func selected(item: Repository) { | ||
| selectedList[0] = item.name | ||
| selectedRepo = item | ||
| self.optionTable.reloadData() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,30 @@ | ||
| import UIKit | ||
| import SnapKit | ||
|
|
||
| class OptionSelectViewController: UIViewController { | ||
| protocol OptionSelectDelegate: AnyObject { | ||
| func selected(item: Repository) | ||
| } | ||
|
|
||
| private let dummy = ["bug", "feature", "document"] | ||
| class OptionSelectViewController: UIViewController { | ||
|
|
||
| weak var delegate: OptionSelectDelegate? | ||
|
|
||
| private let service = IssueService() | ||
| private var token: String? | ||
| private var options: [Repository]? | ||
|
|
||
| private let tableViewCellIdentifier = "tableViewCellIdentifier" | ||
|
|
||
| init(token: String, options: [Repository]) { | ||
| super.init(nibName: nil, bundle: nil) | ||
| self.token = token | ||
|
||
| self.options = options | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| super.init(coder: coder) | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| setupViews() | ||
|
|
@@ -32,20 +51,31 @@ class OptionSelectViewController: UIViewController { | |
|
|
||
| extension OptionSelectViewController: UITableViewDelegate { | ||
| func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
| // TODO: - 선택한 옵션을 이전 ViewController 에 넘겨주기 | ||
| guard let options = options else { | ||
| return | ||
| } | ||
| let selectedItem = options[indexPath.row] | ||
| delegate?.selected(item: selectedItem) | ||
| self.navigationController?.popViewController(animated: true) | ||
|
||
| } | ||
| } | ||
|
|
||
| extension OptionSelectViewController: UITableViewDataSource { | ||
| func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
| return dummy.count | ||
| guard let options = options else { | ||
| return 0 | ||
| } | ||
| return options.count | ||
| } | ||
|
|
||
| func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
| guard let options = options else { | ||
| return UITableViewCell() | ||
| } | ||
| let cell = tableView.dequeueReusableCell(withIdentifier: tableViewCellIdentifier, | ||
| for: indexPath) | ||
| var content = cell.defaultContentConfiguration() | ||
| content.attributedText = NSAttributedString(string: dummy[indexPath.row]) | ||
| content.attributedText = NSAttributedString(string: options[indexPath.row].name) | ||
| cell.contentConfiguration = content | ||
| return cell | ||
| } | ||
|
|
||
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.
프라이빗을 푸신 이유가 싱글톤에서 접근하게 만들기 위해서 일까요??
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.
앗..흔적이 남아있네요😅
Container를 써야 하는 곳은 많은데 객체는 하나만 만들고 싶어서, 싱글톤을 적용해보려 했다가
지난 PR에 static 객체에 접근하기보다는 다른 방법을 사용해보라고 하셨던게 생각나서 싱글톤 없이 해보려고 방향을 바꾸었습니다.
그러다가 (바로 아래와 같은) 더 안 좋은 상황이 발생한 것 같네요..🥲