Skip to content
Snippets Groups Projects
Commit 08b12692 authored by Robert Havrisciuc's avatar Robert Havrisciuc
Browse files

merge events api

parent 4e5ec42d
Branches merge_events
No related tags found
No related merge requests found
......@@ -203,6 +203,15 @@ class API {
}
}
@discardableResult
static func mergeEvent(by id: String, callback: @escaping (Result<Void>) -> Void) -> TTCancellable? {
let path = "events/\(id)/merge"
return request(.delete, path: path, encoding: .url).responseAPI { (reponse, result) in
callback(result)
}
}
// MARK: - Statistics
@discardableResult
......
......@@ -61,9 +61,9 @@ enum EventStatus: String, Codable {
enum EventConfig: String, Codable, CaseIterable {
case other, home, work
case car, passenger, carSharing, taxiUber, motorcycle, walk, eScooter
case bicycle, bicycleSharing, eBicycle, eBicycleSharing
case bus, regionalTrain, subway, train, tram, airplane, boat, coach, cableCar, ski
case car, passenger, carSharing = "carsharing", taxiUber = "taxi_uber", motorcycle = "motorbike_scooter", walk, eScooter = "kick_scooter"
case bicycle, bicycleSharing = "bikesharing", eBicycle = "ebicycle", eBicycleSharing = "ebikesharing"
case bus, regionalTrain = "regional_train", subway, train, tram, airplane, boat, coach, cableCar = "cable_car", aerialWay = "aerial_way", gondola, ski
case deleted, untracked
var title: String {
......@@ -112,7 +112,7 @@ enum EventConfig: String, Codable, CaseIterable {
return Texts.Event.eBicycle.text
case .eBicycleSharing:
return Texts.Event.eBicycleSharing.text
case .cableCar:
case .cableCar, .aerialWay, .gondola:
return Texts.Event.cableCar.text
case .regionalTrain:
return Texts.Event.regionalTrain.text
......@@ -189,7 +189,7 @@ enum EventConfig: String, Codable, CaseIterable {
return Constants.Colors.main.motorcycle.value
case .eScooter:
return Constants.Colors.main.eScooter.value
case .cableCar:
case .cableCar, .aerialWay, .gondola:
return Constants.Colors.main.cableCar.value
case .regionalTrain:
return Constants.Colors.main.regionalTrain.value
......@@ -246,7 +246,7 @@ enum EventConfig: String, Codable, CaseIterable {
return #imageLiteral(resourceName: "car_icon")
case .eScooter:
return #imageLiteral(resourceName: "car_icon")
case .cableCar:
case .cableCar, .aerialWay, .gondola:
return #imageLiteral(resourceName: "car_icon")
case .regionalTrain:
return #imageLiteral(resourceName: "train_icon")
......
......@@ -42,6 +42,7 @@ class EventActivity: Codable, Equatable {
class EventName: Codable {
var eventConfig: EventConfig
var isSelected: Bool
var emissions: Int
var isLast: Bool = false
var isFirst: Bool = false
......@@ -53,10 +54,11 @@ class EventName: Codable {
init(eventConfig: EventConfig, isSelected: Bool = false) {
self.eventConfig = eventConfig
self.isSelected = isSelected
self.emissions = 0
}
enum CodingKeys: String, CodingKey {
case isSelected = "selected", eventConfig = "name"
case isSelected = "selected", eventConfig = "name", emissions
}
}
......
This diff is collapsed.
......@@ -245,7 +245,17 @@ class EventDetailsViewController: __CollectionFeedController, GoogleMapsProtocol
let alert = UIAlertController(title: nil, message: Texts.Other.areYouSure.text, preferredStyle: .alert)
let action = UIAlertAction(title: Texts.Other.yes.text, style: .default) { action in
self.saveEventActivityIndicator.startAnimating()
API.mergeEvent(by: self.event.id, callback: { (result) in
self.saveEventActivityIndicator.stopAnimating()
switch result {
case .failure(let error):
self.checkAndShow(error: error)
case .success(_):
self.dismiss(animated: true, completion: nil)
self.completedEventsDelegate?.didDeleteEvent()
}
})
}
alert.addAction(action)
alert.addAction(UIAlertAction(title: Texts.Other.cancel.text, style: .cancel))
......
......@@ -44,7 +44,7 @@ class EventsViewController: __CollectionFeedController, DateSelectionDelegate, C
cellController.completedEventsDelegate = self
cellController.delegate = delegate
date = Date()
loadEvents(date: date.withFormat("YYYY-MM-dd"))
loadEventsWithFormmatedDate()
}
// MARK: - Data Loading
......@@ -145,22 +145,28 @@ class EventsViewController: __CollectionFeedController, DateSelectionDelegate, C
func didSelectDate(_ date: Date) {
self.date = date
loadEvents(date: date.withFormat("YYYY-MM-dd"))
loadEventsWithFormmatedDate()
delegate?.didSelectDay(date)
}
// MARK: - Helpers
func loadEventsWithFormmatedDate() {
loadEvents(date: date.withFormat("YYYY-MM-dd"))
}
// MARK: - EventDetailsViewController
func didSaveActivity() {
loadEvents(date: date.withFormat("YYYY-MM-dd"))
loadEventsWithFormmatedDate()
}
func didDeleteEvent() {
loadEvents(date: date.withFormat("YYYY-MM-dd"))
loadEventsWithFormmatedDate()
}
func didUpdateUntrackedEvent() {
loadEvents(date: date.withFormat("YYYY-MM-dd"))
loadEventsWithFormmatedDate()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment