Skip to content

Commit

Permalink
✨ 신고기능 Mock 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmozzi committed Dec 5, 2023
1 parent 48e792f commit 6c59e0a
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 8 deletions.
8 changes: 8 additions & 0 deletions iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -270,6 +272,8 @@
8321A2FA2B1E1739000A12AF /* LOReportContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOReportContentView.swift; sourceTree = "<group>"; };
8321A2FC2B1E4260000A12AF /* ReportEndPointFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportEndPointFactory.swift; sourceTree = "<group>"; };
8321A2FE2B1E428C000A12AF /* ReportDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportDTO.swift; sourceTree = "<group>"; };
8321A3002B1F1EC5000A12AF /* MockReportWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockReportWorker.swift; sourceTree = "<group>"; };
8321A3022B1F2041000A12AF /* ReportPlaybackVideo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = ReportPlaybackVideo.json; sourceTree = "<group>"; };
834B7BD42B14F888002BD176 /* MockSignUpWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockSignUpWorker.swift; sourceTree = "<group>"; };
835783C22B14A41600E7D304 /* MockLoginWorker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockLoginWorker.swift; sourceTree = "<group>"; };
835783C52B14A5C800E7D304 /* LoginData.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = LoginData.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -515,6 +519,7 @@
19A169462B17D12500DB34C0 /* MockTagPlayListWorker.swift */,
194C21BA2B1B718B00C62645 /* MockHomeWorker.swift */,
194C21BC2B1B728600C62645 /* StubAuthManager.swift */,
8321A3002B1F1EC5000A12AF /* MockReportWorker.swift */,
);
path = Mocks;
sourceTree = "<group>";
Expand Down Expand Up @@ -748,6 +753,7 @@
FC767F9A2B12283D0088CF9B /* PatchUserName.json */,
835783C52B14A5C800E7D304 /* LoginData.json */,
19A169352B178EA500DB34C0 /* PostList.json */,
8321A3022B1F2041000A12AF /* ReportPlaybackVideo.json */,
);
path = MockData;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
14 changes: 14 additions & 0 deletions iOS/Layover/Layover/DesignSystem/LOPopUpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -73,4 +79,12 @@ final class LOPopUpView: UIView {
])

}

@objc private func cancelButtonDidTap() {
delegate?.dismissReportView()
}

@objc private func reportButtonDidTap() {
delegate?.reportPlaybackVideo(reportContent: getReportContent())
}
}
10 changes: 10 additions & 0 deletions iOS/Layover/Layover/Network/Mock/MockData/ReportPlaybackVideo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"customCode": "SUCCESS",
"message": "성공",
"statusCode": 200,
"data": {
"memberId": 221,
"boardId": 5,
"reportType": "청소년에게 유해한 내용이에요"
}
}
3 changes: 2 additions & 1 deletion iOS/Layover/Layover/Scenes/Report/ReportConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions iOS/Layover/Layover/Scenes/Report/ReportInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion iOS/Layover/Layover/Scenes/Report/ReportViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit

protocol ReportViewControllerDelegate: AnyObject {
func reportPlaybackVideo(reportContent: String)
func dismissReportView()
}

protocol ReportDisplayLogic: AnyObject {
Expand Down Expand Up @@ -62,6 +63,7 @@ final class ReportViewController: BaseViewController {

override func viewDidLoad() {
super.viewDidLoad()
popUpView.delegate = self
}

override func setUI() {
Expand Down Expand Up @@ -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)
})
}
}

Expand Down
7 changes: 3 additions & 4 deletions iOS/Layover/Layover/Scenes/Report/ReportWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions iOS/Layover/Layover/Workers/Mocks/MockReportWorker.swift
Original file line number Diff line number Diff line change
@@ -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<Response<ReportDTO>>(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
}
}
}

0 comments on commit 6c59e0a

Please sign in to comment.