diff --git a/iOS/Layover/Layover.xcodeproj/project.pbxproj b/iOS/Layover/Layover.xcodeproj/project.pbxproj index f8cdac7..1d7bf39 100644 --- a/iOS/Layover/Layover.xcodeproj/project.pbxproj +++ b/iOS/Layover/Layover.xcodeproj/project.pbxproj @@ -77,6 +77,8 @@ 8321A2FB2B1E1739000A12AF /* LOReportContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8321A2FA2B1E1739000A12AF /* LOReportContentView.swift */; }; 8321A2FD2B1E4260000A12AF /* ReportEndPointFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8321A2FC2B1E4260000A12AF /* ReportEndPointFactory.swift */; }; 8321A2FF2B1E428C000A12AF /* ReportDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8321A2FE2B1E428C000A12AF /* ReportDTO.swift */; }; + 8321A3012B1F1EC5000A12AF /* MockReportWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8321A3002B1F1EC5000A12AF /* MockReportWorker.swift */; }; + 8321A3032B1F2041000A12AF /* ReportPlaybackVideo.json in Resources */ = {isa = PBXBuildFile; fileRef = 8321A3022B1F2041000A12AF /* ReportPlaybackVideo.json */; }; 834B7BD52B14F888002BD176 /* MockSignUpWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 834B7BD42B14F888002BD176 /* MockSignUpWorker.swift */; }; 835783C32B14A41600E7D304 /* MockLoginWorker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835783C22B14A41600E7D304 /* MockLoginWorker.swift */; }; 835783C62B14A5C800E7D304 /* LoginData.json in Resources */ = {isa = PBXBuildFile; fileRef = 835783C52B14A5C800E7D304 /* LoginData.json */; }; @@ -270,6 +272,8 @@ 8321A2FA2B1E1739000A12AF /* LOReportContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOReportContentView.swift; sourceTree = ""; }; 8321A2FC2B1E4260000A12AF /* ReportEndPointFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportEndPointFactory.swift; sourceTree = ""; }; 8321A2FE2B1E428C000A12AF /* ReportDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportDTO.swift; sourceTree = ""; }; + 8321A3002B1F1EC5000A12AF /* MockReportWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockReportWorker.swift; sourceTree = ""; }; + 8321A3022B1F2041000A12AF /* ReportPlaybackVideo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = ReportPlaybackVideo.json; sourceTree = ""; }; 834B7BD42B14F888002BD176 /* MockSignUpWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSignUpWorker.swift; sourceTree = ""; }; 835783C22B14A41600E7D304 /* MockLoginWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockLoginWorker.swift; sourceTree = ""; }; 835783C52B14A5C800E7D304 /* LoginData.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = LoginData.json; sourceTree = ""; }; @@ -515,6 +519,7 @@ 19A169462B17D12500DB34C0 /* MockTagPlayListWorker.swift */, 194C21BA2B1B718B00C62645 /* MockHomeWorker.swift */, 194C21BC2B1B728600C62645 /* StubAuthManager.swift */, + 8321A3002B1F1EC5000A12AF /* MockReportWorker.swift */, ); path = Mocks; sourceTree = ""; @@ -748,6 +753,7 @@ FC767F9A2B12283D0088CF9B /* PatchUserName.json */, 835783C52B14A5C800E7D304 /* LoginData.json */, 19A169352B178EA500DB34C0 /* PostList.json */, + 8321A3022B1F2041000A12AF /* ReportPlaybackVideo.json */, ); path = MockData; sourceTree = ""; @@ -1032,6 +1038,7 @@ 835A61A62B0B4DDD002F22A5 /* Dashboard-Regular.ttf in Resources */, 835783C62B14A5C800E7D304 /* LoginData.json in Resources */, FC767FA12B12283D0088CF9B /* DeleteUser.json in Resources */, + 8321A3032B1F2041000A12AF /* ReportPlaybackVideo.json in Resources */, FC7E45462AFEB62B004F155A /* LaunchScreen.storyboard in Resources */, 19A169362B178EA500DB34C0 /* PostList.json in Resources */, FC767FA02B12283D0088CF9B /* CheckUserName.json in Resources */, @@ -1132,6 +1139,7 @@ 193686722B15BCA7008902CD /* UserEndPointFactory.swift in Sources */, 194551F22B037F2D00299768 /* LoginPresenter.swift in Sources */, 194552242B0478B400299768 /* HomeModels.swift in Sources */, + 8321A3012B1F1EC5000A12AF /* MockReportWorker.swift in Sources */, 19A1692D2B17750B00DB34C0 /* Post.swift in Sources */, 194552022B038B8300299768 /* OSLog+.swift in Sources */, 8321A2F92B1E15F3000A12AF /* LOReportStackView.swift in Sources */, diff --git a/iOS/Layover/Layover/DesignSystem/LOPopUpView.swift b/iOS/Layover/Layover/DesignSystem/LOPopUpView.swift index ffc61fd..e27f7be 100644 --- a/iOS/Layover/Layover/DesignSystem/LOPopUpView.swift +++ b/iOS/Layover/Layover/DesignSystem/LOPopUpView.swift @@ -32,14 +32,20 @@ final class LOPopUpView: UIView { return button }() + weak var delegate: ReportViewControllerDelegate? + override init(frame: CGRect) { super.init(frame: frame) setConstraints() + cancelButton.addTarget(self, action: #selector(cancelButtonDidTap), for: .touchUpInside) + reportButton.addTarget(self, action: #selector(reportButtonDidTap), for: .touchUpInside) } required init?(coder: NSCoder) { super.init(coder: coder) setConstraints() + cancelButton.addTarget(self, action: #selector(cancelButtonDidTap), for: .touchUpInside) + reportButton.addTarget(self, action: #selector(reportButtonDidTap), for: .touchUpInside) } func getReportContent() -> String { @@ -73,4 +79,12 @@ final class LOPopUpView: UIView { ]) } + + @objc private func cancelButtonDidTap() { + delegate?.dismissReportView() + } + + @objc private func reportButtonDidTap() { + delegate?.reportPlaybackVideo(reportContent: getReportContent()) + } } diff --git a/iOS/Layover/Layover/Network/Mock/MockData/ReportPlaybackVideo.json b/iOS/Layover/Layover/Network/Mock/MockData/ReportPlaybackVideo.json new file mode 100644 index 0000000..52e9557 --- /dev/null +++ b/iOS/Layover/Layover/Network/Mock/MockData/ReportPlaybackVideo.json @@ -0,0 +1,10 @@ +{ + "customCode": "SUCCESS", + "message": "성공", + "statusCode": 200, + "data": { + "memberId": 221, + "boardId": 5, + "reportType": "청소년에게 유해한 내용이에요" + } +} diff --git a/iOS/Layover/Layover/Scenes/Report/ReportConfigurator.swift b/iOS/Layover/Layover/Scenes/Report/ReportConfigurator.swift index 93566fd..7de9c41 100644 --- a/iOS/Layover/Layover/Scenes/Report/ReportConfigurator.swift +++ b/iOS/Layover/Layover/Scenes/Report/ReportConfigurator.swift @@ -17,7 +17,8 @@ final class ReportConfigurator: Configurator { let viewController: ReportViewController = viewController let interactor: ReportInteractor = ReportInteractor() let presenter: ReportPresenter = ReportPresenter() - let worker: ReportWorker = ReportWorker() +// let worker: ReportWorker = ReportWorker() + let worker: ReportWorkerProtocol = MockReportWorker() let router: ReportRouter = ReportRouter() router.viewController = viewController diff --git a/iOS/Layover/Layover/Scenes/Report/ReportInteractor.swift b/iOS/Layover/Layover/Scenes/Report/ReportInteractor.swift index 1979cdb..4cf1042 100644 --- a/iOS/Layover/Layover/Scenes/Report/ReportInteractor.swift +++ b/iOS/Layover/Layover/Scenes/Report/ReportInteractor.swift @@ -22,13 +22,15 @@ final class ReportInteractor: ReportBusinessLogic, ReportDataStore { typealias Models = ReportModels - lazy var worker = ReportWorker() + var worker: ReportWorkerProtocol? var presenter: ReportPresentationLogic? var boardID: Int? func reportPlaybackVideo(with request: ReportModels.ReportPlaybackVideo.Request) { - guard let boardID else { return } + guard let boardID, + let worker + else { return } Task { let result: Bool = await worker.reportPlaybackVideo(boardId: boardID, reportContent: request.reportContent) let response: Models.ReportPlaybackVideo.Response = Models.ReportPlaybackVideo.Response(reportResult: result) diff --git a/iOS/Layover/Layover/Scenes/Report/ReportViewController.swift b/iOS/Layover/Layover/Scenes/Report/ReportViewController.swift index 8a30191..53971d9 100644 --- a/iOS/Layover/Layover/Scenes/Report/ReportViewController.swift +++ b/iOS/Layover/Layover/Scenes/Report/ReportViewController.swift @@ -10,6 +10,7 @@ import UIKit protocol ReportViewControllerDelegate: AnyObject { func reportPlaybackVideo(reportContent: String) + func dismissReportView() } protocol ReportDisplayLogic: AnyObject { @@ -62,6 +63,7 @@ final class ReportViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() + popUpView.delegate = self } override func setUI() { @@ -96,11 +98,17 @@ extension ReportViewController: ReportViewControllerDelegate { let request: Models.ReportPlaybackVideo.Request = Models.ReportPlaybackVideo.Request(reportContent: reportContent) interactor?.reportPlaybackVideo(with: request) } + + func dismissReportView() { + self.dismiss(animated: false) + } } extension ReportViewController: ReportDisplayLogic { func displayReportResult(viewModel: ReportModels.ReportPlaybackVideo.ViewModel) { - Toast.shared.showToast(message: viewModel.reportMessage) + self.dismiss(animated: false, completion: { + Toast.shared.showToast(message: viewModel.reportMessage) + }) } } diff --git a/iOS/Layover/Layover/Scenes/Report/ReportWorker.swift b/iOS/Layover/Layover/Scenes/Report/ReportWorker.swift index c206a9c..2e67054 100644 --- a/iOS/Layover/Layover/Scenes/Report/ReportWorker.swift +++ b/iOS/Layover/Layover/Scenes/Report/ReportWorker.swift @@ -31,14 +31,13 @@ final class ReportWorker: ReportWorkerProtocol { func reportPlaybackVideo(boardId: Int, reportContent: String) async -> Bool { let endPoint = reportEndPointFactory.reportPlaybackVideoEndpoint(boardId: boardId, reportType: reportContent) do { - let responseData = try await provider.request(with: endPoint, authenticationIfNeeded: false) - print(responseData.message) + let responseData = try await provider.request(with: endPoint) guard let _ = responseData.data else { - os_log(.error, log: .default, "Failed to sign up with error: %@", responseData.message) + os_log(.error, log: .default, "Failed to report with error: %@", responseData.message) return false } } catch { - os_log(.error, log: .default, "Failed to sign up with error: %@", error.localizedDescription) + os_log(.error, log: .default, "Failed to report with error: %@", error.localizedDescription) return false } return true diff --git a/iOS/Layover/Layover/Workers/Mocks/MockReportWorker.swift b/iOS/Layover/Layover/Workers/Mocks/MockReportWorker.swift new file mode 100644 index 0000000..f63d81b --- /dev/null +++ b/iOS/Layover/Layover/Workers/Mocks/MockReportWorker.swift @@ -0,0 +1,50 @@ +// +// MockReportWorker.swift +// Layover +// +// Created by 황지웅 on 12/5/23. +// Copyright © 2023 CodeBomber. All rights reserved. +// + +import Foundation +import OSLog + +final class MockReportWorker: ReportWorkerProtocol { + + // MARK: - Properties + + private let provider: ProviderType = Provider(session: .initMockSession(), authManager: StubAuthManager()) + + // MARK: - Methods + + func reportPlaybackVideo(boardId: Int, reportContent: String) async -> Bool { + guard let mockFileLocation = Bundle.main.url(forResource: "ReportPlaybackVideo", withExtension: "json"), + let mockData = try? Data(contentsOf: mockFileLocation) + else { + return false + } + + MockURLProtocol.requestHandler = { request in + let response = HTTPURLResponse(url: request.url!, + statusCode: 200, + httpVersion: nil, + headerFields: nil) + return (response, mockData, nil) + } + + do { + let bodyParameters = ReportDTO( + memberId: nil, + boardId: 1, + reportType: "청소년에게 유해한 내용입니다.") + let endPoint = EndPoint>(path: "/report", + method: .POST, + bodyParameters: bodyParameters) + let response = try await provider.request(with: endPoint) + return true + } catch { + os_log(.error, log: .data, "%@", error.localizedDescription) + return false + } + } +}