Skip to content

Commit 618807c

Browse files
committed
✨ [feat] 관리자 계정일때만 신고 리스트 보이게 분기 처리
1 parent ea183e9 commit 618807c

File tree

5 files changed

+71
-5
lines changed

5 files changed

+71
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ public struct UserData: Codable {
2222
public let phoneNumber: String?
2323
public let gender: String?
2424
public let birthday: String?
25+
public let role: String
2526
}

Fitfty/Projects/Core/Sources/Utilities/UserManager.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ public protocol UserManager {
1818
var location: AnyPublisher<(longitude: Double, latitude: Double)?, Never> { get }
1919
var gender: Gender? { get }
2020
var isGuest: AnyPublisher<Bool, Never> { get }
21-
21+
var isAdmin: AnyPublisher<Bool, Never> { get }
2222
func updateUserState(_ state: Bool)
2323
func updateCurrentLocation(_ address: Address)
2424
func updateGender(_ gender: Gender)
2525
func updateGuestState(_ isGuest: Bool)
2626
func updateCompletedWelcomePage()
2727
func getCurrentGuestState() -> Bool
28-
28+
func updateAdminState(_ isAdmin: Bool)
29+
func getAdminState() -> Bool
2930
}
3031

3132
public final class DefaultUserManager {
@@ -37,6 +38,7 @@ public final class DefaultUserManager {
3738
private var _location: CurrentValueSubject<(longitude: Double, latitude: Double)?, Never> = .init(nil)
3839
private var _gender: Gender?
3940
private var _guestState: CurrentValueSubject<Bool, Never> = .init(true)
41+
private var _adminState: CurrentValueSubject<Bool, Never> = .init(false)
4042

4143
private var cancellables: Set<AnyCancellable> = .init()
4244

@@ -64,6 +66,7 @@ extension DefaultUserManager: UserManager {
6466
public var location: AnyPublisher<(longitude: Double, latitude: Double)?, Never> { _location.eraseToAnyPublisher() }
6567
public var gender: Gender? { _gender }
6668
public var isGuest: AnyPublisher<Bool, Never> { _guestState.eraseToAnyPublisher() }
69+
public var isAdmin: AnyPublisher<Bool, Never> { _guestState.eraseToAnyPublisher() }
6770

6871
public func updateUserState(_ state: Bool) {
6972
localStorage.write(key: .isNewUser, value: state)
@@ -94,6 +97,14 @@ extension DefaultUserManager: UserManager {
9497
public func getCurrentGuestState() -> Bool {
9598
return _guestState.value
9699
}
100+
101+
public func updateAdminState(_ isAdmin: Bool) {
102+
_adminState.send(isAdmin)
103+
}
104+
105+
public func getAdminState() -> Bool {
106+
return _adminState.value
107+
}
97108

98109
}
99110

Fitfty/Projects/MainFeed/Sources/Main/Home/ViewModel/MainViewModel.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,15 @@ private extension MainViewModel {
185185
}
186186
} else {
187187
let userPrivacy = try await self.getUserPrivacy()
188-
self.myUserToken = userPrivacy.data?.userToken
189-
188+
guard let data = userPrivacy.data else {
189+
return
190+
}
191+
self.myUserToken = data.userToken
192+
if data.role == "ROLE_ADMIN" {
193+
userManager.updateAdminState(true)
194+
} else {
195+
userManager.updateAdminState(false)
196+
}
190197
for i in 0..<codyList.count {
191198
list.append((codyList[i], codyList[i].userToken == self.myUserToken ? .myProfile : .userProfile))
192199
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// ReportListSection.swift
3+
// Setting
4+
//
5+
// Created by 임영선 on 2023/02/16.
6+
// Copyright © 2023 Fitfty. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct ReportListSection {
12+
let sectionKind: ReportListSectionKind
13+
var items: [ReportListCellModel]
14+
}
15+
16+
public enum ReportListSectionKind {
17+
case report
18+
19+
init?(index: Int) {
20+
switch index {
21+
case 0: self = .report
22+
default: return nil
23+
}
24+
}
25+
26+
}
27+
28+
public enum ReportListCellModel: Hashable {
29+
case report(String, String, String, String?)
30+
31+
public func hash(into hasher: inout Hasher) {
32+
switch self {
33+
case .report(let account, let detailReport, let count, let filepath):
34+
hasher.combine(account)
35+
hasher.combine(detailReport)
36+
hasher.combine(count)
37+
hasher.combine(filepath)
38+
}
39+
}
40+
}

Fitfty/Projects/Setting/Sources/Home/ViewController/SettingViewController.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import UIKit
1010
import Common
11+
import Core
1112

1213
public final class SettingViewController: UIViewController {
1314

@@ -16,6 +17,8 @@ public final class SettingViewController: UIViewController {
1617

1718
private var dataSource: UICollectionViewDiffableDataSource<SettingViewSection, Setting>?
1819

20+
private let isAdmin = DefaultUserManager.shared.getAdminState()
21+
1922
public override func viewDidLoad() {
2023
super.viewDidLoad()
2124
setUp()
@@ -132,7 +135,11 @@ private extension SettingViewController {
132135
private func applySnapshot() {
133136
var snapshot = NSDiffableDataSourceSnapshot<SettingViewSection, Setting>()
134137
snapshot.appendSections([.setting])
135-
snapshot.appendItems(Setting.adminSettings())
138+
if isAdmin {
139+
snapshot.appendItems(Setting.adminSettings())
140+
} else {
141+
snapshot.appendItems(Setting.userSettings())
142+
}
136143
dataSource?.apply(snapshot)
137144
}
138145
}

0 commit comments

Comments
 (0)