MindMapAPI.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // MindMapAPI.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/12/16.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import Moya
  9. enum MindMapAPI {
  10. case myFolderTree
  11. case createFolder(MindFolder)
  12. case listNextWithFilter(String, MindMapFilter)
  13. case viewMindWithId(String)
  14. case saveMindMap(MindMapItem)
  15. }
  16. extension MindMapAPI: OOAPIContextCapable {
  17. var apiContextKey: String {
  18. return "x_mind_assemble_control"
  19. }
  20. }
  21. // 是否需要xtoken
  22. extension MindMapAPI: OOAccessTokenAuthorizable {
  23. var shouldAuthorize: Bool {
  24. return true
  25. }
  26. }
  27. extension MindMapAPI: TargetType {
  28. var baseURL: URL {
  29. let model = O2AuthSDK.shared.o2APIServer(context: .x_mind_assemble_control)
  30. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 80)\(model?.context ?? "")"
  31. if let trueUrl = O2AuthSDK.shared.bindUnitTransferUrl2Mapping(url: baseURLString) {
  32. return URL(string: trueUrl)!
  33. }
  34. return URL(string: baseURLString)!
  35. }
  36. var path: String {
  37. switch self {
  38. case .myFolderTree:
  39. return "/jaxrs/folder/tree/my"
  40. case .listNextWithFilter(let id, _):
  41. return "/jaxrs/mind/filter/list/\(id)/next/\(O2.defaultPageSize)"
  42. case .viewMindWithId(let id):
  43. return "/jaxrs/mind/view/\(id)"
  44. case .saveMindMap(_):
  45. return "/jaxrs/mind/save"
  46. case .createFolder(_):
  47. return "/jaxrs/folder/save"
  48. }
  49. }
  50. var method: Moya.Method {
  51. switch self {
  52. case .myFolderTree, .viewMindWithId(_):
  53. return .get
  54. case .listNextWithFilter(_, _):
  55. return .put
  56. case .saveMindMap(_), .createFolder(_):
  57. return .post
  58. }
  59. }
  60. var sampleData: Data {
  61. return "".data(using: String.Encoding.utf8)!
  62. }
  63. var task: Task {
  64. switch self {
  65. case .myFolderTree, .viewMindWithId(_):
  66. return .requestPlain
  67. case .listNextWithFilter(_, let filter):
  68. return .requestParameters(parameters: filter.toJSON() ?? [:], encoding: JSONEncoding.default)
  69. case .saveMindMap(let data):
  70. return .requestParameters(parameters: data.toJSON() ?? [:], encoding: JSONEncoding.default)
  71. case .createFolder(let data):
  72. return .requestParameters(parameters: data.toJSON() ?? [:], encoding: JSONEncoding.default)
  73. }
  74. }
  75. var headers: [String : String]? {
  76. return nil
  77. }
  78. }