git.iko.soy/dashared/hookah-tau
on develop help sign in
Добавила фильтрацию на даты, подстроилась под новую структуру с reservations/all
f964fc9Darya Rednikina
Hookah Tau.xcodeproj/project.pbxproj+20
@@ -36,6 +36,9 @@
36 124D007C23721FD400AE76B9 /* Reservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124D007B23721FD400AE76B9 /* Reservation.swift */; };
36 124D007C23721FD400AE76B9 /* Reservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124D007B23721FD400AE76B9 /* Reservation.swift */; };
37 124D007F237222B200AE76B9 /* ReservationsResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124D007E237222B200AE76B9 /* ReservationsResolver.swift */; };
37 124D007F237222B200AE76B9 /* ReservationsResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124D007E237222B200AE76B9 /* ReservationsResolver.swift */; };
38 124D0081237222C900AE76B9 /* ReservationsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124D0080237222C900AE76B9 /* ReservationsService.swift */; };
38 124D0081237222C900AE76B9 /* ReservationsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 124D0080237222C900AE76B9 /* ReservationsService.swift */; };
39+ 125AE51D2395583E00F847BD /* ChangeReservationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125AE51C2395583E00F847BD /* ChangeReservationCoordinator.swift */; };
40+ 125AE51F2395585300F847BD /* ChangeReservationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125AE51E2395585300F847BD /* ChangeReservationViewController.swift */; };
41+ 125AE5212395753400F847BD /* HFunc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125AE5202395753400F847BD /* HFunc.swift */; };
39 12838EA9236764A600CEF108 /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12838EA8236764A600CEF108 /* APIClient.swift */; };
42 12838EA9236764A600CEF108 /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12838EA8236764A600CEF108 /* APIClient.swift */; };
40 12838EAC2367689600CEF108 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 12838EAB2367689600CEF108 /* Alamofire */; };
43 12838EAC2367689600CEF108 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 12838EAB2367689600CEF108 /* Alamofire */; };
41 12838EAE2367701300CEF108 /* AuthorizationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12838EAD2367701300CEF108 /* AuthorizationService.swift */; };
44 12838EAE2367701300CEF108 /* AuthorizationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12838EAD2367701300CEF108 /* AuthorizationService.swift */; };
@@ -156,6 +159,9 @@
156 124D007B23721FD400AE76B9 /* Reservation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reservation.swift; sourceTree = "<group>"; };
159 124D007B23721FD400AE76B9 /* Reservation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reservation.swift; sourceTree = "<group>"; };
157 124D007E237222B200AE76B9 /* ReservationsResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReservationsResolver.swift; sourceTree = "<group>"; };
160 124D007E237222B200AE76B9 /* ReservationsResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReservationsResolver.swift; sourceTree = "<group>"; };
158 124D0080237222C900AE76B9 /* ReservationsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReservationsService.swift; sourceTree = "<group>"; };
161 124D0080237222C900AE76B9 /* ReservationsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReservationsService.swift; sourceTree = "<group>"; };
162+ 125AE51C2395583E00F847BD /* ChangeReservationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeReservationCoordinator.swift; sourceTree = "<group>"; };
163+ 125AE51E2395585300F847BD /* ChangeReservationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChangeReservationViewController.swift; sourceTree = "<group>"; };
164+ 125AE5202395753400F847BD /* HFunc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HFunc.swift; sourceTree = "<group>"; };
159 12838EA8236764A600CEF108 /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = "<group>"; };
165 12838EA8236764A600CEF108 /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = "<group>"; };
160 12838EAD2367701300CEF108 /* AuthorizationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorizationService.swift; sourceTree = "<group>"; };
166 12838EAD2367701300CEF108 /* AuthorizationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorizationService.swift; sourceTree = "<group>"; };
161 12838EAF236777D400CEF108 /* ServerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerError.swift; sourceTree = "<group>"; };
167 12838EAF236777D400CEF108 /* ServerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerError.swift; sourceTree = "<group>"; };
@@ -420,6 +426,15 @@
420 path = Resolvers;
426 path = Resolvers;
421 sourceTree = "<group>";
427 sourceTree = "<group>";
422 };
428 };
429+ 125AE51B2395582900F847BD /* change */ = {
430+ isa = PBXGroup;
431+ children = (
432+ 125AE51C2395583E00F847BD /* ChangeReservationCoordinator.swift */,
433+ 125AE51E2395585300F847BD /* ChangeReservationViewController.swift */,
434+ );
435+ path = "change ";
436+ sourceTree = "<group>";
437+ };
423 12838EB923679AEB00CEF108 /* API */ = {
438 12838EB923679AEB00CEF108 /* API */ = {
424 isa = PBXGroup;
439 isa = PBXGroup;
425 children = (
440 children = (
@@ -448,6 +463,7 @@
448 12BD95B3237EC231009614D8 /* Steps */ = {
463 12BD95B3237EC231009614D8 /* Steps */ = {
449 isa = PBXGroup;
464 isa = PBXGroup;
450 children = (
465 children = (
466+ 125AE51B2395582900F847BD /* change */,
451 12230AEF239008F8004A01E5 /* Common */,
467 12230AEF239008F8004A01E5 /* Common */,
452 12BD95B4237EC23A009614D8 /* 1 */,
468 12BD95B4237EC23A009614D8 /* 1 */,
453 12F9652823868E4900FCA696 /* 2 */,
469 12F9652823868E4900FCA696 /* 2 */,
@@ -702,6 +718,7 @@
702 F31E20C62348DDB900BEA215 /* Extensions+UIView.swift */,
718 F31E20C62348DDB900BEA215 /* Extensions+UIView.swift */,
703 12050568238048CE00801618 /* Extensions+Date.swift */,
719 12050568238048CE00801618 /* Extensions+Date.swift */,
704 1205056A2380588C00801618 /* Extenstions+IBDesignable.swift */,
720 1205056A2380588C00801618 /* Extenstions+IBDesignable.swift */,
721+ 125AE5202395753400F847BD /* HFunc.swift */,
705 12838EB923679AEB00CEF108 /* API */,
722 12838EB923679AEB00CEF108 /* API */,
706 F30369BC2336861100A8EA84 /* Models */,
723 F30369BC2336861100A8EA84 /* Models */,
707 F3199E59233FD7F700F3C17A /* Views */,
724 F3199E59233FD7F700F3C17A /* Views */,
@@ -895,6 +912,7 @@
895 123615D12355141600D1122A /* ProfileView.swift in Sources */,
912 123615D12355141600D1122A /* ProfileView.swift in Sources */,
896 12F73B022357AD7B007D4476 /* ProfileChangeViewController.swift in Sources */,
913 12F73B022357AD7B007D4476 /* ProfileChangeViewController.swift in Sources */,
897 F3851B2E2340A444009EE0B6 /* TitleTextView.swift in Sources */,
914 F3851B2E2340A444009EE0B6 /* TitleTextView.swift in Sources */,
915+ 125AE51F2395585300F847BD /* ChangeReservationViewController.swift in Sources */,
898 12EA99462362B674005D9FE9 /* AddressCoordinator.swift in Sources */,
916 12EA99462362B674005D9FE9 /* AddressCoordinator.swift in Sources */,
899 12B6A613235B9B4300898B31 /* BaseViewController.swift in Sources */,
917 12B6A613235B9B4300898B31 /* BaseViewController.swift in Sources */,
900 12230AFA23901029004A01E5 /* DataStorage.swift in Sources */,
918 12230AFA23901029004A01E5 /* DataStorage.swift in Sources */,
@@ -910,6 +928,7 @@
910 12219CEF2353A63F0057DDEE /* ReservationsCoordinator.swift in Sources */,
928 12219CEF2353A63F0057DDEE /* ReservationsCoordinator.swift in Sources */,
911 12230AF423900BCB004A01E5 /* EstablishmentService.swift in Sources */,
929 12230AF423900BCB004A01E5 /* EstablishmentService.swift in Sources */,
912 12A07601237359BB00D749BB /* MapView1.swift in Sources */,
930 12A07601237359BB00D749BB /* MapView1.swift in Sources */,
931+ 125AE5212395753400F847BD /* HFunc.swift in Sources */,
913 12BD95B8237EDB01009614D8 /* TimePointView.swift in Sources */,
932 12BD95B8237EDB01009614D8 /* TimePointView.swift in Sources */,
914 12838EB2236779A000CEF108 /* AuthResolver.swift in Sources */,
933 12838EB2236779A000CEF108 /* AuthResolver.swift in Sources */,
915 12A075F72373535C00D749BB /* FirstStepReservationViewController.swift in Sources */,
934 12A075F72373535C00D749BB /* FirstStepReservationViewController.swift in Sources */,
@@ -962,6 +981,7 @@
962 12FC40382382C93D00AB593B /* TableButtonStyle.swift in Sources */,
981 12FC40382382C93D00AB593B /* TableButtonStyle.swift in Sources */,
963 12D8FA31237F08C700305F57 /* AllReservations.swift in Sources */,
982 12D8FA31237F08C700305F57 /* AllReservations.swift in Sources */,
964 12838EB0236777D400CEF108 /* ServerError.swift in Sources */,
983 12838EB0236777D400CEF108 /* ServerError.swift in Sources */,
984+ 125AE51D2395583E00F847BD /* ChangeReservationCoordinator.swift in Sources */,
965 );
985 );
966 runOnlyForDeploymentPostprocessing = 0;
986 runOnlyForDeploymentPostprocessing = 0;
967 };
987 };
Hookah Tau/Controllers/Client/Reservations/Active Reservations/ReservationsCoordinator.swift+14
@@ -29,4 +29,18 @@ class ReservationsCoordinator: BaseCoordinator {
29 }
29 }
30 addressCoordinator.start()
30 addressCoordinator.start()
31 }
31 }
32+
33+ func viewReservation(_ reservation: Reservation) {
34+ let thirdStepRCoordinator = ThirdStepReservationCoordinator(navigationController: navigationController)
35+ addDependency(thirdStepRCoordinator)
36+
37+ thirdStepRCoordinator.resrvation = reservation
38+
39+ thirdStepRCoordinator.didFinish = { [weak self] map in
40+ self?.removeDependency(thirdStepRCoordinator)
41+ self?.navigationController?.popViewController(animated: true)
42+ }
43+
44+ thirdStepRCoordinator.start()
45+ }
32}
46}
Hookah Tau/Controllers/Client/Reservations/Active Reservations/ReservationsViewController.swift+23−2
@@ -19,8 +19,10 @@ class ReservationsViewController: BaseViewController {
19 guard let empty = noReservationsView else { return }
19 guard let empty = noReservationsView else { return }
20 if activeReservations.isEmpty {
20 if activeReservations.isEmpty {
21 contentView.bringSubviewToFront(empty)
21 contentView.bringSubviewToFront(empty)
22+ empty.alpha = 1
22 } else {
23 } else {
23 contentView.sendSubviewToBack(empty)
24 contentView.sendSubviewToBack(empty)
25+ tableView?.alpha = 1
24 }
26 }
25
27
26 tableView?.reloadData()
28 tableView?.reloadData()
@@ -54,11 +56,21 @@ class ReservationsViewController: BaseViewController {
54
56
55 reservationsService = ReservationsService(apiClient: APIClient.shared)
57 reservationsService = ReservationsService(apiClient: APIClient.shared)
56
58
57− performUpdate()
58−
59 setUpContentView()
59 setUpContentView()
60 }
60 }
61
61
62+ override func viewWillAppear(_ animated: Bool) {
63+ super.viewWillAppear(animated)
64+
65+ tabBarController?.tabBar.isHidden = false
66+ }
67+
68+ override func viewDidAppear(_ animated: Bool) {
69+ super.viewDidAppear(animated)
70+
71+ performUpdate()
72+ }
73+
62 // MARK: - Setup
74 // MARK: - Setup
63
75
64 func setUpContentView() {
76 func setUpContentView() {
@@ -68,6 +80,8 @@ class ReservationsViewController: BaseViewController {
68 noReservationsView = NoReservationsView.loadFromNib()
80 noReservationsView = NoReservationsView.loadFromNib()
69 contentView.addSubviewThatFills(noReservationsView)
81 contentView.addSubviewThatFills(noReservationsView)
70 noReservationsView?.makeReservationButton?.addTarget(self, action: #selector(tapToMakeReservation), for: .touchUpInside)
82 noReservationsView?.makeReservationButton?.addTarget(self, action: #selector(tapToMakeReservation), for: .touchUpInside)
83+
84+ noReservationsView?.alpha = 0
71
85
72 // table
86 // table
73 contentView.addSubviewThatFills(tableView)
87 contentView.addSubviewThatFills(tableView)
@@ -79,6 +93,8 @@ class ReservationsViewController: BaseViewController {
79 tableView?.delegate = self
93 tableView?.delegate = self
80 tableView?.dataSource = self
94 tableView?.dataSource = self
81
95
96+ tableView?.alpha = 0
97+
82 tableView?.register(ReservationCell.self, forCellReuseIdentifier: reservationCell)
98 tableView?.register(ReservationCell.self, forCellReuseIdentifier: reservationCell)
83 }
99 }
84
100
@@ -135,6 +151,11 @@ extension ReservationsViewController: UITableViewDelegate, UITableViewDataSource
135 return cell
151 return cell
136 }
152 }
137
153
154+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
155+ let reservation = activeReservations[indexPath.row]
156+ coordinator?.viewReservation(reservation)
157+ }
158+
138 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
159 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
139 return UITableView.automaticDimension
160 return UITableView.automaticDimension
140 }
161 }
Hookah Tau/Controllers/Client/Reservations/Cells/Reservation/ReservationView.swift+19−1
@@ -29,7 +29,25 @@ class ReservationView: UIView {
29
29
30 tableImageView?.image = table.image
30 tableImageView?.image = table.image
31 adressLabel?.text = establishment.address
31 adressLabel?.text = establishment.address
32− maxPeopleLabel?.text = "\(model.numberOfGuests) человека"
32+ maxPeopleLabel?.text = "\(model.numberOfGuests) " + (2...4 ~= model.numberOfGuests ? "человека" : "человек")
33+
34+ let (date, time) = format(model.startTime, model.endTime)
35+ dateLabel?.text = date
36+ timeLabel?.text = time
33 }
37 }
34
38
39+ private func format(_ startDate: Date, _ endDate: Date) -> (date: String, time: String) {
40+ let dateFormatter = DateFormatter()
41+ dateFormatter.calendar = Calendar.current
42+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
43+ dateFormatter.dateFormat = "d MMMM"
44+ dateFormatter.locale = Locale(identifier: "ru_RU")
45+
46+ let dateStr = "\(dateFormatter.string(from: startDate))"
47+
48+ dateFormatter.dateFormat = "HH:mm"
49+ let timeStr = "\(dateFormatter.string(from: startDate)) — \(dateFormatter.string(from: endDate))"
50+
51+ return (dateStr, timeStr)
52+ }
35}
53}
Hookah Tau/Controllers/Client/Reservations/Maps/MapView.swift+1
@@ -26,6 +26,7 @@ class MapImageScroll: UIView {
26 func scrollToTable(table: Int) {
26 func scrollToTable(table: Int) {
27 guard let tableButton = tables[table] else { return }
27 guard let tableButton = tables[table] else { return }
28
28
29+ tableButton.select()
29 img.bringSubviewToFront(shadowView)
30 img.bringSubviewToFront(shadowView)
30 img.bringSubviewToFront(tableButton)
31 img.bringSubviewToFront(tableButton)
31
32
Hookah Tau/Controllers/Client/Reservations/Reservation.storyboard+3−3
@@ -81,14 +81,14 @@
81 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
81 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
82 <subviews>
82 <subviews>
83 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="e2X-iN-FVj">
83 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="e2X-iN-FVj">
84− <rect key="frame" x="0.0" y="502" width="414" height="394"/>
84+ <rect key="frame" x="0.0" y="556" width="414" height="340"/>
85 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
85 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
86 <constraints>
86 <constraints>
87− <constraint firstAttribute="height" constant="394" id="5U9-DA-Asv"/>
87+ <constraint firstAttribute="height" constant="340" id="5U9-DA-Asv"/>
88 </constraints>
88 </constraints>
89 </view>
89 </view>
90 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lUx-gC-C8T">
90 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="lUx-gC-C8T">
91− <rect key="frame" x="0.0" y="44" width="414" height="458"/>
91+ <rect key="frame" x="0.0" y="44" width="414" height="512"/>
92 <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
92 <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
93 </view>
93 </view>
94 </subviews>
94 </subviews>
Hookah Tau/Controllers/Client/Reservations/Steps/1/FirstStepReservationViewController.swift+5−4
@@ -129,7 +129,7 @@ class FirstStepReservationViewController: BaseViewController {
129 }
129 }
130
130
131 func updateChildViewControllerWithChosenId(_ id: Int) {
131 func updateChildViewControllerWithChosenId(_ id: Int) {
132− let reservationsForTable = allReservations?.reservations[id] ?? [:]
132+ let reservationsForTable = allReservations?.reservations[id] ?? []
133 firstStepView?.setUp(reservationsForTable)
133 firstStepView?.setUp(reservationsForTable)
134 }
134 }
135
135
@@ -138,9 +138,10 @@ class FirstStepReservationViewController: BaseViewController {
138 @objc func continueBooking() {
138 @objc func continueBooking() {
139 let map = mapView
139 let map = mapView
140
140
141− guard let startTime = firstStepView?.fullDate else { return }
141+ guard let startTime = firstStepView?.fullDate else { return }
142
142
143− let reservPeriods = allReservations?.reservations[tableId]?[startTime.getDMY()] ?? []
143+ let reservPeriods = HFunc.main.filterPeriodsInDate(allReservations?.reservations[tableId] ?? [],
144+ startTime)
144
145
145 let model = SecondStepModel(establishment: establishmentId,
146 let model = SecondStepModel(establishment: establishmentId,
146 table: tableId,
147 table: tableId,
@@ -169,7 +170,7 @@ extension FirstStepReservationViewController: MapHandler {
169
170
170extension FirstStepReservationViewController: MapUpdater {
171extension FirstStepReservationViewController: MapUpdater {
171 func update(_ date: Date) {
172 func update(_ date: Date) {
172− let areBooked = allReservations?.intervals[date.getDMY()]?[date] ?? []
173+ let areBooked = allReservations?.intervals[date] ?? []
173
174
174 if Set(areBooked).contains(tableId) {
175 if Set(areBooked).contains(tableId) {
175 continueButton.availiable = false
176 continueButton.availiable = false
Hookah Tau/Controllers/Client/Reservations/Steps/1/FirstStepView.swift+15−6
@@ -50,17 +50,21 @@ class FirstStepView: UIView {
50 guard
50 guard
51 let date = fullDate?.getDMY()
51 let date = fullDate?.getDMY()
52 else { return }
52 else { return }
53+
54+ let bookings = HFunc.main.filterPeriodsInDate(bookingsForDates, date)
53− setUpBookingsForIntervals(reservations: bookingsForDates[date] ?? [])
55+ setUpBookingsForIntervals(reservations: bookings)
54 }
56 }
55 }
57 }
56
58
57− var bookingsForDates: [Date: [ReservationPeriod]] = [:] {
59+ var bookingsForDates: [ReservationPeriod] = [] {
58 didSet {
60 didSet {
59 guard
61 guard
60 let date = fullDate?.getDMY()
62 let date = fullDate?.getDMY()
61 else { return }
63 else { return }
62
64
65+ let bookings = HFunc.main.filterPeriodsInDate(bookingsForDates, date)
66+
63− setUpBookingsForIntervals(reservations: bookingsForDates[date] ?? [])
67+ setUpBookingsForIntervals(reservations: bookings)
64 }
68 }
65 }
69 }
66
70
@@ -158,7 +162,12 @@ class FirstStepView: UIView {
158 let d = reservation.duration * Constants.widthTimePoint
162 let d = reservation.duration * Constants.widthTimePoint
159
163
160 let startTime = s < 0 ? 0 : s
164 let startTime = s < 0 ? 0 : s
165+ var duration = 0
166+ if s < 0 {
167+ duration = reservation.endTime.getMinutesPeriods(fromStart: startDate) * Constants.widthTimePoint
168+ } else {
161− let duration = (s + d) > Constants.widthOfIntervals ? Constants.widthOfIntervals - s : d
169+ duration = (s + d) > Constants.widthOfIntervals ? Constants.widthOfIntervals - s : d
170+ }
162
171
163 NSLayoutConstraint.activate([
172 NSLayoutConstraint.activate([
164 uiview.bottomAnchor.constraint(equalToSystemSpacingBelow: scrollViewIntervals.bottomAnchor, multiplier: 0),
173 uiview.bottomAnchor.constraint(equalToSystemSpacingBelow: scrollViewIntervals.bottomAnchor, multiplier: 0),
@@ -184,14 +193,14 @@ class FirstStepView: UIView {
184
193
185 datesScrollView.setContentOffset(CGPoint(x: abs(Constants.widthDate * Constants.daysCount / 2 - Int(edges.left)) + 8, y: 0),
194 datesScrollView.setContentOffset(CGPoint(x: abs(Constants.widthDate * Constants.daysCount / 2 - Int(edges.left)) + 8, y: 0),
186 animated: true)
195 animated: true)
187− scrollViewIntervals.setContentOffset(CGPoint(x: abs(Constants.widthTimePoint * Constants.day10MinPeriods / 2 - Int(edges.left)) + 5, y: 0),
196+ scrollViewIntervals.setContentOffset(CGPoint(x: abs(Constants.widthTimePoint * Constants.day10MinPeriods / 2 - Int(edges.left)) + 7, y: 0),
188 animated: true)
197 animated: true)
189 }
198 }
190
199
191
200
192 /// Method for setting up `stackViewIntervals` with appropriate busy intervals of chosen table
201 /// Method for setting up `stackViewIntervals` with appropriate busy intervals of chosen table
193 /// - Parameter data: Map of booked periods by key - date - is provided
202 /// - Parameter data: Map of booked periods by key - date - is provided
194− func setUp(_ data: [Date: [ReservationPeriod]]) {
203+ func setUp(_ data: [ReservationPeriod]) {
195 bookingsForDates = data
204 bookingsForDates = data
196 }
205 }
197
206
Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepReservationCoordinator.swift+4−8
@@ -19,6 +19,8 @@ class SecondStepReservationCoordinator: BaseCoordinator {
19
19
20 var mapView: MapImageScroll?
20 var mapView: MapImageScroll?
21
21
22+ var onBooking: ((MapImageScroll, Reservation) -> Void)?
23+
22 var vc: SecondStepReservationViewController?
24 var vc: SecondStepReservationViewController?
23
25
24 // MARK: - Lifecycle
26 // MARK: - Lifecycle
@@ -40,7 +42,7 @@ class SecondStepReservationCoordinator: BaseCoordinator {
40 didFinish?(mapView)
42 didFinish?(mapView)
41 }
43 }
42
44
43− func book() {
45+ func book(_ mapView: MapImageScroll?) {
44 let coordinator = ThirdStepReservationCoordinator(navigationController: navigationController)
46 let coordinator = ThirdStepReservationCoordinator(navigationController: navigationController)
45 addDependency(coordinator)
47 addDependency(coordinator)
46
48
@@ -52,13 +54,7 @@ class SecondStepReservationCoordinator: BaseCoordinator {
52 }
54 }
53 }
55 }
54
56
55− coordinator.wantsToBeChanged = { [weak self] reservation in
57+ coordinator.mapView = mapView
56− self?.navigationController?.popViewController(animated: false)
57− self?.removeDependency(coordinator)
58−
59−
60− }
61−
62 coordinator.start()
58 coordinator.start()
63 }
59 }
64}
60}
Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepReservationViewController.swift+8−1
@@ -65,6 +65,13 @@ class SecondStepReservationViewController: BaseViewController {
65
65
66 }
66 }
67
67
68+ override func viewWillAppear(_ animated: Bool) {
69+ super.viewWillAppear(animated)
70+
71+ tabBarController?.tabBar.isHidden = true
72+ }
73+
74+
68 // MARK: - Setup
75 // MARK: - Setup
69
76
70 func setupNavBar() {
77 func setupNavBar() {
@@ -122,6 +129,6 @@ class SecondStepReservationViewController: BaseViewController {
122 }
129 }
123
130
124 @objc func book() {
131 @objc func book() {
125− coordinator?.book()
132+ coordinator?.book(mapView)
126 }
133 }
127}
134}
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationCoordinator.swift+14−8
@@ -12,12 +12,12 @@ class ThirdStepReservationCoordinator: BaseCoordinator {
12
12
13 // MARK: - Properties
13 // MARK: - Properties
14
14
15− var didFinish: ((MapImageScroll) -> Void)?
15+ var didFinish: ((MapImageScroll?) -> Void)?
16
16
17− /// callback to change created booking
17+ var mapView: MapImageScroll?
18− var wantsToBeChanged: ((Reservation) -> Void)?
19
18
20− var mapView: UIView?
19+ /// Объект регистрации, созданной или существующей
20+ var resrvation: Reservation?
21
21
22 // MARK: - Lifecycle
22 // MARK: - Lifecycle
23
23
@@ -26,13 +26,19 @@ class ThirdStepReservationCoordinator: BaseCoordinator {
26 let reservationVC = storyboard.instantiateViewController(withIdentifier: "ThirdStepReservationViewController") as! ThirdStepReservationViewController
26 let reservationVC = storyboard.instantiateViewController(withIdentifier: "ThirdStepReservationViewController") as! ThirdStepReservationViewController
27
27
28 reservationVC.coordinator = self
28 reservationVC.coordinator = self
29−
29+ reservationVC.mapView = mapView
30+ reservationVC.reservation = resrvation
30
31
31 navigationController?.pushViewController(reservationVC, animated: false)
32 navigationController?.pushViewController(reservationVC, animated: false)
32 }
33 }
33
34
34− /// You need to pass `uuid` of the booking to be changed
35+ /// You need to pass reservation object and map describing booked table
35− func change(_ reservation: Reservation) {
36+ func change(_ reservation: Reservation, _ map: MapImageScroll) {
36− wantsToBeChanged?(reservation)
37+ //
38+ }
39+
40+ /// Goes back to `allReservations` screen
41+ func close() {
42+ didFinish?(nil)
37 }
43 }
38}
44}
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationViewController.swift+80−10
@@ -9,27 +9,42 @@
9import UIKit
9import UIKit
10
10
11class ThirdStepReservationViewController: BaseViewController {
11class ThirdStepReservationViewController: BaseViewController {
12+
13+ // MARK: - IBAOutlets
12
14
13 @IBOutlet weak var containerView: UIView!
15 @IBOutlet weak var containerView: UIView!
14
16
17+ @IBOutlet weak var contentForMap: UIView!
18+
19+ // MARK: - Properties
20+
21+ var mapView: MapImageScroll?
22+
15 weak var coordinator: ThirdStepReservationCoordinator?
23 weak var coordinator: ThirdStepReservationCoordinator?
16
24
17 var thirdStepView: ThirdStepView?
25 var thirdStepView: ThirdStepView?
18
26
19− @IBOutlet weak var contentForMap: UIView!
27+ var reservation: Reservation? {
20−
28+ didSet {
21− var mapView: MapImageScroll?
29+ guard let r = reservation,
30+ let data = TotalStorage.standard.getEstablishment(r.establishment)
31+ else { return }
32+
33+ navigationItem.title = data.address
34+ }
35+ }
22
36
23− var reservation: Reservation?
37+ var reservationService: ReservationsService?
24
38
39+ /// "Отменить бронь"
25 let cancelButton: Button = {
40 let cancelButton: Button = {
26 let button = Button()
41 let button = Button()
27 let style = BlackButtonStyle()
42 let style = BlackButtonStyle()
28 style.apply(to: button, withTitle: "ОТМЕНИТЬ БРОНЬ")
43 style.apply(to: button, withTitle: "ОТМЕНИТЬ БРОНЬ")
29− //button.addTarget(self, action: #selector(doneChanging), for: .touchUpInside)
30 return button
44 return button
31 }()
45 }()
32
46
47+ /// "Изменить бронь"
33 let changeButton: Button = {
48 let changeButton: Button = {
34 let button = Button()
49 let button = Button()
35 let style = BlackButtonStyle()
50 let style = BlackButtonStyle()
@@ -37,6 +52,8 @@ class ThirdStepReservationViewController: BaseViewController {
37 return button
52 return button
38 }()
53 }()
39
54
55+ // MARK: - Lifecycle
56+
40 override func viewDidLoad() {
57 override func viewDidLoad() {
41 super.viewDidLoad()
58 super.viewDidLoad()
42
59
@@ -44,17 +61,49 @@ class ThirdStepReservationViewController: BaseViewController {
44 setupContainer()
61 setupContainer()
45 setupButtons()
62 setupButtons()
46 setupMap()
63 setupMap()
64+
65+ reservationService = ReservationsService(apiClient: APIClient.shared)
66+ }
67+
68+ override func viewWillAppear(_ animated: Bool) {
69+ super.viewWillAppear(animated)
70+
71+ tabBarController?.tabBar.isHidden = true
47 }
72 }
73+
74+ // MARK: - Setup
48
75
49 func setupMap() {
76 func setupMap() {
77+ guard let reservation = reservation else {
78+ return
79+ }
80+
81+ if reservation.establishment == 1 {
82+ mapView = MapView1.loadFromNib()
83+ } else {
84+ mapView = MapView2.loadFromNib()
85+ }
86+
50 contentForMap.addSubviewThatFills(mapView)
87 contentForMap.addSubviewThatFills(mapView)
88+
89+ let width = view.frame.width
90+ mapView?.scrollViewParent.contentInset = UIEdgeInsets(top: 0,
91+ left: width / 2,
92+ bottom: 300,
93+ right: width / 2)
94+
95+ mapView?.scrollViewParent.setContentOffset(CGPoint(x: 0, y: -100), animated: false)
96+
97+ mapView?.isUserInteractionEnabled = false
98+ mapView?.scrollToTable(table: reservation.reservedTable)
51 }
99 }
52
100
53 func setupContainer() {
101 func setupContainer() {
54 thirdStepView = ThirdStepView.loadFromNib()
102 thirdStepView = ThirdStepView.loadFromNib()
55 containerView.addSubviewThatFills(thirdStepView)
103 containerView.addSubviewThatFills(thirdStepView)
104+
56−// guard let model = model else { return }
105+ guard let res = reservation else { return }
57−// thirdStepView?.bind(withModel: model)
106+ thirdStepView?.bind(withModel: res)
58 }
107 }
59
108
60 func setupButtons() {
109 func setupButtons() {
@@ -63,17 +112,38 @@ class ThirdStepReservationViewController: BaseViewController {
63 constant: -containerView.frame.height - 20)
112 constant: -containerView.frame.height - 20)
64
113
65 changeButton.addTarget(self, action: #selector(change), for: .touchUpInside)
114 changeButton.addTarget(self, action: #selector(change), for: .touchUpInside)
115+ cancelButton.addTarget(self, action: #selector(cancelBooking), for: .touchUpInside)
116+ thirdStepView?.closeButton.addTarget(self, action: #selector(close), for: .touchUpInside)
66 }
117 }
67
118
68
119
69 // MARK: - handlers for buttons
120 // MARK: - handlers for buttons
70
121
71 @objc func change() {
122 @objc func change() {
123+ guard
72− guard let res = reservation else { return }
124+ let res = reservation,
125+ let map = mapView
126+ else { return }
127+
73− coordinator?.change(res)
128+ coordinator?.change(res, map)
74 }
129 }
75
130
76− @objc func cancel() {
131+ @objc func cancelBooking() {
132+ guard let res = reservation else { return }
77
133
134+ cancelButton.loading = true
135+ reservationService?.deleteReservation(uuid: res.uuid, completion: { [weak self] (result) in
136+ self?.cancelButton.loading = false
137+
138+ if result {
139+ self?.close()
140+ } else {
141+ self?.displayAlert(with: "Не удалось отменить бронь, попробуйте еще раз!")
142+ }
143+ })
144+ }
145+
146+ @objc func close() {
147+ coordinator?.close()
78 }
148 }
79}
149}
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepView.swift+23−2
@@ -25,11 +25,32 @@ class ThirdStepView: UIView {
25 }
25 }
26 }
26 }
27
27
28−
29 @IBOutlet weak var timeInterval: UIView!
28 @IBOutlet weak var timeInterval: UIView!
30
29
30+ func bind(withModel model: Reservation) {
31+ let date = format(model.startTime, model.endTime)
32+
33+ totalLabel.text = "Забронирован \(model.reservedTable) столик на \(model.numberOfGuests)-х\n \(date)"
34+
35+ infoLabel.text = "Минимальное количество кальянов: \(countTotalNumber(model.numberOfGuests))"
36+ }
37+
38+ private func format(_ startDate: Date, _ endDate: Date) -> String {
39+ let dateFormatter = DateFormatter()
40+ dateFormatter.calendar = Calendar.current
41+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
42+ dateFormatter.dateFormat = "MM.dd, с HH:mm по"
31
43
32− func bind(withModel model: ThirdStepViewModel) {
44+ var newDateString = "\(dateFormatter.string(from: startDate))"
45+
46+ dateFormatter.dateFormat = "HH:mm"
47+ newDateString += " \(dateFormatter.string(from: endDate))"
33
48
49+ return newDateString
50+ }
51+
52+ private func countTotalNumber(_ people: Int) -> Int {
53+ let num = people > 6 ? 2 : 1
54+ return num
34 }
55 }
35}
56}
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepView.xib+6−6
@@ -12,7 +12,7 @@
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
12 <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
13 <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14 <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ThirdStepView" customModule="Hookah_Tau" customModuleProvider="target">
14 <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="ThirdStepView" customModule="Hookah_Tau" customModuleProvider="target">
15− <rect key="frame" x="0.0" y="0.0" width="414" height="394"/>
15+ <rect key="frame" x="0.0" y="0.0" width="414" height="340"/>
16 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
17 <subviews>
17 <subviews>
18 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="center" spacing="21" translatesAutoresizingMaskIntoConstraints="NO" id="DL4-0a-WxC">
18 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="center" spacing="21" translatesAutoresizingMaskIntoConstraints="NO" id="DL4-0a-WxC">
@@ -33,7 +33,7 @@
33 </subviews>
33 </subviews>
34 </stackView>
34 </stackView>
35 <stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="0H2-jJ-gOj">
35 <stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="0H2-jJ-gOj">
36− <rect key="frame" x="20" y="152.5" width="374" height="45"/>
36+ <rect key="frame" x="20" y="132.5" width="374" height="45"/>
37 <subviews>
37 <subviews>
38 <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Tick" translatesAutoresizingMaskIntoConstraints="NO" id="lcW-xm-Gb7">
38 <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Tick" translatesAutoresizingMaskIntoConstraints="NO" id="lcW-xm-Gb7">
39 <rect key="frame" x="0.0" y="0.0" width="230" height="45"/>
39 <rect key="frame" x="0.0" y="0.0" width="230" height="45"/>
@@ -50,7 +50,7 @@
50 </subviews>
50 </subviews>
51 </stackView>
51 </stackView>
52 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ByV-f1-mVO">
52 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ByV-f1-mVO">
53− <rect key="frame" x="0.0" y="247.5" width="414" height="106"/>
53+ <rect key="frame" x="0.0" y="207.5" width="414" height="106"/>
54 <color key="backgroundColor" systemColor="systemBlueColor" red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
54 <color key="backgroundColor" systemColor="systemBlueColor" red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
55 <constraints>
55 <constraints>
56 <constraint firstAttribute="height" constant="106" id="UWZ-LN-h4r"/>
56 <constraint firstAttribute="height" constant="106" id="UWZ-LN-h4r"/>
@@ -60,10 +60,10 @@
60 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
60 <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
61 <constraints>
61 <constraints>
62 <constraint firstItem="ByV-f1-mVO" firstAttribute="trailing" secondItem="vUN-kp-3ea" secondAttribute="trailing" id="1g0-ab-erl"/>
62 <constraint firstItem="ByV-f1-mVO" firstAttribute="trailing" secondItem="vUN-kp-3ea" secondAttribute="trailing" id="1g0-ab-erl"/>
63− <constraint firstItem="ByV-f1-mVO" firstAttribute="top" secondItem="0H2-jJ-gOj" secondAttribute="bottom" constant="50" id="F84-ZL-MWp"/>
63+ <constraint firstItem="ByV-f1-mVO" firstAttribute="top" secondItem="0H2-jJ-gOj" secondAttribute="bottom" constant="30" id="F84-ZL-MWp"/>
64 <constraint firstItem="0H2-jJ-gOj" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="GR6-gI-ecm"/>
64 <constraint firstItem="0H2-jJ-gOj" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="20" id="GR6-gI-ecm"/>
65 <constraint firstItem="ByV-f1-mVO" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="KKj-7n-eQf"/>
65 <constraint firstItem="ByV-f1-mVO" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="KKj-7n-eQf"/>
66− <constraint firstItem="0H2-jJ-gOj" firstAttribute="top" secondItem="DL4-0a-WxC" secondAttribute="bottom" constant="50" id="VbN-sb-Pko"/>
66+ <constraint firstItem="0H2-jJ-gOj" firstAttribute="top" secondItem="DL4-0a-WxC" secondAttribute="bottom" constant="30" id="VbN-sb-Pko"/>
67 <constraint firstItem="DL4-0a-WxC" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="20" id="cm0-tz-ta4"/>
67 <constraint firstItem="DL4-0a-WxC" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="20" id="cm0-tz-ta4"/>
68 <constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="0H2-jJ-gOj" secondAttribute="trailing" constant="20" id="i3D-sP-KlI"/>
68 <constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="0H2-jJ-gOj" secondAttribute="trailing" constant="20" id="i3D-sP-KlI"/>
69 <constraint firstAttribute="trailing" secondItem="DL4-0a-WxC" secondAttribute="trailing" constant="20" id="kHp-8n-OTp"/>
69 <constraint firstAttribute="trailing" secondItem="DL4-0a-WxC" secondAttribute="trailing" constant="20" id="kHp-8n-OTp"/>
@@ -77,7 +77,7 @@
77 <outlet property="timeInterval" destination="ByV-f1-mVO" id="oB4-jH-8Ot"/>
77 <outlet property="timeInterval" destination="ByV-f1-mVO" id="oB4-jH-8Ot"/>
78 <outlet property="totalLabel" destination="xHF-9h-q9F" id="W94-2J-w0A"/>
78 <outlet property="totalLabel" destination="xHF-9h-q9F" id="W94-2J-w0A"/>
79 </connections>
79 </connections>
80− <point key="canvasLocation" x="137.59999999999999" y="391.304347826087"/>
80+ <point key="canvasLocation" x="137.59999999999999" y="365.21739130434787"/>
81 </view>
81 </view>
82 </objects>
82 </objects>
83 <resources>
83 <resources>
Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationCoordinator.swiftnew file+13
@@ -0,0 +1,13 @@
1+//
2+// ChangeReservationCoordinator.swift
3+// Hookah Tau
4+//
5+// Created by cstore on 02/12/2019.
6+// Copyright © 2019 Daria Rednikina. All rights reserved.
7+//
8+
9+import Foundation
10+
11+class ChangeReservationCoordinator: BaseCoordinator {
12+
13+}
Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationViewController.swiftnew file+19
@@ -0,0 +1,19 @@
1+//
2+// ChangeReservationViewController.swift
3+// Hookah Tau
4+//
5+// Created by cstore on 02/12/2019.
6+// Copyright © 2019 Daria Rednikina. All rights reserved.
7+//
8+
9+import UIKit
10+
11+class ChangeReservationViewController: BaseViewController {
12+
13+ override func viewDidLoad() {
14+ super.viewDidLoad()
15+
16+ // Do any additional setup after loading the view.
17+ }
18+
19+}
Hookah Tau/Extensions+Date.swift+2−12
@@ -84,20 +84,10 @@ extension Date {
84 }
84 }
85
85
86 func changeTime(periods: Int) -> Date? {
86 func changeTime(periods: Int) -> Date? {
87− let hours = (periods * 10 / 60 + 12) % 24
87+ let hours = (periods * 10 / 60) % 24
88 let min = (periods * 10) % 60
88 let min = (periods * 10) % 60
89
89
90− let day = Calendar.current.dateComponents([.year, .month, .day], from: self)
90+ return self.set(hours: hours, minutes: min, seconds: 0)
91−
92− var dateCalendars = DateComponents()
93− dateCalendars.hour = hours
94− dateCalendars.minute = min
95− dateCalendars.day = day.day!
96− dateCalendars.month = day.month!
97− dateCalendars.year = day.year!
98− dateCalendars.timeZone = TimeZone(abbreviation: "GMT")
99−
100− return Calendar.current.date(from: dateCalendars)
101 }
91 }
102
92
103 func getDay() -> Int {
93 func getDay() -> Int {
Hookah Tau/HFunc.swiftnew file+39
@@ -0,0 +1,39 @@
1+//
2+// HFunc.swift
3+// Hookah Tau
4+//
5+// Created by cstore on 02/12/2019.
6+// Copyright © 2019 Daria Rednikina. All rights reserved.
7+//
8+
9+import Foundation
10+
11+
12+class HFunc {
13+
14+ private init() {}
15+
16+ static let main = HFunc()
17+
18+ private func filterPeriod(_ today: Date) -> ((ReservationPeriod) -> Bool) {
19+ func datePredicate(_ start: Date, _ end: Date, _ current: Date) -> Bool {
20+ var calendar = Calendar.current
21+ calendar.timeZone = TimeZone(identifier: "GMT")!
22+
23+ let result = calendar.isDate(start, equalTo: current, toGranularity: .day)
24+ || calendar.isDate(end, equalTo: current, toGranularity: .day)
25+
26+ return result
27+ }
28+
29+ return { (period: ReservationPeriod) in datePredicate(period.startTime, period.endTime, today) }
30+ }
31+
32+
33+ /// Filtering function to get every periods which intersects with given date
34+ /// - Parameter periods: all periods of bookings (for a particular table)
35+ /// - Parameter today: date
36+ func filterPeriodsInDate(_ periods: [ReservationPeriod], _ today: Date) -> [ReservationPeriod] {
37+ return periods.filter(filterPeriod(today))
38+ }
39+}
Hookah Tau/Models/AllReservations.swift+8−17
@@ -9,8 +9,8 @@
9import Foundation
9import Foundation
10
10
11struct AllReservations: MyCodable {
11struct AllReservations: MyCodable {
12− var reservations: [Int: [Date: [ReservationPeriod]]]
12+ var reservations: [Int: [ReservationPeriod]]
13− var intervals: [Date: [Date: [Int]]]
13+ var intervals: [Date: [Int]]
14
14
15 enum CodingKeys: CodingKey {
15 enum CodingKeys: CodingKey {
16 case reservations
16 case reservations
@@ -20,29 +20,20 @@ struct AllReservations: MyCodable {
20 init(from decoder: Decoder) throws {
20 init(from decoder: Decoder) throws {
21 let container = try decoder.container(keyedBy: CodingKeys.self)
21 let container = try decoder.container(keyedBy: CodingKeys.self)
22
22
23− let intervalsWithStr = try container.decode([String: [String: [Int]]].self, forKey: .intervals)
23+ let intervalsWithStr = try container.decode([String: [Int]].self, forKey: .intervals)
24− let reservationWithStr = try container.decode([String: [String: [ReservationPeriod]]].self, forKey: .reservations)
24+ reservations = try container.decode([Int: [ReservationPeriod]].self, forKey: .reservations)
25
25
26− let resArray = reservationWithStr.map { (element) -> (Int, [Date: [ReservationPeriod]]) in
27− let key = Int(element.key) ?? 0
28− let valArr = element.value.compactMap { (DateFormatter.dmy.date(from: $0.0)!, $0.1) }
29− let val = Dictionary(uniqueKeysWithValues: valArr)
30− return (key, val)
31− }
32−
33− let intervArray = intervalsWithStr.map { (element) -> (Date, [Date: [Int]]) in
26+ let intervArray = intervalsWithStr.map { (element) -> (Date, [Int]) in
34− let key = DateFormatter.dmy.date(from: element.key)!
35− let arr = element.value.compactMap { (DateFormatter.iso8601Full.date(from: $0.0)!, $0.1) }
27+ let key = DateFormatter.iso8601Full.date(from: element.key)!
36− let val = Dictionary(uniqueKeysWithValues: arr)
37− return (key, val)
28+ return (key, element.value)
38 }
29 }
39
30
40 intervals = Dictionary(uniqueKeysWithValues: intervArray)
31 intervals = Dictionary(uniqueKeysWithValues: intervArray)
41− reservations = Dictionary(uniqueKeysWithValues: resArray)
42 }
32 }
43}
33}
44
34
45struct ReservationPeriod: MyCodable {
35struct ReservationPeriod: MyCodable {
46 var startTime: Date
36 var startTime: Date
47 var duration: Int
37 var duration: Int
38+ var endTime: Date
48}
39}
Hookah Tau/Models/Reservation.swift+4−4
@@ -13,8 +13,8 @@ struct Reservation: MyCodable {
13
13
14 var uuid: String
14 var uuid: String
15 var establishment: Int
15 var establishment: Int
16− var startTime: String
16+ var startTime: Date
17− var endTime: String
17+ var endTime: Date
18 var numberOfGuests: Int
18 var numberOfGuests: Int
19 var reservedTable: Int
19 var reservedTable: Int
20
20
@@ -24,8 +24,8 @@ struct Reservation: MyCodable {
24struct ReservationData: MyCodable {
24struct ReservationData: MyCodable {
25
25
26 var establishment: Int
26 var establishment: Int
27− var startTime: String
27+ var startTime: Date
28− var endTime: String
28+ var endTime: Date
29 var numberOfGuests: Int
29 var numberOfGuests: Int
30 var reservedTable: Int
30 var reservedTable: Int
31
31