git.iko.soy/dashared/hookah-tau
on develop help sign in
Теперь можно добавлять администратора через профиль :)
commit1f3f41c6f33ace7c5a99e1627752d980c265c0e7 authorDarya Rednikina <rednikina.com@yandex.ru> dateFri 20 Dec 2019, 13:58 (7 years ago) parent87fcf7e
13 files changed+168−13
Hookah Tau.xcodeproj/project.pbxproj+24 Hookah Tau/API/Reservations api/ReservationsService.swift+1−1 Hookah Tau/API/Reservations api/Resolvers/Admin/AReservationsResolver.swift+1−1 Hookah Tau/API/Settings/Resolvers/AddOtherAdminResolver.swift+35 Hookah Tau/API/Settings/SettingsService.swift+34 Hookah Tau/Controllers/Admin/Clients/ClientsViewController.swift+5 Hookah Tau/Controllers/Admin/Reservations/Views/No reserv/AdminNoReservationsView.swift+1−1 Hookah Tau/Controllers/BaseViewController.swift+1−1 Hookah Tau/Controllers/Client/Profile/ProfileChangeCoordinator.swift+6−4 Hookah Tau/Controllers/Client/Profile/ProfileChangeViewController.swift+22−3 Hookah Tau/Controllers/Client/Profile/Views/ChangeView.swift+32−1 Hookah Tau/Extensions+String.swift+5 Hookah Tau/Models/Reservation.swift+1−1
Hookah Tau.xcodeproj/project.pbxproj+24
@@ -69,6 +69,8 @@
6969 12B3A7AF23AC1872009E2FA6 /* AdminNoReservationsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12B3A7AE23AC1872009E2FA6 /* AdminNoReservationsView.swift */; };
7070 12B3A7B123AC1885009E2FA6 /* AdminNoReservationsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 12B3A7B023AC1885009E2FA6 /* AdminNoReservationsView.xib */; };
7171 12B3A7B423AC1D09009E2FA6 /* AdminReservationCellView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 12B3A7B323AC1D09009E2FA6 /* AdminReservationCellView.xib */; };
72+ 12B3A7B723ACCD07009E2FA6 /* SettingsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12B3A7B623ACCD07009E2FA6 /* SettingsService.swift */; };
73+ 12B3A7B923ACCD83009E2FA6 /* AddOtherAdminResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12B3A7B823ACCD83009E2FA6 /* AddOtherAdminResolver.swift */; };
7274 12B4447C238EF25C000B6B16 /* CreateReservationResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12B4447B238EF25C000B6B16 /* CreateReservationResolver.swift */; };
7375 12B6A60F235B857A00898B31 /* ProfileChangeCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12B6A60E235B857A00898B31 /* ProfileChangeCoordinator.swift */; };
7476 12B6A611235B8EC500898B31 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12B6A610235B8EC500898B31 /* User.swift */; };
@@ -217,6 +219,8 @@
217219 12B3A7AE23AC1872009E2FA6 /* AdminNoReservationsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminNoReservationsView.swift; sourceTree = "<group>"; };
218220 12B3A7B023AC1885009E2FA6 /* AdminNoReservationsView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AdminNoReservationsView.xib; sourceTree = "<group>"; };
219221 12B3A7B323AC1D09009E2FA6 /* AdminReservationCellView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AdminReservationCellView.xib; sourceTree = "<group>"; };
222+ 12B3A7B623ACCD07009E2FA6 /* SettingsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsService.swift; sourceTree = "<group>"; };
223+ 12B3A7B823ACCD83009E2FA6 /* AddOtherAdminResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddOtherAdminResolver.swift; sourceTree = "<group>"; };
220224 12B4447B238EF25C000B6B16 /* CreateReservationResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateReservationResolver.swift; sourceTree = "<group>"; };
221225 12B6A60E235B857A00898B31 /* ProfileChangeCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileChangeCoordinator.swift; sourceTree = "<group>"; };
222226 12B6A610235B8EC500898B31 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
@@ -531,6 +535,7 @@
531535 12838EB923679AEB00CEF108 /* API */ = {
532536 isa = PBXGroup;
533537 children = (
538+ 12B3A7B523ACCCD0009E2FA6 /* Settings */,
534539 12838EA8236764A600CEF108 /* APIClient.swift */,
535540 12838EB3236779C700CEF108 /* ApiResolver.swift */,
536541 12838EAF236777D400CEF108 /* ServerError.swift */,
@@ -589,6 +594,23 @@
589594 path = "No reserv";
590595 sourceTree = "<group>";
591596 };
597+ 12B3A7B523ACCCD0009E2FA6 /* Settings */ = {
598+ isa = PBXGroup;
599+ children = (
600+ 12B3A7B623ACCD07009E2FA6 /* SettingsService.swift */,
601+ 12B3A7BA23ACCD88009E2FA6 /* Resolvers */,
602+ );
603+ path = Settings;
604+ sourceTree = "<group>";
605+ };
606+ 12B3A7BA23ACCD88009E2FA6 /* Resolvers */ = {
607+ isa = PBXGroup;
608+ children = (
609+ 12B3A7B823ACCD83009E2FA6 /* AddOtherAdminResolver.swift */,
610+ );
611+ path = Resolvers;
612+ sourceTree = "<group>";
613+ };
592614 12BD95AE237EBE52009614D8 /* Maps */ = {
593615 isa = PBXGroup;
594616 children = (
@@ -1096,6 +1118,7 @@
10961118 12230AF723900D44004A01E5 /* EstablishmentResolver.swift in Sources */,
10971119 1246B719235CD3AD004CBFA1 /* NoReservationsView.swift in Sources */,
10981120 F3895F4A233D323700FA6A37 /* CodeCoordinator.swift in Sources */,
1121+ 12B3A7B923ACCD83009E2FA6 /* AddOtherAdminResolver.swift in Sources */,
10991122 12E3507F239FDFC2004BB188 /* ClientProfileCoordinator.swift in Sources */,
11001123 12838EB4236779C700CEF108 /* ApiResolver.swift in Sources */,
11011124 12838EA9236764A600CEF108 /* APIClient.swift in Sources */,
@@ -1162,6 +1185,7 @@
11621185 F3851B302340A513009EE0B6 /* RegistationViewModel.swift in Sources */,
11631186 12B3A7AF23AC1872009E2FA6 /* AdminNoReservationsView.swift in Sources */,
11641187 12838EAE2367701300CEF108 /* AuthorizationService.swift in Sources */,
1188+ 12B3A7B723ACCD07009E2FA6 /* SettingsService.swift in Sources */,
11651189 12C72EDF23537D1B00AD7004 /* ProfileCoordinator.swift in Sources */,
11661190 12E3507D239FD1F3004BB188 /* ClientReservationsResolver.swift in Sources */,
11671191 12EA994E2362FCE8005D9FE9 /* AddressView.swift in Sources */,
Hookah Tau/API/Reservations api/ReservationsService.swift+1−1
@@ -164,7 +164,7 @@ class ReservationsService {
164164 return
165165 }
166166
167− completion(.success(decodedData.newAdmin))
167+ completion(.success(decodedData.reservations))
168168 return
169169 }
170170 }
Hookah Tau/API/Reservations api/Resolvers/Admin/AReservationsResolver.swift+1−1
@@ -9,7 +9,7 @@
99import Foundation
1010
1111struct AReservationResponse: MyCodable {
12− var newAdmin: [ReservationWithUser]
12+ var reservations: [ReservationWithUser]
1313}
1414
1515/// `/admin/reservations/{establishment id}`
Hookah Tau/API/Settings/Resolvers/AddOtherAdminResolver.swiftnew file+35
@@ -0,0 +1,35 @@
1+//
2+// AddOtherAdminResolver.swift
3+// Hookah Tau
4+//
5+// Created by cstore on 20/12/2019.
6+// Copyright © 2019 Daria Rednikina. All rights reserved.
7+//
8+
9+import Foundation
10+
11+/// `PUT /admin/other`
12+class AddOtherAdminResolver: ApiResolver {
13+ /// Request struct
14+ struct Request: MyCodable {
15+ var newAdmin: String
16+ }
17+
18+ var name: String {
19+ return "/other"
20+ }
21+
22+ var groupName: String? {
23+ return "/admin"
24+ }
25+
26+ var phone: String
27+
28+ init(phone: String) {
29+ self.phone = phone
30+ }
31+
32+ func parameters() -> MyCodable? {
33+ return Request(newAdmin: phone)
34+ }
35+}
Hookah Tau/API/Settings/SettingsService.swiftnew file+34
@@ -0,0 +1,34 @@
1+//
2+// AdminServise.swift
3+// Hookah Tau
4+//
5+// Created by cstore on 20/12/2019.
6+// Copyright © 2019 Daria Rednikina. All rights reserved.
7+//
8+
9+import Foundation
10+
11+class SettingsService {
12+
13+ private var apiClient: APIClient
14+
15+ init(apiClient: APIClient) {
16+ self.apiClient = apiClient
17+ }
18+
19+ func addOtherAdmin(phone: String, completion: @escaping ((Bool) -> Void)) {
20+ let resolver = AddOtherAdminResolver(phone: phone)
21+ let request = ApiRequest(resolver: resolver, httpMethod: .put)
22+
23+ apiClient.load(request: request.request) { result in
24+ switch result {
25+ case .failure:
26+ completion(false)
27+ return
28+ case .success:
29+ completion(true)
30+ return
31+ }
32+ }
33+ }
34+}
Hookah Tau/Controllers/Admin/Clients/ClientsViewController.swift+5
@@ -14,6 +14,7 @@ class ClientsViewController: UITableViewController {
1414
1515 var dataSource: [FullUser] = [] {
1616 didSet {
17+ print(dataSource)
1718 tableView.reloadData()
1819 }
1920 }
@@ -29,6 +30,10 @@ class ClientsViewController: UITableViewController {
2930
3031 navigationItem.title = "Клиенты"
3132 clientsService = ClientsService(apiClient: APIClient.shared)
33+ }
34+
35+ override func viewDidAppear(_ animated: Bool) {
36+ super.viewDidAppear(animated)
3237 loadClients()
3338 }
3439
Hookah Tau/Controllers/Admin/Reservations/Views/No reserv/AdminNoReservationsView.swift+1−1
@@ -15,7 +15,7 @@ class AdminNoReservationsView: UIView {
1515 @IBOutlet weak var bookButton: Button? {
1616 didSet {
1717 let style = BlackButtonStyle()
18− style.apply(to: bookButton)
18+ style.apply(to: bookButton, withTitle: "ЗАБРОНИРОВАТЬ")
1919 }
2020 }
2121
Hookah Tau/Controllers/BaseViewController.swift+1−1
@@ -111,7 +111,7 @@ class BaseViewController: UIViewController {
111111 // MARK: - Alert
112112
113113 func displayAlert(forError error: GeneralError = GeneralError.noData, with message: String? = nil) {
114− var title: String? = message != nil ? error.localizedDescription : message
114+ var title: String? = message == nil ? error.localizedDescription : message
115115 switch error {
116116 case .serverError(let se):
117117 title = se.error
Hookah Tau/Controllers/Client/Profile/ProfileChangeCoordinator.swift+6−4
@@ -29,10 +29,12 @@ class ProfileChangeCoordinator: BaseCoordinator {
2929 }
3030
3131 /// Done
32− func update(withModel model: User) {
33− for controller in navigationController?.viewControllers ?? [] {
34− guard let updatableController = controller as? UserUpdate else { continue }
35− updatableController.updateUser(withModel: model)
32+ func update(withModel model: User?) {
33+ if let model = model {
34+ for controller in navigationController?.viewControllers ?? [] {
35+ guard let updatableController = controller as? UserUpdate else { continue }
36+ updatableController.updateUser(withModel: model)
37+ }
3638 }
3739
3840 didEndFlow?()
Hookah Tau/Controllers/Client/Profile/ProfileChangeViewController.swift+22−3
@@ -23,6 +23,8 @@ class ProfileChangeViewController: BaseViewController {
2323
2424 var changeView: ChangeView?
2525
26+ var settingsService: SettingsService?
27+
2628 var contentView: UIView = {
2729 let view = UIView()
2830 view.translatesAutoresizingMaskIntoConstraints = false
@@ -57,6 +59,8 @@ class ProfileChangeViewController: BaseViewController {
5759
5860 setUpView()
5961 setUpKeyboard()
62+
63+ settingsService = SettingsService(apiClient: APIClient.shared)
6064 }
6165
6266 func setUpView() {
@@ -86,15 +90,30 @@ class ProfileChangeViewController: BaseViewController {
8690 var userModel = model.userModel
8791 switch model.editingOption {
8892 case .invite:
89− print("New person is added")
90− return
93+ addNewAdmin(phone: text.toApiPhoneNumberFormat())
9194 case .name:
95+ // TODO:-f
9296 userModel.name = text
97+ coordinator?.update(withModel: userModel)
9398 case .phone:
99+ // TODO:-
94100 userModel.phoneNumber = text
101+ coordinator?.update(withModel: userModel)
95102 }
96103
97− coordinator?.update(withModel: userModel)
98104 }
99105
106+ func addNewAdmin(phone: String) {
107+ doneButton.loading = true
108+
109+ settingsService?.addOtherAdmin(phone: phone) { [weak self] res in
110+ if res {
111+ self?.coordinator?.update(withModel: nil)
112+ } else {
113+ self?.displayAlert(with: "Что-то пошло не так!\nПопробуй еще раз")
114+ }
115+
116+ self?.doneButton.loading = false
117+ }
118+ }
100119}
Hookah Tau/Controllers/Client/Profile/Views/ChangeView.swift+32−1
@@ -11,15 +11,20 @@ import UIKit
1111
1212class ChangeView: UIView {
1313
14+ var type: EditingOption = .invite
15+
1416 @IBOutlet weak var titleLabel: UILabel?
1517
1618 @IBOutlet weak var textField: UITextField?
1719
1820 func bind(withModel model: ChangeModel) {
21+ self.textField?.delegate = self
22+ self.type = model.editingOption
23+
1924 switch model.editingOption {
2025 case .invite:
2126 titleLabel?.text = "Добавить администратора"
22− textField?.placeholder = "+ 7 888 888 88 88"
27+ textField?.placeholder = "+ 7 (888) 888-88-88"
2328 textField?.keyboardType = .numberPad
2429 case .name:
2530 titleLabel?.text = "Имя"
@@ -32,3 +37,29 @@ class ChangeView: UIView {
3237 }
3338 }
3439}
40+
41+extension ChangeView: UITextFieldDelegate {
42+
43+ func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
44+ let newString = (textField.text! as NSString).replacingCharacters(in: range, with: string)
45+ textField.text = formattedNumber(newString)
46+ return false
47+ }
48+
49+ private func formattedNumber(_ number: String) -> String {
50+ let cleanPhoneNumber = number.components(separatedBy: CharacterSet.decimalDigits.inverted).joined()
51+
52+ var result = ""
53+ let phoneMask = "+X (XXX) XXX XX XX"
54+ var index = cleanPhoneNumber.startIndex
55+ for ch in phoneMask where index < cleanPhoneNumber.endIndex {
56+ if ch == "X" {
57+ result.append(cleanPhoneNumber[index])
58+ index = cleanPhoneNumber.index(after: index)
59+ } else {
60+ result.append(ch)
61+ }
62+ }
63+ return result
64+ }
65+}
Hookah Tau/Extensions+String.swift+5
@@ -28,4 +28,9 @@ extension String {
2828 }
2929 return result
3030 }
31+
32+ /// Gets +7 9(XX) XXX-XX-XX returns XXXXXXXXX
33+ func toApiPhoneNumberFormat() -> String {
34+ return String(self.filter{ $0.isNumber }.dropFirst(2))
35+ }
3136}
Hookah Tau/Models/Reservation.swift+1−1
@@ -51,7 +51,7 @@ struct ReservationData: MyCodable {
5151/// Структура для получения респонса на `GET /admin/reservations/{establishment id}`
5252struct ReservationWithUser: MyCodable {
5353
54− var uuis: String
54+ var uuid: String
5555 var establishment: Int
5656 var startTime: Date
5757 var endTime: Date