-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] #102 - 소셜로그인 회원가입 서버 구현 #111
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
27 changes: 27 additions & 0 deletions
27
Spark-iOS/Spark-iOS/Source/NetworkModels/Auth/Signup.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,27 @@ | ||
// | ||
// Signup.swift | ||
// Spark-iOS | ||
// | ||
// Created by kimhyungyu on 2022/01/18. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
// MARK: - DataClass | ||
struct Signup: Codable { | ||
let user: User | ||
let accesstoken: String | ||
} | ||
|
||
// MARK: - User | ||
struct User: Codable { | ||
let userID: Int | ||
let nickname: String | ||
let profileImg: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case userID = "userId" | ||
case nickname, profileImg | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthAPI.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,53 @@ | ||
// | ||
// AuthAPI.swift | ||
// Spark-iOS | ||
// | ||
// Created by kimhyungyu on 2022/01/18. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
public class AuthAPI { | ||
|
||
static let shared = AuthAPI() | ||
var userProvider = MoyaProvider<AuthService>(plugins: [MoyaLoggerPlugin()]) | ||
|
||
public init() { } | ||
|
||
func signup(socailID: String, profileImg: UIImage, nickname: String, fcmToken: String, completion: @escaping (NetworkResult<Any>) -> Void) { | ||
userProvider.request(.signup(socialId: socailID, profileImg: profileImg, nickname: nickname, fcmToken: fcmToken)) { result in | ||
switch result { | ||
case .success(let response): | ||
let statusCode = response.statusCode | ||
let data = response.data | ||
|
||
let networkResult = self.judgeSignupStatus(by: statusCode, data) | ||
completion(networkResult) | ||
|
||
case .failure(let err): | ||
print(err) | ||
} | ||
} | ||
} | ||
|
||
private func judgeSignupStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
|
||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GenericResponse<Signup>.self, from: data) | ||
else { | ||
return .pathErr | ||
} | ||
|
||
switch statusCode { | ||
case 200: | ||
return .success(decodedData.data ?? "None-Data") | ||
case 400..<500: | ||
return .requestErr(decodedData.message) | ||
case 500: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Spark-iOS/Spark-iOS/Source/NetworkServices/Auth/AuthService.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,59 @@ | ||
// | ||
// AuthService.swift | ||
// Spark-iOS | ||
// | ||
// Created by kimhyungyu on 2022/01/18. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
enum AuthService { | ||
case signup(socialId: String, profileImg: UIImage, nickname: String, fcmToken: String) | ||
} | ||
|
||
extension AuthService: TargetType { | ||
var baseURL: URL { | ||
return URL(string: Const.URL.baseURL)! | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .signup: | ||
return "/auth/signup" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
switch self { | ||
case .signup: | ||
return .post | ||
} | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case .signup(let socialID, let profileImg, let nickname, let fcmToken): | ||
var multiPartData: [Moya.MultipartFormData] = [] | ||
|
||
let socialIDData = socialID.data(using: .utf8) ?? Data() | ||
multiPartData.append(MultipartFormData(provider: .data(socialIDData), name: "socialId")) | ||
let nicknameData = nickname.data(using: .utf8) ?? Data() | ||
multiPartData.append(MultipartFormData(provider: .data(nicknameData), name: "nickname")) | ||
let fcmTokenData = fcmToken.data(using: .utf8) ?? Data() | ||
multiPartData.append(MultipartFormData(provider: .data(fcmTokenData), name: "fcmToken")) | ||
|
||
let profileImgData = MultipartFormData(provider: .data(profileImg.pngData() ?? Data()), name: "image", fileName: "image", mimeType: "image/png") | ||
multiPartData.append(profileImgData) | ||
|
||
return .uploadMultipart(multiPartData) | ||
} | ||
} | ||
|
||
var headers: [String: String]? { | ||
switch self { | ||
case .signup: | ||
return Const.Header.authrizationHeader | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
토큰도 스트링으로 보내면 되는거군뇨!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넹!