| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //
- // NotificationDetailPresenter.swift
- // Sirani
- //
- // Created by Anhar Solehudin on 12/11/20.
- // Copyright © 2020 Anhar Solehudin. All rights reserved.
- //
- import Foundation
- import SwiftyJSON
- class NotificationDetailPresenter {
-
- private let siraniApiServices: SiraniApiServices
- weak private var view: NotificationDetailViewDelegate?
-
- init(siraniApiServices: SiraniApiServices) {
- self.siraniApiServices = siraniApiServices
- }
-
- func attachView(view: NotificationDetailViewDelegate?) {
- self.view = view
- }
-
- func detachView() {
- self.view = nil
- }
-
- func loadData(notifId: Int) {
- self.view?.showLoading()
-
- siraniApiServices.postToGetPushNotificationDetail(notifId: notifId).responseJSON { response in
- if response.error == nil {
- guard let data = response.data else { return }
- if let json = try? JSON(data: data) {
- if let data = json["data"].array {
- if data.count > 0 {
- let item = data[0]
- let notificationDetail = NotificationDetail(
- log_activity_id: item["log_activity_id"].intValue,
- apl_id: item["apl_id"].intValue,
- activity_date: item["activity_date"].stringValue,
- judul_notifikasi: item["judul_notifikasi"].stringValue,
- note: item["note"].string ?? "",
- plg_id: item["plg_id"].intValue,
- cust_name: item["cust_name"].stringValue,
- eqp_name: item["eqp_name"].stringValue,
- models: item["models"].stringValue,
- fullname: item["fullname"].stringValue,
- negara: item["negara"].stringValue
- )
- self.view?.setNotificationDetail(notificationDetail: notificationDetail)
- self.view?.hideLoading()
- } else {
- self.view?.hideLoading()
- }
- } else {
- self.view?.hideLoading()
- }
- } else {
- self.view?.hideLoading()
- }
- } else {
- self.view?.hideLoading()
- }
- }
- }
-
- func readNotif(notifId: Int) {
- siraniApiServices.postToGetPushNotificationRead(notifId: notifId).responseJSON { response in
- if response.error == nil {
- print("update notif status to read success")
- }
- }
- }
-
- }
|