Skip to content

Commit a7a9e51

Browse files
committed
[feat] 계정 신고 리스트 조회 API, 게시글 신고 리스트 조회 API 구현
1 parent 603c25e commit a7a9e51

File tree

6 files changed

+164
-33
lines changed

6 files changed

+164
-33
lines changed

Fitfty/Projects/Coordinator/Sources/Setting/ReportListCoordinator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
import UIKit
1111
import Common
1212
import Setting
13+
import Core
1314

1415
final class ReportListCoordinator: Coordinator {
1516

@@ -33,7 +34,10 @@ final class ReportListCoordinator: Coordinator {
3334
private extension ReportListCoordinator {
3435

3536
func makeReportListViewController() -> UIViewController {
36-
let viewController = ReportListViewController(coordinator: self)
37+
let viewController = ReportListViewController(
38+
coordinator: self,
39+
viewModel: ReportListViewModel(reportType: .userReport, fitftyRepository: DefaultFitftyRepository())
40+
)
3741
return viewController
3842
}
3943

Fitfty/Projects/Core/Sources/Network/Response/Setting/PostReportListResponse.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
import Foundation
1010

11-
struct PostReportListResponse: Codable {
12-
let result: String
13-
let data: [PostReportListData]?
14-
let message, errorCode: String?
11+
public struct PostReportListResponse: Codable {
12+
public let result: String
13+
public let data: [PostReportListData]?
14+
public let message, errorCode: String?
1515
}
1616

17-
struct PostReportListData: Codable {
18-
let reportToken, reportUserToken, reportUserEmail, reportedBoardToken: String
19-
let reportedBoardFilePath: String
20-
let reportedCount: Int
21-
let type: [String]
22-
let isConfirmed: Bool
17+
public struct PostReportListData: Codable {
18+
public let reportToken, reportUserToken, reportUserEmail, reportedBoardToken: String
19+
public let reportedBoardFilePath: String
20+
public let reportedCount: Int
21+
public let type: [String]
22+
public let isConfirmed: Bool
2323
}

Fitfty/Projects/Core/Sources/Network/Response/Setting/UserReportListResponse.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
import Foundation
1010

11-
struct UserReportListResponse: Codable {
12-
let result: String
13-
let data: [UserReportListData]?
14-
let message, errorCode: String?
11+
public struct UserReportListResponse: Codable {
12+
public let result: String
13+
public let data: [UserReportListData]?
14+
public let message, errorCode: String?
1515
}
1616

17-
struct UserReportListData: Codable {
18-
let reportToken, reportUserToken, reportUserEmail, reportedUserToken: String
19-
let reportedUserEmail: String
20-
let reportedCount: Int
21-
let type: [String]
22-
let isConfirmed: Bool
17+
public struct UserReportListData: Codable {
18+
public let reportToken, reportUserToken, reportUserEmail, reportedUserToken: String
19+
public let reportedUserEmail: String
20+
public let reportedCount: Int
21+
public let type: [String]
22+
public let isConfirmed: Bool
2323
}

Fitfty/Projects/Core/Sources/Repositories/FitftyRepository.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public protocol FitftyRepository {
2323

2424
func report(_ request: UserReportRequest) async throws -> FitftyResponse
2525

26+
func getUserReportList() async throws -> UserReportListResponse
27+
28+
func getPostReportList() async throws -> PostReportListResponse
29+
2630
}
2731

2832
public final class DefaultFitftyRepository: FitftyRepository {
@@ -64,4 +68,12 @@ public final class DefaultFitftyRepository: FitftyRepository {
6468
return try await FitftyAPI.request(target: .reportUser(parameters: request), dataType: FitftyResponse.self)
6569
}
6670

71+
public func getUserReportList() async throws -> UserReportListResponse {
72+
return try await FitftyAPI.request(target: .getUserReportList, dataType: UserReportListResponse.self)
73+
}
74+
75+
public func getPostReportList() async throws -> PostReportListResponse {
76+
return try await FitftyAPI.request(target: .getPostReportList, dataType: PostReportListResponse.self)
77+
}
78+
6779
}

Fitfty/Projects/Setting/Sources/Admin/VewController/ReportListViewController.swift

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88

99
import UIKit
1010
import Common
11+
import Combine
1112

1213
final public class ReportListViewController: UIViewController {
1314

1415
private let menuView = ReportMenuView()
1516
private var coordinator: ReportListCoordinatorInterface
17+
let viewModel: ReportListViewModel
18+
private var cancellables: Set<AnyCancellable> = .init()
1619

1720
private lazy var tableView: UITableView = {
1821
let tableView = UITableView()
@@ -24,8 +27,12 @@ final public class ReportListViewController: UIViewController {
2427

2528
private var dataSource: UITableViewDiffableDataSource<ReportListSectionKind, ReportListCellModel>?
2629

27-
public init(coordinator: ReportListCoordinatorInterface) {
30+
public init(
31+
coordinator: ReportListCoordinatorInterface,
32+
viewModel: ReportListViewModel
33+
) {
2834
self.coordinator = coordinator
35+
self.viewModel = viewModel
2936
super.init(nibName: nil, bundle: nil)
3037
}
3138

@@ -36,15 +43,14 @@ final public class ReportListViewController: UIViewController {
3643
public override func viewDidLoad() {
3744
super.viewDidLoad()
3845
setUp()
46+
viewModel.input.viewDidLoad()
3947
}
40-
48+
4149
private func setUp() {
50+
bind()
4251
setConstraintsLayout()
4352
setNavigationBar()
4453
setDataSource()
45-
applySnapshot([
46-
ReportListSection(sectionKind: .report, items: [ReportListCellModel.report("a", true), ReportListCellModel.report("aa", true)])
47-
])
4854
}
4955

5056
@objc func didTapBackButton(_ sender: Any?) {
@@ -55,6 +61,19 @@ final public class ReportListViewController: UIViewController {
5561

5662
private extension ReportListViewController {
5763

64+
func bind() {
65+
viewModel.state.compactMap { $0 }
66+
.sinkOnMainThread(receiveValue: { [weak self] state in
67+
switch state {
68+
case .errorMessage(let message):
69+
self?.showAlert(message: message)
70+
71+
case .sections(let sections):
72+
self?.applySnapshot(sections)
73+
}
74+
}).store(in: &cancellables)
75+
}
76+
5877
func setConstraintsLayout() {
5978
view.addSubviews(menuView, tableView)
6079
NSLayoutConstraint.activate([
@@ -72,12 +91,12 @@ private extension ReportListViewController {
7291
func setNavigationBar() {
7392
navigationController?.navigationBar.prefersLargeTitles = false
7493
navigationController?.navigationBar.isHidden = false
75-
94+
7695
let cancelButton = UIBarButtonItem(
77-
image: CommonAsset.Images.btnArrowleft.image,
78-
style: .plain,
79-
target: self,
80-
action: #selector(didTapBackButton(_:))
96+
image: CommonAsset.Images.btnArrowleft.image,
97+
style: .plain,
98+
target: self,
99+
action: #selector(didTapBackButton(_:))
81100
)
82101
navigationItem.leftBarButtonItem = cancelButton
83102
}
@@ -86,9 +105,10 @@ private extension ReportListViewController {
86105
dataSource = UITableViewDiffableDataSource<ReportListSectionKind, ReportListCellModel>(
87106
tableView: tableView, cellProvider: { tableView, indexPath, item in
88107
switch item {
89-
case .report(let title, let isSelected):
108+
case .report(let account, let detailReport, let count):
90109
let cell = tableView.dequeueReusableCell(withIdentifier: ReportListCell.className, for: indexPath) as? ReportListCell
91110
cell?.selectionStyle = .none
111+
cell?.setUp(account: account, detailReport: detailReport, count: count)
92112
return cell
93113
}
94114
})
@@ -102,7 +122,7 @@ private extension ReportListViewController {
102122
}
103123
dataSource?.apply(snapshot, animatingDifferences: false)
104124
}
105-
125+
106126
}
107127

108128
extension ReportListViewController: UITableViewDelegate {
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// ReportListViewModel.swift
3+
// Setting
4+
//
5+
// Created by 임영선 on 2023/02/16.
6+
// Copyright © 2023 Fitfty. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
import Common
12+
import Combine
13+
import Core
14+
15+
protocol ReportListViewModelInput {
16+
17+
var input: ReportListViewModelInput { get }
18+
func viewDidLoad()
19+
20+
}
21+
22+
public final class ReportListViewModel {
23+
private var currentState: CurrentValueSubject<ViewModelState?, Never> = .init(nil)
24+
private var cancellables: Set<AnyCancellable> = .init()
25+
private var reportType: ReportType
26+
private var fitftyRepository: FitftyRepository
27+
28+
public init(reportType: ReportType, fitftyRepository: FitftyRepository) {
29+
self.reportType = reportType
30+
self.fitftyRepository = fitftyRepository
31+
}
32+
33+
}
34+
35+
extension ReportListViewModel: ReportListViewModelInput {
36+
var input: ReportListViewModelInput { self }
37+
38+
func viewDidLoad() {
39+
getReportList()
40+
}
41+
42+
}
43+
44+
extension ReportListViewModel: ViewModelType {
45+
46+
public enum ViewModelState {
47+
case errorMessage(String)
48+
case sections([ReportListSection])
49+
}
50+
51+
public var state: AnyPublisher<ViewModelState, Never> { currentState.compactMap { $0 }.eraseToAnyPublisher() }
52+
53+
}
54+
55+
extension ReportListViewModel {
56+
57+
func getReportList() {
58+
Task { [weak self] in
59+
guard let self = self else {
60+
return
61+
}
62+
do {
63+
switch reportType {
64+
case .postReport:
65+
let response = try await self.fitftyRepository.getPostReportList()
66+
print(response)
67+
guard response.result == "SUCCESS",
68+
let data = response.data else {
69+
return
70+
}
71+
var cellModels = [ReportListCellModel]()
72+
for i in 0..<data.count {
73+
cellModels.append(ReportListCellModel.report(data[i].reportUserEmail, data[i].type[0], String(data[i].reportedCount)))
74+
}
75+
self.currentState.send(.sections([ReportListSection(sectionKind: .report, items: cellModels)]))
76+
case .userReport:
77+
let response = try await self.fitftyRepository.getUserReportList()
78+
print(response)
79+
guard response.result == "SUCCESS",
80+
let data = response.data else {
81+
return
82+
}
83+
var cellModels = [ReportListCellModel]()
84+
for i in 0..<data.count {
85+
cellModels.append(ReportListCellModel.report(data[i].reportedUserEmail, data[i].type[0], String(data[i].reportedCount)))
86+
}
87+
self.currentState.send(.sections([ReportListSection(sectionKind: .report, items: cellModels)]))
88+
}
89+
} catch {
90+
Logger.debug(error: error, message: "신고 리스트 조회 실패")
91+
self.currentState.send(.errorMessage("신고 리스트 조회에 알 수 없는 에러가 발생했습니다."))
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)