From b0852aa6522b9858ab583399b7e68d74b6f9ab3e Mon Sep 17 00:00:00 2001 From: SojinLee <513sojin@naver.com> Date: Sat, 23 Jul 2022 06:11:20 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Feat]=20=EC=83=81=EC=84=B8=EB=B3=B4?= =?UTF-8?q?=EA=B8=B0=20->=20=EC=88=98=EC=A0=95=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecordViewController.swift | 34 ++++++++++++------- ...ecordDetailBottomSheetViewController.swift | 12 +++++++ .../RecordDetailViewController.swift | 6 ++++ .../RecordDetailBottomSheetViewController.xib | 3 ++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift index 2cabea8..b276dd8 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift @@ -170,6 +170,7 @@ class RecordViewController: BaseViewController { var isCreateView: Bool = true var emotionSelectedArray = [false, false, false, false, false, false] // var reviseRecordInfo = [] // 서버에서 받아올 값. 모델이랑 매칭해주어야 함 + var recordDetailData: RecordDetailModel? // MARK: - life cycle override func viewDidLoad() { @@ -188,7 +189,8 @@ class RecordViewController: BaseViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) resetStatus() - setReviseView() + setEditView() + setBackground() } // MARK: - Functions @@ -196,22 +198,28 @@ class RecordViewController: BaseViewController { headerView.setHeaderView(HiddenMoreBtn: true, headerLabelText: "기록하기") } - private func setReviseView() { + private func setEditView() { + print("----------------------") + print(recordDetailData) if !isCreateView { //MARK: - 수정하기 뷰인경우 - //날짜, 제목 , 내용 , 감정, 꿈색상, 장르, 노트 headerView.headerLabel.text = "수정하기" - dateView.recordDateLabel.text = "2022-07-24" - titleTextField.text = "소진이당 ㅋㅋ" - contentTextView.text = "내용이당 ㅋㅋ" - noteTextView.text = "노트내용이다 ㅋㅋ" - CreateRecordConst.emotionNum = 4 - CreateRecordConst.dreamColorNum = 3 - CreateRecordConst.isTouchedIndex = [3] + dateView.recordDateLabel.text = recordDetailData?.date + titleTextField.text = recordDetailData?.title + contentTextView.text = recordDetailData?.content + noteTextView.text = recordDetailData?.note + CreateRecordConst.todayDate = Date() + CreateRecordConst.emotionNum = recordDetailData?.emotion + CreateRecordConst.dreamColorNum = recordDetailData?.dream_color + CreateRecordConst.isTouchedIndex = recordDetailData?.genre ?? [3] contentLable.isHidden = true setTitleTextField() } } + private func setBackground() { + view.backgroundColor = ColorType.darkBlue01.color + } + private func setDelegate() { headerView.delegate = self emotionCollectionView.delegate = self @@ -333,10 +341,12 @@ class RecordViewController: BaseViewController { let record = CreateRecord(title: title, date: date, content: content, emotion: CreateRecordConst.emotionNum, dreamColor: CreateRecordConst.dreamColorNum, genre: CreateRecordConst.isTouchedIndex, note: note, voice: "62cdb868c3032f2b7af76531", writer: "62c9cf068094605c781a2fb9") guard let emotionNum = CreateRecordConst.emotionNum, - let dreamNum = CreateRecordConst.dreamColorNum else { return } + let dreamNum = CreateRecordConst.dreamColorNum, + let id = recordDetailData?._id else { return } + let recordPut = PatchRecord(title: title, date: date, content: content, emotion: emotionNum, dreamColor: dreamNum, genre: CreateRecordConst.isTouchedIndex, note: note) - isCreateView ? postRecord(record: record) : putRecord(record: recordPut, id: "sojin") + isCreateView ? postRecord(record: record) : putRecord(record: recordPut, id: id) } else { // MARK: - 저장 불가능 상태 UIView.animate(withDuration: 1.25, delay: 0.01, options: .curveEaseIn, animations: { diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailBottomSheetViewController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailBottomSheetViewController.swift index 5b97e6b..416f19c 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailBottomSheetViewController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailBottomSheetViewController.swift @@ -9,6 +9,7 @@ import UIKit class RecordDetailBottomSheetViewController: BaseViewController { @IBOutlet weak var bottomSheetHeight: NSLayoutConstraint! + var recordDetailData: RecordDetailModel? override func viewDidLoad() { super.viewDidLoad() @@ -27,6 +28,17 @@ class RecordDetailBottomSheetViewController: BaseViewController { } } + @IBAction func EditButtonTapped(_ sender: Any) { + print("수정하기") + let editRecordViewController = RecordViewController() + editRecordViewController.recordDetailData = recordDetailData + editRecordViewController.modalPresentationStyle = .overFullScreen + editRecordViewController.modalTransitionStyle = .crossDissolve + editRecordViewController.isCreateView = false + + present(editRecordViewController, animated: true) + } + @IBAction func shareButtonDidTapped(_ sender: UIButton) { guard let captureView = UINib(nibName: "RecordDetailViewController", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else { return } diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift index cc28460..07ccf13 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift @@ -23,6 +23,7 @@ class RecordDetailViewController: BaseViewController { private var recordTitle = "" private var recordDate = "" var recordID: String? //TODO: - 화면 전환 시 기록 고유 번호 할당해주기 + var recordDetailData: RecordDetailModel? override func viewDidLoad() { super.viewDidLoad() @@ -114,6 +115,7 @@ extension RecordDetailViewController: NavigationBarDelegate { func navigationMoreButtonDidTap() { let recordDetailBottomSheet = RecordDetailBottomSheetViewController.instanceFromNib() recordDetailBottomSheet.modalPresentationStyle = .overFullScreen + recordDetailBottomSheet.recordDetailData = recordDetailData self.present(recordDetailBottomSheet, animated: false) { recordDetailBottomSheet.showBottomSheet() @@ -133,6 +135,8 @@ extension RecordDetailViewController { guard let self = self else { return } print("111") guard let recordDetail = recordDetail as? RecordDetailModel else { return } + self.recordDetailData = recordDetail + self.emotion = recordDetail.emotion self.dreamColor = recordDetail.dream_color self.genres = recordDetail.genre @@ -146,6 +150,8 @@ extension RecordDetailViewController { self.dateLabel.text = recordDetail.date self.cardView.image = UIImage(named: Constant.DetailBackgroundColor.IntType(self.dreamColor).title) } + + }) } } diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/View/RecordDetailBottomSheetViewController.xib b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/View/RecordDetailBottomSheetViewController.xib index 6d7b793..0de76e1 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/View/RecordDetailBottomSheetViewController.xib +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/View/RecordDetailBottomSheetViewController.xib @@ -55,6 +55,9 @@ + + + From 0da0775e1bf75dde94cd2e5e10980e9b26924faf Mon Sep 17 00:00:00 2001 From: SojinLee <513sojin@naver.com> Date: Sat, 23 Jul 2022 06:52:45 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Feat]=20=ED=99=88=20=EB=B7=B0=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=EC=97=B0=EA=B2=B0=20=EC=88=98=EC=A0=95=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecordViewController.swift | 66 ++++++++++--------- .../TabBar/TabBarController.swift | 2 +- .../Concept/Create/CreateAPIManager.swift | 46 +++++++++++-- 3 files changed, 78 insertions(+), 36 deletions(-) diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift index b276dd8..ac6c80a 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift @@ -36,6 +36,7 @@ enum CreateRecordConst { static var dreamColorNum: Int? static var isTouchedIndex: [Int] = [] static var genreIndex: [Int] = [] + } class RecordViewController: BaseViewController { @@ -319,34 +320,31 @@ class RecordViewController: BaseViewController { } @objc func saveButtonDidTap() { + print("saveButtonDidTap") if let title = titleTextField.text { if !title.isEmpty && !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { // MARK: - 저장 가능 상태 + print("hoihihihihi") guard let title = titleTextField.text, let content = contentTextView.text, let note = noteTextView.text else { return } let date: String = CreateRecordConst.todayDate.toString() - print("---------------") - print(title) - print(content) - print(note) - print(CreateRecordConst.emotionNum) - print(CreateRecordConst.dreamColorNum) - print(CreateRecordConst.isTouchedIndex) - print(note) - print("---------------") - let record = CreateRecord(title: title, date: date, content: content, emotion: CreateRecordConst.emotionNum, dreamColor: CreateRecordConst.dreamColorNum, genre: CreateRecordConst.isTouchedIndex, note: note, voice: "62cdb868c3032f2b7af76531", writer: "62c9cf068094605c781a2fb9") - guard let emotionNum = CreateRecordConst.emotionNum, - let dreamNum = CreateRecordConst.dreamColorNum, - let id = recordDetailData?._id else { return } + print("record: \(record)") - let recordPut = PatchRecord(title: title, date: date, content: content, emotion: emotionNum, dreamColor: dreamNum, genre: CreateRecordConst.isTouchedIndex, note: note) - - isCreateView ? postRecord(record: record) : putRecord(record: recordPut, id: id) +// guard let emotionNum = CreateRecordConst.emotionNum, +// let dreamNum = CreateRecordConst.dreamColorNum, +// let id = recordDetailData?._id else { return } +// +// let recordPut = PatchRecord(title: title, date: date, content: content, emotion: emotionNum, dreamColor: dreamNum, genre: CreateRecordConst.isTouchedIndex, note: note) +// print("recordPut: \(recordPut)") +// +// print("isCreateView: \(isCreateView)") +// isCreateView ? postRecord(record: record) : putRecord(record: recordPut, id: id) + postRecord(record: record) } else { // MARK: - 저장 불가능 상태 UIView.animate(withDuration: 1.25, delay: 0.01, options: .curveEaseIn, animations: { @@ -360,15 +358,11 @@ class RecordViewController: BaseViewController { func setTitleTextField() { if let title = titleTextField.text { - print("title : \(title)") - print(title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) if !title.isEmpty && !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { // MARK: - 저장 가능 상태 - print("저장 가능 상태") saveButton.setImage(UIImage(named: ImageList.icnSaveOn.name), for: .normal) } else { // MARK: - 저장 불가능 상태 - print("저장 불가능 상태") saveButton.setImage(UIImage(named: ImageList.icnSaveOff.name), for: .normal) } } @@ -584,8 +578,6 @@ extension RecordViewController: UICollectionViewDataSource, UICollectionViewDele if collectionView == emotionCollectionView { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: RecordBarCollectionViewCell.reuseIdentifier, for: indexPath) as? RecordBarCollectionViewCell else { return UICollectionViewCell() } if !isCreateView { -// cell.isSelected = false - print("isSelected - ") if indexPath.item == CreateRecordConst.emotionNum { print("안녕") cell.updateRecordBarImage(reset: false) @@ -593,7 +585,6 @@ extension RecordViewController: UICollectionViewDataSource, UICollectionViewDele } else { print("isisisisisisisis") } -// cell.recordBarImageView.alpha = 1 cell.setRecordBarImage(imageName: Constant.Emotion.IntType(indexPath.item + 1).title) return cell } else if collectionView == dreamColorCollectionView { @@ -657,14 +648,29 @@ extension UILabel { } extension RecordViewController { +// func postRecord(record: CreateRecord) { +// Task { +// do { +// let recordData = try await createManager.postRequest(record: record) +// } catch { +// print("실패") +// } +// } +// } +// +// private func requestUserInformation() { +// MyPageService.shared.getUserInformation(completionHandler: { [weak self] data in +// guard let data = data as? UserInformationModel else { return } +// self?.userInformation = data +// }) +// } +// func postRecord(record: CreateRecord) { - Task { - do { - try await createManager.postRequest(record: record) - } catch { - print("실패") - } - } + createManager.postRequest(record: record, completionHandler: { [weak self] data in + guard let data = data as? DreamBaseModel else { return } + print("postRecord") + print(data) + }) } func putRecord(record: PatchRecord, id: String) { diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/TabBar/TabBarController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/TabBar/TabBarController.swift index ef1e809..9ca97a2 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/TabBar/TabBarController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/TabBar/TabBarController.swift @@ -59,7 +59,7 @@ extension TabBarController: Presentable { private func presentRecordView() { let recordViewController = RecordViewController() navigationController?.pushViewController(recordViewController, animated: false) - recordViewController.isCreateView = false + recordViewController.isCreateView = true } private func setTabBarItems() { diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Service/DTO/Network/Manager/Concept/Create/CreateAPIManager.swift b/RecorDream-iOS/RecorDream-iOS/Source/Service/DTO/Network/Manager/Concept/Create/CreateAPIManager.swift index 1fb4c86..11a2e06 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Service/DTO/Network/Manager/Concept/Create/CreateAPIManager.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Service/DTO/Network/Manager/Concept/Create/CreateAPIManager.swift @@ -9,7 +9,8 @@ import Foundation protocol CreateRequestable: AnyObject { func request(_ request: NetworkRequest) async throws -> [Record] - func postRequest(record: CreateRecord) +// func postRequest(record: CreateRecord) async throws -> DreamBaseModel + func postRequest(record: CreateRecord, completionHandler: @escaping (Any) -> Void) func putRequset(record: PatchRecord, id: String) } @@ -24,7 +25,6 @@ final class CreateAPIManager: CreateRequestable { guard let httpResponse = response as? HTTPURLResponse, (200..<500) ~= httpResponse.statusCode else { throw APIError.serverError } - print("httpResponse.statusCode: \(httpResponse.statusCode)") let decodedData = try JSONDecoder().decode(Record.self, from: data) @@ -35,8 +35,44 @@ final class CreateAPIManager: CreateRequestable { } } - func postRequest(record: CreateRecord) { +// func postRequest(record: CreateRecord) async throws -> DreamBaseModel { +// let url = URL(string: "http://13.125.138.47:8000/record") +// var request = URLRequest(url: url!) +// request.httpMethod = "POST" +// +// guard let uploadData = try? JSONEncoder().encode(record) +// else { throw APIError.urlEncodingError } +// request.addValue("application/json", forHTTPHeaderField: "Content-Type") +// request.addValue("1", forHTTPHeaderField: "userId") +// +// let task = URLSession.shared.uploadTask(with: request, from: uploadData) { data, response, error in +// if let data = data, +// let response = response as? HTTPURLResponse, +// (200..<500) ~= response.statusCode { +// print("response: \(response.statusCode)") +// +// guard let responseData = try? JSONDecoder().decode(DreamBaseModel.self, from: data) else { +// print("json decode error") +// throw APIError.clientError(message: "client error") +// } +// if responseData.success { +// print(responseData.success) +// return [responseData] +// } else { +// print("실패") +// throw APIError.clientError(message: decodedData.message) +// } +// } else { +// print("Error") +// throw APIError.clientError(message: decodedData.message) +// } +// } +// task.resume() +// } + + func postRequest(record: CreateRecord, completionHandler: @escaping (Any) -> Void) { let url = URL(string: "http://13.125.138.47:8000/record") + print(url) var request = URLRequest(url: url!) request.httpMethod = "POST" @@ -46,11 +82,10 @@ final class CreateAPIManager: CreateRequestable { request.addValue("1", forHTTPHeaderField: "userId") let task = URLSession.shared.uploadTask(with: request, from: uploadData) { data, response, error in - if let data = data, let response = response as? HTTPURLResponse, (200..<500) ~= response.statusCode { - print("response: \(response.statusCode)") + print("response - post: \(response.statusCode)") guard let responseData = try? JSONDecoder().decode(DreamBaseModel.self, from: data) else { print("json decode error") @@ -58,6 +93,7 @@ final class CreateAPIManager: CreateRequestable { } if responseData.success { print(responseData.success) + completionHandler(responseData) } else { print("실패") } From 62b25801483303606383907387e10eaabf587760 Mon Sep 17 00:00:00 2001 From: SojinLee <513sojin@naver.com> Date: Sat, 23 Jul 2022 08:20:07 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[Feat]=20=EA=B8=B0=EB=A1=9D=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=EC=8B=9C=20=ED=99=88=ED=99=94=EB=A9=B4=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20(#64)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecordViewController.swift | 30 ++++++++++++++++--- .../RecordDetailViewController.swift | 3 ++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift index ac6c80a..a9c35a4 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Create/Record/ViewControllers/RecordViewController.swift @@ -36,7 +36,7 @@ enum CreateRecordConst { static var dreamColorNum: Int? static var isTouchedIndex: [Int] = [] static var genreIndex: [Int] = [] - + static var recordId: String? } class RecordViewController: BaseViewController { @@ -172,6 +172,16 @@ class RecordViewController: BaseViewController { var emotionSelectedArray = [false, false, false, false, false, false] // var reviseRecordInfo = [] // 서버에서 받아올 값. 모델이랑 매칭해주어야 함 var recordDetailData: RecordDetailModel? + var detailRecordId: String? { + didSet { + DispatchQueue.main.async { + self.navigationDetailView(id: self.detailRecordId ?? "") + } + } + } + + var recordIdClosure: ((String) -> ())? + // MARK: - life cycle override func viewDidLoad() { @@ -199,6 +209,12 @@ class RecordViewController: BaseViewController { headerView.setHeaderView(HiddenMoreBtn: true, headerLabelText: "기록하기") } + private func navigationDetailView(id: String) { + let detailVC = RecordDetailViewController() + navigationController?.pushViewController(detailVC, animated: true) + detailVC.recordID = id + } + private func setEditView() { print("----------------------") print(recordDetailData) @@ -345,6 +361,9 @@ class RecordViewController: BaseViewController { // print("isCreateView: \(isCreateView)") // isCreateView ? postRecord(record: record) : putRecord(record: recordPut, id: id) postRecord(record: record) +// + let tabVC = TabBarController() + navigationController?.pushViewController(tabVC, animated: true) } else { // MARK: - 저장 불가능 상태 UIView.animate(withDuration: 1.25, delay: 0.01, options: .curveEaseIn, animations: { @@ -666,10 +685,13 @@ extension RecordViewController { // } // func postRecord(record: CreateRecord) { - createManager.postRequest(record: record, completionHandler: { [weak self] data in + createManager.postRequest(record: record, completionHandler: { [self] data in guard let data = data as? DreamBaseModel else { return } - print("postRecord") - print(data) +// guard let data = data.data?.id as? DataClass else { return } + guard let recordDataId = data.data?.id as? String else { return } + CreateRecordConst.recordId = data.data?.id +// print("postRecord: \(CreateRecordConst.recordId)") +// recordIdClosure?(CreateRecordConst.recordId ?? "") }) } diff --git a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift index 07ccf13..ecf584e 100644 --- a/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift +++ b/RecorDream-iOS/RecorDream-iOS/Source/Presentation/Concept/Play/ViewController/RecordDetailViewController.swift @@ -24,6 +24,7 @@ class RecordDetailViewController: BaseViewController { private var recordDate = "" var recordID: String? //TODO: - 화면 전환 시 기록 고유 번호 할당해주기 var recordDetailData: RecordDetailModel? +// var completionHandler: ((String) -> ())? override func viewDidLoad() { super.viewDidLoad() @@ -137,6 +138,8 @@ extension RecordDetailViewController { guard let recordDetail = recordDetail as? RecordDetailModel else { return } self.recordDetailData = recordDetail +// self.completionHandler?(CreateRecordConst.recordId ?? "") + self.emotion = recordDetail.emotion self.dreamColor = recordDetail.dream_color self.genres = recordDetail.genre