Skip to content

Commit

Permalink
update #144: AuthAPI: task 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
minsangKang committed Apr 30, 2024
1 parent 234bec5 commit 0d80edf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Project_Timer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
8761BDC82BCFE64000E9281A /* RxMoya in Frameworks */ = {isa = PBXBuildFile; productRef = 8761BDC72BCFE64000E9281A /* RxMoya */; };
8761BDCA2BCFEA7A00E9281A /* AuthAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8761BDC92BCFEA7A00E9281A /* AuthAPI.swift */; };
8761BDCC2BCFEC8500E9281A /* DailysAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8761BDCB2BCFEC8500E9281A /* DailysAPI.swift */; };
8761BDCE2BCFEFD500E9281A /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8761BDCD2BCFEFD500E9281A /* API.swift */; };
8765234628C76B6D00487BFB /* WeekSmallTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8765234528C76B6D00487BFB /* WeekSmallTime.swift */; };
8765234828C76FFE00487BFB /* WeekSmallVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8765234728C76FFE00487BFB /* WeekSmallVM.swift */; };
8765234A28C7709700487BFB /* WeekSmallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8765234928C7709700487BFB /* WeekSmallView.swift */; };
Expand Down Expand Up @@ -627,6 +628,7 @@
8761BDBF2BCFE52E00E9281A /* FirebaseAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirebaseAPI.swift; sourceTree = "<group>"; };
8761BDC92BCFEA7A00E9281A /* AuthAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthAPI.swift; sourceTree = "<group>"; };
8761BDCB2BCFEC8500E9281A /* DailysAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailysAPI.swift; sourceTree = "<group>"; };
8761BDCD2BCFEFD500E9281A /* API.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = "<group>"; };
8765234528C76B6D00487BFB /* WeekSmallTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekSmallTime.swift; sourceTree = "<group>"; };
8765234728C76FFE00487BFB /* WeekSmallVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekSmallVM.swift; sourceTree = "<group>"; };
8765234928C7709700487BFB /* WeekSmallView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekSmallView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1169,6 +1171,7 @@
8761BDBF2BCFE52E00E9281A /* FirebaseAPI.swift */,
8761BDC92BCFEA7A00E9281A /* AuthAPI.swift */,
8761BDCB2BCFEC8500E9281A /* DailysAPI.swift */,
8761BDCD2BCFEFD500E9281A /* API.swift */,
);
path = API;
sourceTree = "<group>";
Expand Down Expand Up @@ -2392,6 +2395,7 @@
87A4704826493D4D007B89D6 /* RecordTimes.swift in Sources */,
87A8CD252AF0C37200D4C1D7 /* TTSignupSecureFieldView.swift in Sources */,
872C0EE3284AF26A00E8E3F2 /* SettingUpdateHistoryVM.swift in Sources */,
8761BDCE2BCFEFD500E9281A /* API.swift in Sources */,
87EFD6832AC12C3800C422B1 /* SigninSignupEnvironment.swift in Sources */,
93A892B124C14D4700F89180 /* CircularProgressView.swift in Sources */,
8791C1F427DCD120000D6BA9 /* UserDefaultsManager.swift in Sources */,
Expand Down
22 changes: 22 additions & 0 deletions Project_Timer/Data/API/API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// API.swift
// Project_Timer
//
// Created by Kang Minsang on 2024/04/17.
// Copyright © 2024 FDEE. All rights reserved.
//

import Foundation
import Moya

extension TargetType {
func parameters(from encodable: Encodable) -> [String: Any] {
let encoder = JSONEncoder()
guard let data = try? encoder.encode(encodable),
let dictionary = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any] else {
return [:]
}

return dictionary
}
}
31 changes: 24 additions & 7 deletions Project_Timer/Data/API/AuthAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Foundation
import Moya

enum AuthAPI {
case postSignup
case postSignin
case getCheckUsername
case getCheckEmail
case postUpdatePassword
case postSignup(TestUserSignupInfo)
case postSignin(TestUserSigninInfo)
case getCheckUsername(String)
case getCheckEmail(String, String)
case postUpdatePassword(ResetPasswordRequest)
}

extension AuthAPI: TargetType {
Expand Down Expand Up @@ -45,10 +45,27 @@ extension AuthAPI: TargetType {
}

var task: Moya.Task {
return .requestPlain
switch self {
case .postSignup(let testUserSignupInfo):
return .requestJSONEncodable(testUserSignupInfo)
case .postSignin(let testUserSignupInfo):
return .requestJSONEncodable(testUserSignupInfo)
case .getCheckUsername(let username):
return .requestParameters(parameters: [
"username" : username
], encoding: URLEncoding.queryString)
case .getCheckEmail(let username, let email):
return .requestParameters(parameters: [
"username": username,
"email": email
], encoding: URLEncoding.queryString)
case .postUpdatePassword(let resetPasswordRequest):
return .requestJSONEncodable(resetPasswordRequest)
}
}

var headers: [String : String]? {
var headers: [String: String]? {
return nil
}
}

0 comments on commit 0d80edf

Please sign in to comment.