NotificationDetailPresenter.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // NotificationDetailPresenter.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 12/11/20.
  6. // Copyright © 2020 Anhar Solehudin. All rights reserved.
  7. //
  8. import Foundation
  9. import SwiftyJSON
  10. class NotificationDetailPresenter {
  11. private let siraniApiServices: SiraniApiServices
  12. weak private var view: NotificationDetailViewDelegate?
  13. init(siraniApiServices: SiraniApiServices) {
  14. self.siraniApiServices = siraniApiServices
  15. }
  16. func attachView(view: NotificationDetailViewDelegate?) {
  17. self.view = view
  18. }
  19. func detachView() {
  20. self.view = nil
  21. }
  22. func loadData(notifId: Int) {
  23. self.view?.showLoading()
  24. siraniApiServices.postToGetPushNotificationDetail(notifId: notifId).responseJSON { response in
  25. if response.error == nil {
  26. guard let data = response.data else { return }
  27. if let json = try? JSON(data: data) {
  28. if let data = json["data"].array {
  29. if data.count > 0 {
  30. let item = data[0]
  31. let notificationDetail = NotificationDetail(
  32. log_activity_id: item["log_activity_id"].intValue,
  33. apl_id: item["apl_id"].intValue,
  34. activity_date: item["activity_date"].stringValue,
  35. judul_notifikasi: item["judul_notifikasi"].stringValue,
  36. note: item["note"].string ?? "",
  37. plg_id: item["plg_id"].intValue,
  38. cust_name: item["cust_name"].stringValue,
  39. eqp_name: item["eqp_name"].stringValue,
  40. models: item["models"].stringValue,
  41. fullname: item["fullname"].stringValue,
  42. negara: item["negara"].stringValue
  43. )
  44. self.view?.setNotificationDetail(notificationDetail: notificationDetail)
  45. self.view?.hideLoading()
  46. } else {
  47. self.view?.hideLoading()
  48. }
  49. } else {
  50. self.view?.hideLoading()
  51. }
  52. } else {
  53. self.view?.hideLoading()
  54. }
  55. } else {
  56. self.view?.hideLoading()
  57. }
  58. }
  59. }
  60. func readNotif(notifId: Int) {
  61. siraniApiServices.postToGetPushNotificationRead(notifId: notifId).responseJSON { response in
  62. if response.error == nil {
  63. print("update notif status to read success")
  64. }
  65. }
  66. }
  67. }