CoachAPI.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // CoachAPI.swift
  3. // JiaPeiManage
  4. //
  5. // Created by Ning.ge on 2023/6/13.
  6. //
  7. import Moya
  8. import SwiftyUserDefaults
  9. enum CoachAPI {
  10. //获取教练信息
  11. case coachInfo(id:String ,city:String)
  12. //获取教练二维码
  13. case coachQrInfo(id:String ,city:String)
  14. //获取教练的学员
  15. case coachInfoList(city:String,appCoachId:String ,coachId:String ,field:String ,pageNum:Int ,pageSize:Int ,schoolId:Int ,state:String )
  16. //通过id获取学员详细
  17. case studentInfoById(city:String,id:Int )
  18. }
  19. extension CoachAPI: TargetType {
  20. var baseURL: URL {
  21. switch self {
  22. case .coachInfo,.coachQrInfo,.coachInfoList,.studentInfoById:
  23. return URL(string: HttpRequest.api.path)!
  24. }
  25. }
  26. var path: String {
  27. switch self {
  28. case .coachInfo(_,_):
  29. return "/jsjp-admin/open-api/tms/coachInfo/getCoachInfo"
  30. case .coachQrInfo(_,_):
  31. return "/jsjp-admin/open-api/tms/coachInfo/getCoachQrInfo"
  32. case .coachInfoList(_,_,_,_,_,_,_,_):
  33. return "/jsjp-admin/open-api/tms/coachInfo/list"
  34. case .studentInfoById(_,_):
  35. return "/jsjp-admin/open-api/tms/coachInfo/getTmsStudentInfoById"
  36. }
  37. }
  38. var method: Moya.Method {
  39. switch self {
  40. case .coachInfo,.coachQrInfo,.coachInfoList,.studentInfoById:
  41. return .get
  42. default:
  43. return .get
  44. }
  45. }
  46. var sampleData: Data {
  47. return Data()
  48. }
  49. var task: Moya.Task {
  50. switch self {
  51. case .coachInfo(_,_),.coachQrInfo(_,_),.coachInfoList(_,_,_,_,_,_,_,_),.studentInfoById(_,_):
  52. if let parameters = parameters {
  53. return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
  54. }
  55. return .requestPlain
  56. }
  57. }
  58. var headers: [String: String]? {
  59. return ["Content-Type":"application/json"]
  60. }
  61. var parameters: [String : Any]? {
  62. switch self {
  63. case let .coachInfo(id,city):
  64. return ["city": city,
  65. "id": id,]
  66. case let .coachQrInfo(id,city):
  67. return ["city": city,
  68. "id": id,]
  69. case let .coachInfoList(city,appCoachId ,coachId ,field ,pageNum ,pageSize ,schoolId ,state):
  70. return ["city": city,
  71. "appCoachId": appCoachId,
  72. "coachId": coachId,
  73. "field": field,
  74. "pageNum": pageNum,
  75. "pageSize": pageSize,
  76. "schoolId": schoolId==0 ?"":"\(schoolId)",
  77. "state": state,]
  78. case let .studentInfoById(city,id):
  79. return ["city": city,
  80. "id": id,]
  81. default:
  82. return nil
  83. }
  84. }
  85. }