-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat/#12] โจ moya network serivce add
# <ํ์ >: <์ ๋ชฉ> ##### ์ ๋ชฉ์ ์ต๋ 50 ๊ธ์๊น์ง๋ง ์ ๋ ฅ ############## -> | # ๋ณธ๋ฌธ์ ์์ ์์ฑ ######## ๋ณธ๋ฌธ์ ํ ์ค์ ์ต๋ 72 ๊ธ์๊น์ง๋ง ์ ๋ ฅ ########################### -> | # ๊ผฌ๋ฆฟ๋ง์ ์๋์ ์์ฑ: ex) #์ด์ ๋ฒํธ # --- COMMIT END --- # <ํ์ > ๋ฆฌ์คํธ # feat sparkles : ๊ธฐ๋ฅ(์๋ก์ด ๊ธฐ๋ฅ) # fix beetle : ๋ฒ๊ทธ(๋ฒ๊ทธ ์์ ) # refactor hammer : refacetor ๋ฆฌํฉํ ๋ง # style art : ์คํ์ผ( ์ฝ๋ ํ์ ๋ณ๊ฒฝ, ๋ก์ง ๋ณ๊ฒฝ ์์) # doc pencil : ๋ฌธ์(๋ฌธ์ ์ถ๊ฐ, ์์ , ์ญ์ ) # test white_check_mark : ํ ์คํธ ์ฝ๋ ์ถ๊ฐ # chore moyai : ๊ธฐํ ๋ณ๊ฒฝ์ฌํญ # ------------------ # ์ ๋ชฉ ์ฒซ ๊ธ์๋ฅผ ๋๋ฌธ์๋ก # ์ ๋ชฉ์ ๋ช ๋ น๋ฌธ์ผ๋ก # ์ ๋ชฉ ๋์ ๋ง์นจํ(.) ๊ธ์ง # ์ ๋ชฉ๊ณผ ๋ณธ๋ฌธ์ ํ ์ค ๋์ ๋ถ๋ฆฌํ๊ธฐ # ๋ณธ๋ฌธ์ "์ด๋ป๊ฒ" ๋ณด๋ค "๋ฌด์์", "์"๋ฅผ ์ค๋ช ํ๋ค. # ๋ณธ๋ฌธ์ ์ฌ๋ฌ์ค์ ๋ฉ์์ง๋ฅผ ์์ฑํ ๋ "-"๋ก ๊ตฌ๋ถ # ------------------
- Loading branch information
1 parent
5e646b8
commit 95ad258
Showing
19 changed files
with
432 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+173 KB
(200%)
...pt_29th_Assignment.xcworkspace/xcuserdata/kone.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
sopt_29th_Assignment/sopt_29th_Assignment/Global/Models/Account/AccountDataGettable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// AccountDataGettable.swift | ||
// sopt_29th_Assignment | ||
// | ||
// Created by ์ก์งํ on 2021/11/14. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AccountDataGettable: Codable { | ||
let status: Int | ||
let success: Bool | ||
let message: String | ||
let data: UserData? | ||
} | ||
|
||
// MARK: - DataClass | ||
struct UserData: Codable { | ||
let id: Int | ||
let name, email: String | ||
} |
151 changes: 151 additions & 0 deletions
151
sopt_29th_Assignment/sopt_29th_Assignment/Global/Network/BaseAPI.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// | ||
// BaseAPI.swift | ||
// sopt_29th_Assignment | ||
// | ||
// Created by ์ก์งํ on 2021/11/14. | ||
// | ||
|
||
import Moya | ||
import Alamofire | ||
|
||
|
||
enum BaseAPI{ | ||
case sampleAPI(sample : String) | ||
// ๊ณ์ ๊ด๋ จ | ||
case postSignIn(email : String, pw : String) | ||
case postSignUp(email : String, pw : String, name : String) | ||
} | ||
|
||
|
||
extension BaseAPI: TargetType { | ||
|
||
|
||
// MARK: - Base URL | ||
|
||
public var baseURL: URL { | ||
var base = Config.Network.baseURL | ||
switch self{ | ||
case .sampleAPI: | ||
base += "๋ํ ์ฃผ์" | ||
|
||
case .postSignIn,.postSignUp: | ||
base += "/user" | ||
} | ||
guard let url = URL(string: base) else { | ||
fatalError("baseURL could not be configured") | ||
} | ||
return url | ||
} | ||
|
||
// MARK: - Path | ||
var path: String { | ||
switch self{ | ||
case .sampleAPI: | ||
return "๋ค์๋ถ๋ ์ฃผ์" | ||
case .postSignIn: | ||
return "/signin" | ||
case .postSignUp: | ||
return "/signin" | ||
default : | ||
return "" | ||
} | ||
} | ||
|
||
|
||
// MARK: - Method | ||
var method: Moya.Method { | ||
switch self{ | ||
|
||
case .postSignIn,.postSignUp : | ||
return .post | ||
default : | ||
return .get | ||
|
||
} | ||
} | ||
|
||
// MARK: - Data | ||
var sampleData: Data { | ||
return Data() | ||
} | ||
|
||
// MARK: - Parameters | ||
private var bodyParameters: Parameters? { | ||
var params: Parameters = [:] | ||
switch self{ | ||
case .sampleAPI: | ||
params[""] = "" | ||
case .postSignIn(let email, let password) : | ||
params["email"] = email | ||
params["password"] = password | ||
case .postSignUp(let email, let password, let name): | ||
params["email"] = email | ||
params["name"] = name | ||
params["password"] = password | ||
default : | ||
break | ||
} | ||
return params | ||
} | ||
|
||
|
||
// MARK: - MultiParts | ||
|
||
private var multiparts: [Moya.MultipartFormData] { | ||
switch self{ | ||
case .sampleAPI(_): | ||
var multiparts : [Moya.MultipartFormData] = [] | ||
multiparts.append(.init(provider: .data("".data(using: .utf8) ?? Data()), name: "")) | ||
return multiparts | ||
default : return [] | ||
// images.forEach { | ||
// multiparts.append(.init(provider: .data($0), name: "images", fileName: "image.jpeg", mimeType: "image/jpeg")) | ||
// } | ||
} | ||
} | ||
|
||
|
||
private var parameterEncoding : ParameterEncoding{ | ||
switch self { | ||
case .sampleAPI: | ||
return URLEncoding.init(destination: .queryString, arrayEncoding: .noBrackets, boolEncoding: .literal) | ||
default : | ||
return JSONEncoding.default | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
var task: Task { | ||
switch self{ | ||
case .sampleAPI | ||
: | ||
return .uploadMultipart(multiparts) | ||
|
||
case .postSignIn,.postSignUp: | ||
return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding) | ||
|
||
default : | ||
return .requestPlain | ||
|
||
} | ||
} | ||
|
||
public var headers: [String: String]? { | ||
if let userToken = UserDefaults.standard.string(forKey: "userToken") { | ||
return ["Authorization": userToken, | ||
"Content-Type": "application/json"] | ||
}else{ | ||
return ["Content-Type": "application/json"] | ||
} | ||
} | ||
|
||
public var validationType: ValidationType { | ||
return .successCodes | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
sopt_29th_Assignment/sopt_29th_Assignment/Global/Network/Config.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Config.swift | ||
// sopt_29th_Assignment | ||
// | ||
// Created by ์ก์งํ on 2021/11/14. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Config | ||
{ | ||
enum Network { | ||
static var baseURL: String { | ||
return "https://asia-northeast3-we-sopt-29.cloudfunctions.net/api" | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.