O2MeetingAPI.swift 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. //
  2. // O2MeetingAPI.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/1/16.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum O2MeetingAPI {
  12. //会议地点
  13. case buildByCreate
  14. case buildSearchByPingYin(String)
  15. case buildListByAll
  16. case buildListBySearchKey(String)
  17. case buildListByPinYinInitialSearch(String)
  18. case buildListByStartAndCompletedDate(String,String)
  19. case buildItemById(String)
  20. //会议房间
  21. case roomByCreate
  22. case roomSearchByPinYin(String)
  23. case roomListByAll
  24. case roomListBySearchKey(String)
  25. case roomListByPinYinInitialSearch(String)
  26. case roomItemById(String)
  27. //会议按年月列表
  28. case meetingListByYearMonth(String,String)
  29. case meetingListByYearMonthDay(String,String,String)
  30. case meetingListByAccept
  31. case meetingListByApplied
  32. case meetingListForDayCount(String)
  33. case meetingItemById(String)
  34. case meetingItemAcceptById(String)
  35. case meetingItemAddInvitedById(String)
  36. case meetingItemConfirmAllowById(String)
  37. case meetingItemConfirmDenyById(String)
  38. case meetingItemCompletedById(String)
  39. case meetingItemRejectById(String)
  40. case meetingItemByCreate(OOMeetingFormBean)
  41. case meetingCreate(OOMeetingInfo)
  42. case meetingItemUpdate(OOMeetingInfo)
  43. case meetingItemDelete(String)
  44. case meetingUploadFile(String, String, Data)
  45. case meetingAttachmentList(String)
  46. case meetingAttachmentDelete(String)
  47. case meetingAttachmentDownload(OOMeetingAttachmentList)
  48. }
  49. // MARK:- 上下文实现
  50. extension O2MeetingAPI:OOAPIContextCapable {
  51. var apiContextKey: String {
  52. return "x_meeting_assemble_control"
  53. }
  54. }
  55. // MARK: - 是否需要加入x-token访问头
  56. extension O2MeetingAPI:OOAccessTokenAuthorizable {
  57. public var shouldAuthorize: Bool {
  58. return true
  59. }
  60. }
  61. extension O2MeetingAPI:TargetType{
  62. var baseURL: URL {
  63. let model = O2AuthSDK.shared.o2APIServer(context: .x_meeting_assemble_control)
  64. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  65. return URL(string: baseURLString)!
  66. }
  67. var path: String {
  68. switch self {
  69. //会议地点
  70. case .buildByCreate:
  71. return "/jaxrs/building"
  72. case .buildSearchByPingYin(let pinyin):
  73. return "/jaxrs/building/list/like/pinyin/\(pinyin.urlEscaped)"
  74. case .buildListByAll:
  75. return "/jaxrs/building/list"
  76. case .buildListBySearchKey(let searchKey):
  77. return "/jaxrs/building/list/like/\(searchKey.urlEscaped)"
  78. case .buildListByPinYinInitialSearch(let pinyininitial):
  79. return "/jaxrs/building/list/pinyininitial/\(pinyininitial.urlEscaped)"
  80. case .buildListByStartAndCompletedDate(let start,let completed):
  81. return "/jaxrs/building/list/start/\(start)/completed/\(completed)"
  82. case .buildItemById(let id):
  83. return "/jaxrs/building/\(id)"
  84. //会议房间
  85. case .roomByCreate:
  86. return "/jaxrs/room"
  87. case .roomSearchByPinYin(let pinyin):
  88. return "/jaxrs/room/list/like/pinyin/\(pinyin)"
  89. case .roomListByAll:
  90. return "/jaxrs/room/list"
  91. case .roomListBySearchKey(let searchkey):
  92. return "/jaxrs/room/list/like/\(searchkey)"
  93. case .roomListByPinYinInitialSearch(let pinyininitial):
  94. return "/jaxrs/room/list/pinyininitial/\(pinyininitial)"
  95. case .roomItemById(let id):
  96. return "/jaxrs/room/\(id)"
  97. //会议按年月列表
  98. case .meetingListByYearMonth(let year,let month):
  99. return "/jaxrs/meeting/list/year/\(year)/month/\(month)"
  100. case .meetingListByYearMonthDay(let year,let month,let day):
  101. return "/jaxrs/meeting/list/year/\(year)/month/\(month)/day/\(day)"
  102. case .meetingListByAccept:
  103. return "/jaxrs/meeting/list/wait/accept"
  104. case .meetingListByApplied:
  105. return "/jaxrs/meeting/list/applied/wait"
  106. case .meetingListForDayCount(let day):
  107. return "/jaxrs/meeting/list/coming/day/\(day)"
  108. case .meetingItemById(let id):
  109. return "/jaxrs/meeting/\(id)"
  110. case .meetingItemAcceptById(let id):
  111. return "/jaxrs/meeting/\(id)/accept"
  112. case .meetingItemAddInvitedById(let id):
  113. return "/jaxrs/meeting/\(id)/add/invite"
  114. case .meetingItemConfirmAllowById(let id):
  115. return "/jaxrs/meeting/\(id)/confirm/allow"
  116. case .meetingItemConfirmDenyById(let id):
  117. return "/jaxrs/meeting/\(id)/confirm/deny"
  118. case .meetingItemCompletedById(let id):
  119. return "/jaxrs/meeting/\(id)/manual/completed"
  120. case .meetingItemRejectById(let id):
  121. return "/jaxrs/meeting/\(id)/reject"
  122. case .meetingItemByCreate(_), .meetingCreate(_):
  123. return "/jaxrs/meeting"
  124. case .meetingItemUpdate(let form):
  125. return "/jaxrs/meeting/\(form.id!)"
  126. case .meetingItemDelete(let id):
  127. return "/jaxrs/meeting/\(id)"
  128. case .meetingUploadFile(let meetingId, _, _):
  129. return "/jaxrs/attachment/meeting/\(meetingId)/upload/false"
  130. case .meetingAttachmentList(let meetingId):
  131. return "/jaxrs/attachment/list/meeting/\(meetingId)"
  132. case .meetingAttachmentDelete(let id):
  133. return "/jaxrs/attachment/\(id)"
  134. case .meetingAttachmentDownload(let atta):
  135. return "/jaxrs/attachment/\(atta.id!)/download/false"
  136. }
  137. }
  138. var method: Moya.Method {
  139. switch self {
  140. //会议地点
  141. case .buildByCreate:
  142. return .put
  143. case .buildSearchByPingYin(_):
  144. return .get
  145. case .buildListByAll:
  146. return .get
  147. case .buildListBySearchKey(_):
  148. return .get
  149. case .buildListByPinYinInitialSearch(_):
  150. return .get
  151. case .buildListByStartAndCompletedDate(_,_):
  152. return .get
  153. case .buildItemById(_):
  154. return .get
  155. //会议房间
  156. case .roomByCreate:
  157. return .put
  158. case .roomSearchByPinYin(_):
  159. return .get
  160. case .roomListByAll:
  161. return .get
  162. case .roomListBySearchKey(_):
  163. return .get
  164. case .roomListByPinYinInitialSearch(_):
  165. return .get
  166. case .roomItemById(_):
  167. return .get
  168. //会议按年月列表
  169. case .meetingListByYearMonth(_,_):
  170. return .get
  171. case .meetingListByYearMonthDay(_,_,_):
  172. return .get
  173. case .meetingListByAccept:
  174. return .get
  175. case .meetingListByApplied:
  176. return .get
  177. case .meetingListForDayCount(_):
  178. return .get
  179. case .meetingItemById(_):
  180. return .get
  181. case .meetingItemAcceptById(_):
  182. return .get
  183. case .meetingItemAddInvitedById(_):
  184. return .get
  185. case .meetingItemConfirmAllowById(_):
  186. return .get
  187. case .meetingItemConfirmDenyById(_):
  188. return .get
  189. case .meetingItemCompletedById(_):
  190. return .get
  191. case .meetingItemRejectById(_):
  192. return .get
  193. case .meetingItemByCreate(_), .meetingCreate(_):
  194. return .post
  195. case .meetingItemUpdate(_):
  196. return .put
  197. case .meetingItemDelete(_):
  198. return .delete
  199. case .meetingUploadFile(_, _, _):
  200. return .post
  201. case .meetingAttachmentList(_):
  202. return .get
  203. case .meetingAttachmentDelete(_):
  204. return .delete
  205. case .meetingAttachmentDownload(_):
  206. return .get
  207. }
  208. }
  209. var sampleData: Data {
  210. return "".data(using: String.Encoding.utf8)!
  211. }
  212. var task: Task {
  213. switch self {
  214. case .meetingItemByCreate(let mBean):
  215. return .requestParameters(parameters: mBean.toJSON()!, encoding: JSONEncoding.default)
  216. case .meetingCreate(let mBean):
  217. return .requestParameters(parameters: mBean.toJSON()!, encoding: JSONEncoding.default)
  218. case .meetingItemUpdate(let meeting):
  219. return .requestParameters(parameters: meeting.toJSON()!, encoding: JSONEncoding.default)
  220. case .meetingUploadFile(_, let fileName, let data):
  221. //字符串类型 文件名
  222. let strData = fileName.data(using: .utf8)
  223. let fileNameData = MultipartFormData(provider: .data(strData!), name: "fileName")
  224. //文件类型
  225. let fileData = MultipartFormData(provider: .data(data), name: "file", fileName: fileName)
  226. return .uploadMultipart([fileData, fileNameData])
  227. case .meetingAttachmentDownload(let atta):
  228. let myDest:DownloadDestination = { temporaryURL, response in
  229. let fileName = "\(atta.name ?? "untitle").\(atta.extension ?? "png")"
  230. let fileURL = O2.meetingFileLocalFolder().appendingPathComponent(fileName)
  231. return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
  232. }
  233. return .downloadDestination(myDest)
  234. default:
  235. return .requestPlain
  236. }
  237. }
  238. var headers: [String : String]? {
  239. return nil
  240. }
  241. }