fix: add actual changes

This commit is contained in:
Grigory Boyko 2022-08-01 21:11:39 +07:00
parent 179a368fe5
commit 343c40888d
6 changed files with 66 additions and 23 deletions

View File

@ -84,7 +84,7 @@ let package = Package(
.target(name: "TIAuth", dependencies: ["TIFoundationUtils"], path: "TIAuth/Sources"),
//MARK: - Skolkovo
.target(name: "TIEcommerce", dependencies: ["TIFoundationUtils"], path: "TIEcommerce/Sources"),
.target(name: "TIEcommerce", dependencies: ["TIFoundationUtils", "TISwiftUtils", "TINetworking"], path: "TIEcommerce/Sources"),
// MARK: - Tests

View File

@ -1,8 +1,54 @@
//
// File.swift
//
//
// Created by  Григорий Бойко on 01.08.2022.
//
import TIFoundationUtils
import TINetworking
import Foundation
open class CartRequestExecutor<S: Decodable, AE: Decodable, NE>: Cancellable {
public typealias ExecutionCompletion = (EndpointRecoverableRequestResult<S, AE, NE>) -> Void
public typealias ExecutionClosure = (ExecutionCompletion) -> Cancellable
public typealias SuccessCompletion = (S) -> Void
private let executionClosure: ExecutionClosure
public var successCompletion: SuccessCompletion
private var executingRequest: Cancellable?
public init(executionClosure: @escaping ExecutionClosure, successCompletion: @escaping SuccessCompletion) {
self.executionClosure = executionClosure
self.successCompletion = successCompletion
}
open func execute() {
executingRequest?.cancel()
_ = executionClosure { [weak self] in
switch $0 {
case let .success(result):
self?.handle(successResult: result)
case let .failure(errorCollection):
self?.handle(failure: errorCollection)
}
}
}
open func handle(successResult: S) {
successCompletion(successResult)
}
open func handle(failure: ErrorCollection<EndpointErrorResult<AE, NE>>) {
if shouldRetry(failure: failure) && 0 < 3 {
execute()
}
}
open func shouldRetry(failure: ErrorCollection<EndpointErrorResult<AE, NE>>) -> Bool {
if case .networkError = failure.failures.first {
return true
}
return false
}
open func cancel() {
executingRequest?.cancel()
}
}

View File

@ -1,8 +1,8 @@
import Foundation
struct BaseErrorResponseBody: Decodable, Equatable, Hashable {
protocol BaseErrorResponseBody: Decodable, Hashable {
///Код ошибки
let errorCode: Int
var errorCode: Int { get }
///Текст сообщения об ошибке
let errorMessage: String
var errorMessage: String { get }
}

View File

@ -1,14 +1,14 @@
import Foundation
protocol CartProduct: ProductPriceHolder, BonusesHolder {
protocol CartProduct {
///Идентификатор продукта
var id: String { get }
///Цена в определённой валюте
var price: CartProductPrice { get }
var price: Price { get }
///Сколько единиц есть доступно
var availableCount: Int? { get }
///Варианты товара (фасовка, цвет, размер, и т.п.)
var variants: [CartProduct?] { get }
var variants: [CartProduct] { get }
///Количество бонусов, которые будут начислены при покупке
var bonuses: Int? { get }
}

View File

@ -1,8 +1,5 @@
//
// File.swift
//
//
// Created by  Григорий Бойко on 01.08.2022.
//
import Foundation
protocol Promocode {
var discount: Price? { get }
}

View File

@ -1,13 +1,13 @@
Pod::Spec.new do |s|
s.name = 'TIEcommerce'
s.version = '1.25.0'
s.summary = 'Cart'
s.summary = 'Cart, products, promocodes, bonuses, receipt and other related actions'
s.homepage = 'https://github.com/TouchInstinct/LeadKit/tree/' + s.version.to_s + '/' + s.name
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'petropavel13' => 'ivan.smolin@touchin.ru' }
s.source = { :git => 'https://github.com/TouchInstinct/LeadKit.git', :tag => s.version.to_s }
s.ios.deployment_target = '13.0'
s.ios.deployment_target = '10.0'
s.swift_versions = ['5.3']
s.source_files = s.name + '/Sources/**/*'