Skip to content

Instantly share code, notes, and snippets.

@ricardopsantos
Last active January 14, 2023 14:02
Show Gist options
  • Save ricardopsantos/8e2b43606632888306f693a8dd508d2e to your computer and use it in GitHub Desktop.
Save ricardopsantos/8e2b43606632888306f693a8dd508d2e to your computer and use it in GitHub Desktop.
Article_13_G3.swift
typealias ResponseWithCacheMaybe = AnyPublisher<ResponseDto.EmployeeServiceAvailability, AppErrors>
/// No cache API call
public func requestWithoutCache(param: String) -> ResponseWithCacheMaybe {
let requestDto = FRPSampleAPI.RequestDto.Employee(someParam: param)
let apiRequest = sampleRepository2.requestSampleJSON(requestDto)
return apiRequest.mapError({$0.toAppError}).eraseToAnyPublisher()
}
/// - parameter cachePolicy: chacheNoLoad || noCacheDoLoad || cacheElseLoad || cacheAndLoad
public func requestWithCacheMaybe(param: String,
cachePolicy: CachePolicy) -> ResponseWithCacheMaybe {
let apiRequest = requestWithoutCache(param: param)
let serviceKey = #function
let serviceParams: [String] = [param]
let apiResponseType = ResponseDto.EmployeeServiceAvailability.self
return NetworkinNameSpace.NetworkingUtils.genericRequestWithCache(apiRequest,
apiResponseType,
cachePolicy,
serviceKey,
serviceParams)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment