Commit 925add2f authored by Grigor Aghabalyan's avatar Grigor Aghabalyan
Browse files

Feat: add forms list api

parent cf2d80e4
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
C5D2A725242B077100825031 /* FormsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5D2A724242B077100825031 /* FormsService.swift */; };
C5D2A727242B0A2300825031 /* FormsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5D2A726242B0A2300825031 /* FormsResponse.swift */; };
C5D6914E242AA091004268C3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5D6914D242AA091004268C3 /* AppDelegate.swift */; };
C5D69150242AA091004268C3 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5D6914F242AA091004268C3 /* SceneDelegate.swift */; };
C5D69155242AA091004268C3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C5D69153242AA091004268C3 /* Main.storyboard */; };
......@@ -53,6 +55,8 @@
57DE28D9ACEB4E61AAE67E58 /* Pods-App16.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App16.debug.xcconfig"; path = "Target Support Files/Pods-App16/Pods-App16.debug.xcconfig"; sourceTree = "<group>"; };
AC947C811CE3C096F8981C77 /* Pods_App16.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App16.framework; sourceTree = BUILT_PRODUCTS_DIR; };
AF4BB414838A78D615C7E656 /* Pods-App16.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App16.release.xcconfig"; path = "Target Support Files/Pods-App16/Pods-App16.release.xcconfig"; sourceTree = "<group>"; };
C5D2A724242B077100825031 /* FormsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormsService.swift; sourceTree = "<group>"; };
C5D2A726242B0A2300825031 /* FormsResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormsResponse.swift; sourceTree = "<group>"; };
C5D6914A242AA091004268C3 /* App16.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App16.app; sourceTree = BUILT_PRODUCTS_DIR; };
C5D6914D242AA091004268C3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C5D6914F242AA091004268C3 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
......@@ -205,6 +209,7 @@
children = (
C5D691BD242AE510004268C3 /* FormCreateService.swift */,
C5D691C1242AF07F004268C3 /* CurrentFormService.swift */,
C5D2A724242B077100825031 /* FormsService.swift */,
);
path = Services;
sourceTree = "<group>";
......@@ -334,6 +339,7 @@
C5D691BA242AE1D1004268C3 /* Form */ = {
isa = PBXGroup;
children = (
C5D2A726242B0A2300825031 /* FormsResponse.swift */,
C5D691BB242AE1F8004268C3 /* FormCreateRequestForm.swift */,
C5D691BF242AE5E2004268C3 /* FormCreateResponse.swift */,
C5D691C3242AF0B1004268C3 /* CurentFormRequestForm.swift */,
......@@ -485,6 +491,8 @@
C5D69173242AA539004268C3 /* BaseService.swift in Sources */,
C5D691A1242AAE12004268C3 /* MainViewController.swift in Sources */,
C5D69194242AAD00004268C3 /* SingleFormViewController.swift in Sources */,
C5D2A727242B0A2300825031 /* FormsResponse.swift in Sources */,
C5D2A725242B077100825031 /* FormsService.swift in Sources */,
C5D691BE242AE510004268C3 /* FormCreateService.swift in Sources */,
C5D691C2242AF07F004268C3 /* CurrentFormService.swift in Sources */,
C5D69170242AA4E9004268C3 /* Config.swift in Sources */,
......
......@@ -23,25 +23,27 @@ class FormCreateResponse: Mappable {
var visitingLongitude: Double?
var visitingReason: String?
var plannedReturnDatetime: String?
var createdAt: String?
required init?(map: Map) { }
init() { }
func mapping(map: Map) {
deviceToken <- map["device_token"]
firstName <- map["first_name"]
lastName <- map["last_name"]
middleName <- map["middle_name"]
outAddress <- map["out_address"]
outLatitude <- map["out_latitude"]
outLongitude <- map["out_longitude"]
outDatetime <- map["out_datetime"]
visitingAddressAndName <- map["visiting_address_and_name"]
visitingLatitude <- map["visiting_latitude"]
visitingLongitude <- map["visiting_longitude"]
visitingReason <- map["visiting_reason"]
plannedReturnDatetime <- map["planned_return_datetime"]
deviceToken <- map["device_token"]
firstName <- map["first_name"]
lastName <- map["last_name"]
middleName <- map["middle_name"]
outAddress <- map["out_address"]
outLatitude <- map["out_latitude"]
outLongitude <- map["out_longitude"]
outDatetime <- map["out_datetime"]
visitingAddressAndName <- map["visiting_address_and_name"]
visitingLatitude <- map["visiting_latitude"]
visitingLongitude <- map["visiting_longitude"]
visitingReason <- map["visiting_reason"]
plannedReturnDatetime <- map["planned_return_datetime"]
createdAt <- map["created_at"]
}
}
......
//
// FormsResponse.swift
// App16
//
// Created by Grigor Aghabalyan on 3/25/20.
// Copyright © 2020 X-TECH. All rights reserved.
//
import ObjectMapper
class FormsResponse: Mappable {
var data: [FormCreateResponse]?
required init?(map: Map) { }
init() { }
func mapping(map: Map) {
data <- map["data"]
}
}
enum FormsResponseResponseData<FormCreateResponse> {
case success(result: FormCreateResponse)
case base(response: BaseResponse)
case conflict
case isOffline
}
//
// FormsService.swift
// App16
//
// Created by Grigor Aghabalyan on 3/25/20.
// Copyright © 2020 X-TECH. All rights reserved.
//
import ObjectMapper
import AlamofireObjectMapper
import Alamofire
class FormsService {
static let shered = FormsService()
func retriveForms(data: CurentFormRequestForm, completion: @escaping ((FormsResponseResponseData<FormsResponse>) -> Void)) {
BaseService.shared.get(endpoint: "/applications", parameters: data.toJSON(), for: .unsecure)
.responseString { (response) in
print(response.result.value ?? "result value is nil")
if let responseHttp = response.response, let value = response.result.value {
if let baseResponse = BaseService.shared.checkBaseResponse(responseHttp, value) {
return completion(.base(response: baseResponse))
}
} else {
return completion(.isOffline)
}
switch response.response?.statusCode ?? 400 {
case 200...201:
if let value = response.result.value, let data = Mapper<FormsResponse>().map(JSONString: value) {
return completion(.success(result: data))
}
return completion(.base(response: .unexpectedError(error: ResponseUnexpectedError.mappingFailed)))
default:
return completion(.base(response: .badRequest))
}
}
}
}
......@@ -15,6 +15,7 @@ class FormListViewController: UIViewController {
// MARK: - Varibales
private let formListCell = "FormListCell"
var dataSource: [FormCreateResponse] = []
// MARK: - LifeCycle
override func viewDidLoad() {
......@@ -24,6 +25,10 @@ class FormListViewController: UIViewController {
tableView.dataSource = self
registerCelll()
if let deviceId = UIDevice.current.identifierForVendor?.uuidString {
retriveCurentForm(deviceToken: deviceId)
}
}
// MARK: - Register
......@@ -32,6 +37,31 @@ class FormListViewController: UIViewController {
let nib = UINib(nibName: formListCell, bundle: nil)
tableView.register(nib, forCellReuseIdentifier: formListCell)
}
private func retriveCurentForm(deviceToken: String) {
let form = CurentFormRequestForm(deviceToken: UIDevice.current.identifierForVendor?.uuidString)
FormsService.shered.retriveForms(data: form) { (responseData) in
switch responseData {
case .base(response: let baseResposne):
CheckBaseHelper.checkBaseResponse(baseResposne, viewController: self)
case .success(let response):
self.dataSource = response.data ?? []
DispatchQueue.main.async {
self.tableView.reloadData()
}
case .isOffline:
//self.activityIndicator.stopAnimating()
return
case .conflict:
//self.activityIndicator.stopAnimating()
return
}
}
}
}
extension FormListViewController: UITableViewDataSource {
......@@ -39,12 +69,15 @@ extension FormListViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
return dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: formListCell, for: indexPath) as? FormListCell
cell?.outDateLabel.text = dataSource[indexPath.row].outDatetime
cell?.planeDateLabel.text = dataSource[indexPath.row].outDatetime
cell?.createdDateLabel.text = dataSource[indexPath.row].createdAt
return cell ?? UITableViewCell()
}
}
......
......@@ -48,7 +48,9 @@ class MainViewController: UIViewController {
self.openWelcomeController()
}
CheckBaseHelper.checkBaseResponse(baseResposne, viewController: self)
case .success(_):
case .success(let response):
UserDefaultsHelper.set(alias: .firstName, value: response.firstName)
UserDefaultsHelper.set(alias: .lstName, value: response.lastName)
self.openQRController()
case .isOffline:
//self.activityIndicator.stopAnimating()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment