-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from k-angama/feature/clients_contrats
Add clients contracts data
- Loading branch information
Showing
19 changed files
with
605 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// ContractsView.swift | ||
// LinkyAPIExample | ||
// | ||
// Created by Karim Angama on 29/01/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContractsView: View { | ||
|
||
@ObservedObject var viewModel = ContractsViewModel() | ||
|
||
var body: some View { | ||
|
||
VStack { | ||
Text("Contract") | ||
.font(.title) | ||
.padding(.bottom, 4.0) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
HStack { | ||
Text("Subscribed Power") | ||
.font(.body) | ||
Spacer() | ||
Text(viewModel.subscribedPower) | ||
.font(.caption) | ||
} | ||
HStack { | ||
Text("Distribution Tariff") | ||
.font(.body) | ||
Spacer() | ||
Text(viewModel.distributionTariff) | ||
.font(.caption) | ||
} | ||
HStack { | ||
Text("Off-Peak house") | ||
.font(.body) | ||
Spacer() | ||
Text(viewModel.offpeakHours) | ||
.font(.caption) | ||
} | ||
} | ||
.onAppear() { | ||
viewModel.getContracts() | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
ContractsView() | ||
} |
31 changes: 31 additions & 0 deletions
31
Example/LinkyAPIExample/Consumption/ContractsViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// ContractsViewModel.swift | ||
// LinkyAPIExample | ||
// | ||
// Created by Karim Angama on 29/01/2024. | ||
// | ||
|
||
import Foundation | ||
import LinkyAPI | ||
import Combine | ||
|
||
|
||
class ContractsViewModel: ObservableObject { | ||
|
||
@Published var subscribedPower = "-" | ||
@Published var distributionTariff = "-" | ||
@Published var offpeakHours = "-" | ||
|
||
func getContracts() { | ||
LinkyCustomer.shared.contracts { [weak self] consumption, error in | ||
if error == nil { | ||
DispatchQueue.main.async { | ||
let contracts = consumption?.customer.usagePoints.first?.contracts | ||
self?.subscribedPower = contracts?.subscribedPower ?? "-" | ||
self?.distributionTariff = contracts?.distributionTariff ?? "-" | ||
self?.offpeakHours = contracts?.offpeakHours ?? "-" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// LinkyCustomers.swift | ||
// LinkyAPI | ||
// | ||
// Created by Karim Angama on 28/01/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Retries the daily consumption | ||
/// | ||
/// - Parameter shared: The shared singleton session object. | ||
/// | ||
public struct LinkyCustomers { | ||
|
||
/// The shared singleton session object. | ||
public static var shared = LinkyCustomers() | ||
|
||
internal var linkyAPI: LinkyAPI? | ||
|
||
private init() {} | ||
|
||
/// Retries the user's contacts | ||
/// | ||
/// - Parameter completionHandler: The completion handler to call when the load request is complete. | ||
/// | ||
func contracts(completionHandler: @escaping (_ consumption: LinkyCustomerEntity?, _ error: Error?) -> Void) { | ||
linkyAPI?.customer(route: .customerContracts) { contracts, error in | ||
if let contracts = contracts { | ||
completionHandler(LinkyContractsMapper.rawToEntity(raw: contracts), nil) | ||
} else { | ||
completionHandler(nil, error) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// LinkyCustomers.swift | ||
// LinkyAPI | ||
// | ||
// Created by Karim Angama on 28/01/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Retries the daily consumption | ||
/// | ||
/// - Parameter shared: The shared singleton session object. | ||
/// | ||
public struct LinkyCustomer { | ||
|
||
/// The shared singleton session object. | ||
public static var shared = LinkyCustomer() | ||
|
||
internal var linkyAPI: LinkyAPI? | ||
|
||
private init() {} | ||
|
||
/// Retries the user's contacts | ||
/// | ||
/// - Parameter completionHandler: The completion handler to call when the load request is complete. | ||
/// | ||
public func contracts(completionHandler: @escaping (_ consumption: LinkyCustomerEntity?, _ error: Error?) -> Void) { | ||
linkyAPI?.customer(route: .customerContracts) { contracts, error in | ||
if let contracts = contracts { | ||
completionHandler(LinkyContractsMapper.rawToEntity(raw: contracts), nil) | ||
} else { | ||
completionHandler(nil, error) | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.