123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- //
- // AccountService.swift
- // iOSFirst
- //
- // Created by 孙宇峰 on 2023/2/3.
- //
-
- import Foundation
- import Moya
-
- enum AccountService {
- case login(_ username: String, _ password: String, _ showLoading: Bool)
-
- }
-
- extension AccountService: TargetType {
-
- var baseURL: URL {
- return URL(string: Api.shoolurl)!
- }
-
- var path: String {
- switch self {
- case .login:
- return Api.Account.loginTeacher
- }
- }
-
- var method: Moya.Method {
- switch self {
- case .login:
- return .post
- default:
- return .post
- }
- }
-
- // var sampleData: Data {
- // return Data()
- // }
- //
- var task: Task {
- switch self {
- case .login(let username, let password, _):
-
- return .requestParameters(parameters: ["loginname": username,
- "loginpwd": password,
- "ultype":"p_phone_t",
- "versionnum":"3.6.0"],
- encoding: JSONEncoding.default)
- }
-
- }
-
- var headers: [String : String]? {
- switch self {
- case .login(_, _, let showLoading):
-
- return [
- "st":"false",
-
- "Content-type":"application/json"]
- default:
- return nil
- }
-
- }
-
- var sampleData: Data {
- switch self {
- case .login:
- return "should be filled properly".utf8Encoded
- }
- }
- }
-
- private extension String {
- var utf8Encoded:Data {
- return data(using: .utf8)!
- }
- }
|