diff --git a/HARA/HARA.xcodeproj/project.pbxproj b/HARA/HARA.xcodeproj/project.pbxproj index 0aa42e2..6180efc 100644 --- a/HARA/HARA.xcodeproj/project.pbxproj +++ b/HARA/HARA.xcodeproj/project.pbxproj @@ -10,13 +10,16 @@ 6713491B296F24190093DDAA /* StorageAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C69C19295AD72F00848B72 /* StorageAPI.swift */; }; 673315EF2965C1E500398AA5 /* UnderlineSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 673315EE2965C1E500398AA5 /* UnderlineSegmentedControl.swift */; }; 673315F12966D1AC00398AA5 /* StorageVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 673315F02966D1AC00398AA5 /* StorageVC.swift */; }; - 6779C7F0296F1F3D0026BE10 /* StorageAloneResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6779C7EF296F1F3D0026BE10 /* StorageAloneResponse.swift */; }; + 6779C7F0296F1F3D0026BE10 /* StorageResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6779C7EF296F1F3D0026BE10 /* StorageResponse.swift */; }; 67DA6D22296C9242006F4C5C /* AloneWorriedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D21296C9242006F4C5C /* AloneWorriedVC.swift */; }; 67DA6D24296C924C006F4C5C /* TogetherWorriedVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D23296C924C006F4C5C /* TogetherWorriedVC.swift */; }; 67DA6D26296C9259006F4C5C /* AloneWorriedCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D25296C9259006F4C5C /* AloneWorriedCVC.swift */; }; 67DA6D28296C925F006F4C5C /* TogetherWorriedCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D27296C925F006F4C5C /* TogetherWorriedCVC.swift */; }; 67DA6D2D296C92B9006F4C5C /* WorriedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DA6D2B296C92B9006F4C5C /* WorriedModel.swift */; }; 852B6B3D2971826E00BA2276 /* StorageNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B3C2971826E00BA2276 /* StorageNavigationView.swift */; }; + 852B6B3F29719CF000BA2276 /* WorryDetailResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B3E29719CF000BA2276 /* WorryDetailResponse.swift */; }; + 852B6B432971A27200BA2276 /* WorryDetailService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B422971A27200BA2276 /* WorryDetailService.swift */; }; + 852B6B452971A39E00BA2276 /* WorryDetailAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 852B6B442971A39E00BA2276 /* WorryDetailAPI.swift */; }; 8532A77A296BE14D00402E91 /* BaseOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8532A779296BE14D00402E91 /* BaseOptionView.swift */; }; 8532A77C296BE15300402E91 /* AddOptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8532A77B296BE15300402E91 /* AddOptionView.swift */; }; 8532A77F296BEFEF00402E91 /* AddOptionBtnView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8532A77E296BEFEF00402E91 /* AddOptionBtnView.swift */; }; @@ -98,13 +101,16 @@ /* Begin PBXFileReference section */ 673315EE2965C1E500398AA5 /* UnderlineSegmentedControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineSegmentedControl.swift; sourceTree = ""; }; 673315F02966D1AC00398AA5 /* StorageVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageVC.swift; sourceTree = ""; }; - 6779C7EF296F1F3D0026BE10 /* StorageAloneResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageAloneResponse.swift; sourceTree = ""; }; + 6779C7EF296F1F3D0026BE10 /* StorageResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageResponse.swift; sourceTree = ""; }; 67DA6D21296C9242006F4C5C /* AloneWorriedVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AloneWorriedVC.swift; sourceTree = ""; }; 67DA6D23296C924C006F4C5C /* TogetherWorriedVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TogetherWorriedVC.swift; sourceTree = ""; }; 67DA6D25296C9259006F4C5C /* AloneWorriedCVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AloneWorriedCVC.swift; sourceTree = ""; }; 67DA6D27296C925F006F4C5C /* TogetherWorriedCVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TogetherWorriedCVC.swift; sourceTree = ""; }; 67DA6D2B296C92B9006F4C5C /* WorriedModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WorriedModel.swift; sourceTree = ""; }; 852B6B3C2971826E00BA2276 /* StorageNavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageNavigationView.swift; sourceTree = ""; }; + 852B6B3E29719CF000BA2276 /* WorryDetailResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorryDetailResponse.swift; sourceTree = ""; }; + 852B6B422971A27200BA2276 /* WorryDetailService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorryDetailService.swift; sourceTree = ""; }; + 852B6B442971A39E00BA2276 /* WorryDetailAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorryDetailAPI.swift; sourceTree = ""; }; 8532A779296BE14D00402E91 /* BaseOptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseOptionView.swift; sourceTree = ""; }; 8532A77B296BE15300402E91 /* AddOptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOptionView.swift; sourceTree = ""; }; 8532A77E296BEFEF00402E91 /* AddOptionBtnView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOptionBtnView.swift; sourceTree = ""; }; @@ -336,7 +342,8 @@ E7B47C2D296F0E69009987E1 /* Storage */ = { isa = PBXGroup; children = ( - 6779C7EF296F1F3D0026BE10 /* StorageAloneResponse.swift */, + 6779C7EF296F1F3D0026BE10 /* StorageResponse.swift */, + 852B6B3E29719CF000BA2276 /* WorryDetailResponse.swift */, ); path = Storage; sourceTree = ""; @@ -467,6 +474,7 @@ E7C69C15295AD70F00848B72 /* TogetherAPI.swift */, E7C69C17295AD71C00848B72 /* WriteAPI.swift */, E7C69C19295AD72F00848B72 /* StorageAPI.swift */, + 852B6B442971A39E00BA2276 /* WorryDetailAPI.swift */, ); path = APIs; sourceTree = ""; @@ -477,6 +485,7 @@ E7C69CDB2965552700848B72 /* TogetherService.swift */, E7C69CDD296555A600848B72 /* WriteService.swift */, E7C69CDF296555B400848B72 /* StorageService.swift */, + 852B6B422971A27200BA2276 /* WorryDetailService.swift */, ); path = Services; sourceTree = ""; @@ -674,6 +683,7 @@ E7C69C09295AD68100848B72 /* ToastMessageColorType.swift in Sources */, E7C69CDE296555A600848B72 /* WriteService.swift in Sources */, E7C69CD2296554D700848B72 /* NetworkConstant.swift in Sources */, + 852B6B3F29719CF000BA2276 /* WorryDetailResponse.swift in Sources */, E7C69CEB29658BF900848B72 /* VoteOptionCVC.swift in Sources */, E74585CB296DEE5800597168 /* WorryDetailFooterView.swift in Sources */, 8532A77F296BEFEF00402E91 /* AddOptionBtnView.swift in Sources */, @@ -697,10 +707,11 @@ 85E0A44B29646E300007C3CA /* SecondWriteStepVC.swift in Sources */, 8532A78C296DCE9300402E91 /* OneSecGameVC.swift in Sources */, E7C69C9D29613F2700848B72 /* UIStackView+.swift in Sources */, - 6779C7F0296F1F3D0026BE10 /* StorageAloneResponse.swift in Sources */, + 6779C7F0296F1F3D0026BE10 /* StorageResponse.swift in Sources */, 673315EF2965C1E500398AA5 /* UnderlineSegmentedControl.swift in Sources */, 8532A77A296BE14D00402E91 /* BaseOptionView.swift in Sources */, E74585D5296EA2B500597168 /* FinalChoiceVC.swift in Sources */, + 852B6B452971A39E00BA2276 /* WorryDetailAPI.swift in Sources */, E74585CD296E01E100597168 /* DetailWorryCommentCVC.swift in Sources */, 8532A786296C251200402E91 /* ProsConsCVC.swift in Sources */, E7C69C9929613A4300848B72 /* UIButton+.swift in Sources */, @@ -709,6 +720,7 @@ E74C8751296ABB2300BFAD31 /* DetailWorryCardVC.swift in Sources */, E7C69CD6296554F800848B72 /* GeneralResponse.swift in Sources */, E74C8753296C128F00BFAD31 /* DetailWorryCVC.swift in Sources */, + 852B6B432971A27200BA2276 /* WorryDetailService.swift in Sources */, E7C69BE9295AC8A900848B72 /* AppDelegate.swift in Sources */, 85E0A44929646E280007C3CA /* FirstWriteStepVC.swift in Sources */, E74C874F296A97AF00BFAD31 /* VotedCVC.swift in Sources */, diff --git a/HARA/HARA/Network/APIs/WorryDetailAPI.swift b/HARA/HARA/Network/APIs/WorryDetailAPI.swift new file mode 100644 index 0000000..c00ff14 --- /dev/null +++ b/HARA/HARA/Network/APIs/WorryDetailAPI.swift @@ -0,0 +1,74 @@ +// +// WorryDetailAPI.swift +// HARA +// +// Created by saint on 2023/01/13. +// + +import Foundation +import Moya + +final class WorryDetailAPI { + + static let shared: WorryDetailAPI = WorryDetailAPI() + private let worryDetailProvider = MoyaProvider(plugins: [MoyaLoggingPlugin()]) + private init() { } + + public private(set) var worryAloneDetailResponse: GeneralArrayResponse? + + public private(set) var worryWithDetailResponse: GeneralArrayResponse? + + // MARK: - WorryAlone + func getWorryAloneList(param: Int, completion: @escaping ((GeneralArrayResponse?) -> ())) { + worryDetailProvider.request(.alone(param: param)) { [weak self] response in + switch response { + case .success(let result): + do { + self?.worryAloneDetailResponse = try + result.map(GeneralArrayResponse?.self) + print("성공") + print(result) + guard let aloneData = self?.worryAloneDetailResponse else { print("빠짐") + return + } + print(aloneData) + completion(aloneData) + } catch(let err) { + print("데이터 실패") + print(err.localizedDescription) + completion(nil) + } + case .failure(let err): + print("실패") + print(err.localizedDescription) + completion(nil) + } + } + } + + // MARK: - StorageWith + func getWorryWithList(param: Int, completion: @escaping ((GeneralArrayResponse?) -> ())) { + worryDetailProvider.request(.with(param: param)) { [weak self] response in + switch response { + case .success(let result): + do { + self?.worryWithDetailResponse = try result.map(GeneralArrayResponse?.self) + print("성공") + guard let withData = self?.worryWithDetailResponse else {print("2") + return + } + print(withData) + completion(withData) + } catch(let err) { + print("데이터 실패") + print(err.localizedDescription) + completion(nil) + } + case .failure(let err): + print("실패") + print(err.localizedDescription) + completion(nil) + } + } + } +} diff --git a/HARA/HARA/Network/Base/APIConstant.swift b/HARA/HARA/Network/Base/APIConstant.swift index bf1a6b0..42d9758 100644 --- a/HARA/HARA/Network/Base/APIConstant.swift +++ b/HARA/HARA/Network/Base/APIConstant.swift @@ -31,7 +31,7 @@ struct APIConstant { /// 파라미터 :worryId static let worryAloneDetail = "/worry/alone" - static let worryWidthDetail = "/worry/with" + static let worryWithDetail = "/worry/with" //MARK: - Write static let worryAlone = "/worry/alone" diff --git a/HARA/HARA/Network/DataModel/Storage/StorageAloneResponse.swift b/HARA/HARA/Network/DataModel/Storage/StorageResponse.swift similarity index 100% rename from HARA/HARA/Network/DataModel/Storage/StorageAloneResponse.swift rename to HARA/HARA/Network/DataModel/Storage/StorageResponse.swift diff --git a/HARA/HARA/Network/DataModel/Storage/WorryDetailResponse.swift b/HARA/HARA/Network/DataModel/Storage/WorryDetailResponse.swift new file mode 100644 index 0000000..ad79995 --- /dev/null +++ b/HARA/HARA/Network/DataModel/Storage/WorryDetailResponse.swift @@ -0,0 +1,58 @@ +// +// AloneWorryDetailResponse.swift +// HARA +// +// Created by saint on 2023/01/13. +// + +import Foundation + +// MARK: - WorryAloneDetailResponse +struct WorryAloneDetailResponse: Codable { + var finalOption: Int? + var createdAt, worryTitle, worryContent: String + var category: String + var options: Option + + // MARK: - Option + struct Option: Codable { + var id, worryAloneId: Int + var title: String + var advantage, disadvantage: String? + var image: String? + var hasImage: Bool + } +} + +// MARK: - WorryWithDetailResponse +struct WorryWithDetailResponse: Codable { + var isAuthor: Bool + var finalOption: Int? + var isVoted: Bool + var selectedOptionId: Int? + var createdAt, worryTitle, worryContent, category: String + var options: [Option] + var commentCount: Int + var comments: [Comment]? + + // MARK: - Option + struct Option: Codable { + var id, worryWithId: Int + var title: String + var advantage, disadvantage: String? + var image: String? + var hasImage: Bool + var percentage: Int? + } + + // MARK: - Comment + struct Comment: Codable { + var userNickName: String + var userImage: String + var content: String + var createdAt: String + } +} + + + diff --git a/HARA/HARA/Network/Services/WorryDetailService.swift b/HARA/HARA/Network/Services/WorryDetailService.swift new file mode 100644 index 0000000..c549f53 --- /dev/null +++ b/HARA/HARA/Network/Services/WorryDetailService.swift @@ -0,0 +1,69 @@ +// +// WorryDetailService.swift +// HARA +// +// Created by saint on 2023/01/13. +// + +import Foundation +import Moya + +enum WorryDetailService { + case alone(param: Int) + case with(param: Int) +} + +extension WorryDetailService: BaseTargetType { + + var path: String { + switch self { + case .alone(let param): + return APIConstant.worryAloneDetail + "/\(param)" + /// param은 int형으로 받아온다. + + case .with(let param): + return APIConstant.worryWithDetail + "/\(param)" + } + } + + var method: Moya.Method { + switch self { + case .alone: + return .get + + case .with: + return .get + } + } + +// var parameters: [String: Any]? { +// switch self { +// case .alone(let param): +// return ["worryId": param] +// +// case .with(let param): +// return ["worryId": param] +// } +// } + + var task: Task { + switch self { + case .alone: + return .requestPlain + + case .with: + return .requestPlain + } + } + + var headers: [String : String]? { + switch self { + case .alone: + return NetworkConstant.noTokenHeader + + case .with: + return NetworkConstant.noTokenHeader + } + } +} + diff --git a/HARA/HARA/Sources/Scenes/Together/WorryCardCVC.swift b/HARA/HARA/Sources/Scenes/Together/WorryCardCVC.swift index ff13967..975909f 100644 --- a/HARA/HARA/Sources/Scenes/Together/WorryCardCVC.swift +++ b/HARA/HARA/Sources/Scenes/Together/WorryCardCVC.swift @@ -191,7 +191,7 @@ extension WorryCardCVC: UICollectionViewDelegate { // MARK: - Layout extension WorryCardCVC { private func setLayout() { - contentView.addSubviews([worryCategoryLabel, worryDateLabel, worryTitleLabel, worryContentLabel,voteOptionCV, voteButton, chatButton]) + contentView.addSubviews([worryCategoryLabel, worryDateLabel, worryTitleLabel, worryContentLabel, voteOptionCV, voteButton, chatButton]) worryCategoryLabel.snp.makeConstraints { $0.leading.equalToSuperview().offset(14) diff --git a/HARA/HARA/Sources/Scenes/Together/WorryDetail/DetailWorryCardVC.swift b/HARA/HARA/Sources/Scenes/Together/WorryDetail/DetailWorryCardVC.swift index 477e5a6..bbeb70f 100644 --- a/HARA/HARA/Sources/Scenes/Together/WorryDetail/DetailWorryCardVC.swift +++ b/HARA/HARA/Sources/Scenes/Together/WorryDetail/DetailWorryCardVC.swift @@ -133,6 +133,7 @@ final class DetailWorryCardVC: UIViewController { setLayout() setPressAction() setVoteOptionCV() + getWorryAloneList(worryId: 3) } override func viewWillLayoutSubviews() { @@ -301,3 +302,24 @@ extension DetailWorryCardVC: SendButtonAction { self.voteOptionCV.reloadData() } } + +// MARK: - Network +extension DetailWorryCardVC{ + func getWorryAloneList(worryId: Int){ + WorryDetailAPI.shared.getWorryAloneList(param: worryId){ result in + guard let res = result else {return} + print("값: \(res)") + guard let dataModel = res.data else {return} + print(dataModel) + } + } + + func getWorryWithList(worryId: Int){ + WorryDetailAPI.shared.getWorryWithList(param: worryId){ result in + guard let res = result else {return} + print("값\(res)") + guard let dataModel = res.data else {return} + print(dataModel) + } + } +} diff --git a/HARA/HARA/Sources/Scenes/Together/WorryDetail/WorryDetailFooterView.swift b/HARA/HARA/Sources/Scenes/Together/WorryDetail/WorryDetailFooterView.swift index 292a1af..1e76006 100644 --- a/HARA/HARA/Sources/Scenes/Together/WorryDetail/WorryDetailFooterView.swift +++ b/HARA/HARA/Sources/Scenes/Together/WorryDetail/WorryDetailFooterView.swift @@ -53,21 +53,15 @@ final class WorryDetailFooterView: UICollectionReusableView { private func setPressAction() { voteButton.press { -// self.isOptionSelected = true + // self.isOptionSelected = true self.voteButton.backgroundColor = .hOrange3 self.voteButton.layer.borderWidth = 0 self.voteButton.setTitle("투표완료!", for: .normal) self.voteButton.setTitleColor(.hWhite, for: .normal) self.voteButton.setBackgroundColor(.hGray3, for: .normal) self.voteButton.isUserInteractionEnabled = false -// self.voteOptionCV.reloadData() + // self.voteOptionCV.reloadData() self.buttonDelegate?.sendData(isSelected: true) } - - - } - - - }