Skip to content

Commit 5e554d5

Browse files
committed
♻️ [refactor] 신고리스트 response가져오는 로직, cellModels만드는 로직 메소드로 분리
1 parent f45a1a1 commit 5e554d5

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

Fitfty/Projects/Setting/Sources/Admin/ViewModel/ReportListViewModel.swift

+41-20
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension ReportListViewModel: ViewModelType {
5353

5454
}
5555

56-
extension ReportListViewModel {
56+
private extension ReportListViewModel {
5757

5858
func getReportList() {
5959
Task { [weak self] in
@@ -63,29 +63,16 @@ extension ReportListViewModel {
6363
do {
6464
switch reportType {
6565
case .postReport:
66-
let response = try await self.fitftyRepository.getPostReportList()
67-
print(response)
68-
guard response.result == "SUCCESS",
69-
let data = response.data else {
66+
guard let data = try await getPostReportList() else {
7067
return
7168
}
72-
var cellModels = [ReportListCellModel]()
73-
for i in 0..<data.count {
74-
cellModels.append(ReportListCellModel.report(data[i].reportUserEmail, getKoreanDetailReport(data[i].type[0]), String(data[i].reportedCount+1), data[i].reportedBoardFilePath))
75-
}
76-
self.currentState.send(.sections([ReportListSection(sectionKind: .report, items: cellModels)]))
69+
self.currentState.send(.sections([ReportListSection(sectionKind: .report, items: getCellModels(data))]))
70+
7771
case .userReport:
78-
let response = try await self.fitftyRepository.getUserReportList()
79-
print(response)
80-
guard response.result == "SUCCESS",
81-
let data = response.data else {
72+
guard let data = try await getUserReportList() else {
8273
return
8374
}
84-
var cellModels = [ReportListCellModel]()
85-
for i in 0..<data.count {
86-
cellModels.append(ReportListCellModel.report(data[i].reportedUserEmail, getKoreanDetailReport(data[i].type[0]), String(data[i].reportedCount+1), nil))
87-
}
88-
self.currentState.send(.sections([ReportListSection(sectionKind: .report, items: cellModels)]))
75+
self.currentState.send(.sections([ReportListSection(sectionKind: .report, items: getCellModels(data))]))
8976
}
9077
} catch {
9178
Logger.debug(error: error, message: "신고 리스트 조회 실패")
@@ -94,7 +81,41 @@ extension ReportListViewModel {
9481
}
9582
}
9683

97-
private func getKoreanDetailReport(_ english: String) -> String {
84+
func getPostReportList() async throws -> [PostReportListData]? {
85+
let response = try await self.fitftyRepository.getPostReportList()
86+
if response.result == "SUCCESS" {
87+
return response.data
88+
} else {
89+
return nil
90+
}
91+
}
92+
93+
func getUserReportList() async throws -> [UserReportListData]? {
94+
let response = try await self.fitftyRepository.getUserReportList()
95+
if response.result == "SUCCESS" {
96+
return response.data
97+
} else {
98+
return nil
99+
}
100+
}
101+
102+
func getCellModels(_ data: [PostReportListData]) -> [ReportListCellModel] {
103+
var cellModels = [ReportListCellModel]()
104+
for i in 0..<data.count {
105+
cellModels.append(ReportListCellModel.report(data[i].reportUserEmail, getKoreanDetailReport(data[i].type[0]), String(data[i].reportedCount+1), data[i].reportedBoardFilePath))
106+
}
107+
return cellModels
108+
}
109+
110+
func getCellModels(_ data: [UserReportListData]) -> [ReportListCellModel] {
111+
var cellModels = [ReportListCellModel]()
112+
for i in 0..<data.count {
113+
cellModels.append(ReportListCellModel.report(data[i].reportedUserEmail, getKoreanDetailReport(data[i].type[0]), String(data[i].reportedCount+1), nil))
114+
}
115+
return cellModels
116+
}
117+
118+
func getKoreanDetailReport(_ english: String) -> String {
98119
switch english {
99120
case "OBSCENE": return "음란성/선정성"
100121
case "WEATHER": return "날씨와맞지않음"

0 commit comments

Comments
 (0)