Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import Alamofire
- import MapKit
- import CoreLocation
- enum DoctorRouter: AuthorizedRouter {
- case list(query: String?, country : Country?, state : State?, city : City?, batch : Batch)
- case map ( georegion : CLCircularRegion, query: String?)
- case details (doctor : Doctor)
- case rate (doctor : Doctor, rate: Double)
- case top (batch : Batch?)
- /// Locations
- case countryList
- case stateList(country : Country)
- case cityList(country: Country, state: State)
- }
- extension DoctorRouter {
- func asURLRequest() throws -> URLRequest {
- switch self {
- case .list(let query, let country, let state, let city, let batch):
- let params : [String : Any?] = ["key" : query,
- "type" : "doctor",
- "country_id" : country?.id,
- "state_id" : state?.id,
- "city_id" : city?.id,
- "count" : batch.limit,
- "offset" : batch.offset]
- return self.authorizedRequest(method: .get,
- path: "/commercial/search",
- params: params.nullKeyRemoval(),
- encoding: URLEncoding.default)
- case .map( let georegion, let query):
- let params : [String : Any?] = ["latitude" : georegion.center.latitude,
- "longitude" : georegion.center.longitude,
- "radius" : georegion.radius / 1000,
- "key" : query]
- return self.authorizedRequest(method: .get,
- path: "/commercial/doctor/map",
- params: params.nullKeyRemoval(),
- encoding: URLEncoding.default)
- case .details (let doctor) :
- return self.authorizedRequest(method: .get,
- path: "/commercial/doctor/\(doctor.id)")
- case .rate (let doctor, let rate) :
- let params : [String : Any?] = ["rate" : rate]
- return self.authorizedRequest(method: .post,
- path: "/commercial/doctor/like/\(doctor.id)",
- params: params.nullKeyRemoval(),
- encoding: URLEncoding.default)
- case .top (let batch):
- let b = batch ?? Batch(offset: 0, limit: 10)
- return self.authorizedRequest(method: .get,
- path: "/commercial/doctor/top",
- params: ["count" : b.limit,
- "offset" : b.offset])
- case .countryList:
- return self.authorizedRequest(method: .get,
- path: "/commercial/country/doctor")
- case .stateList(let country):
- return self.authorizedRequest(method: .get,
- path: "/commercial/doctor/state/\(country.id)")
- case .cityList(let country, let state):
- return self.authorizedRequest(method: .get,
- path: "/commercial/doctor/city/\(country.id)/\(state.id)")
- }
- }
- }
Add Comment
Please, Sign In to add comment