Skip to content

Commit

Permalink
[Feat] 로그인 서버 연결 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcsoyeon committed May 13, 2022
1 parent 2cabb43 commit 28b42d9
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 21 deletions.
24 changes: 12 additions & 12 deletions Instagram/Instagram.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
5CE6EFA4AF3313DD3C034709 /* Pods_Instagram.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DFC3BF8E1AE7CC1FAF92389 /* Pods_Instagram.framework */; };
9201FE52282E322A00443946 /* SignInService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9201FE51282E322A00443946 /* SignInService.swift */; };
9201FE54282E327C00443946 /* AuthRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9201FE53282E327C00443946 /* AuthRequest.swift */; };
9201FE56282E33E800443946 /* SignInAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9201FE55282E33E800443946 /* SignInAPI.swift */; };
920995A8280DD79F008C3491 /* TabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920995A7280DD79F008C3491 /* TabBarController.swift */; };
920995AB280DD965008C3491 /* SearchMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920995AA280DD965008C3491 /* SearchMainViewController.swift */; };
920995AF280DD9AD008C3491 /* ShopMainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 920995AE280DD9AD008C3491 /* ShopMainViewController.swift */; };
Expand All @@ -24,9 +27,6 @@
921E575C27FAD1DF00CDC913 /* IDSFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E575B27FAD1DF00CDC913 /* IDSFont.swift */; };
921E575E27FAD25300CDC913 /* IDSTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E575D27FAD25300CDC913 /* IDSTextField.swift */; };
921E576027FAD3AA00CDC913 /* IDSButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E575F27FAD3AA00CDC913 /* IDSButton.swift */; };
921E576827FADA4C00CDC913 /* TempAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E576727FADA4C00CDC913 /* TempAPI.swift */; };
921E576A27FADA5700CDC913 /* TempDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E576927FADA5700CDC913 /* TempDataModel.swift */; };
921E576C27FADA5F00CDC913 /* TempService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E576B27FADA5F00CDC913 /* TempService.swift */; };
921E576E27FADA7800CDC913 /* BaseResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E576D27FADA7800CDC913 /* BaseResponse.swift */; };
921E577027FADA8900CDC913 /* GeneralAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E576F27FADA8900CDC913 /* GeneralAPI.swift */; };
921E577227FADA9800CDC913 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 921E577127FADA9800CDC913 /* NetworkResult.swift */; };
Expand Down Expand Up @@ -61,6 +61,9 @@
/* Begin PBXFileReference section */
4DFC3BF8E1AE7CC1FAF92389 /* Pods_Instagram.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Instagram.framework; sourceTree = BUILT_PRODUCTS_DIR; };
90819665880AA30CF7419138 /* Pods-Instagram.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Instagram.debug.xcconfig"; path = "Target Support Files/Pods-Instagram/Pods-Instagram.debug.xcconfig"; sourceTree = "<group>"; };
9201FE51282E322A00443946 /* SignInService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInService.swift; sourceTree = "<group>"; };
9201FE53282E327C00443946 /* AuthRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRequest.swift; sourceTree = "<group>"; };
9201FE55282E33E800443946 /* SignInAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignInAPI.swift; sourceTree = "<group>"; };
920995A7280DD79F008C3491 /* TabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarController.swift; sourceTree = "<group>"; };
920995AA280DD965008C3491 /* SearchMainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchMainViewController.swift; sourceTree = "<group>"; };
920995AE280DD9AD008C3491 /* ShopMainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopMainViewController.swift; sourceTree = "<group>"; };
Expand All @@ -79,9 +82,6 @@
921E575B27FAD1DF00CDC913 /* IDSFont.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IDSFont.swift; sourceTree = "<group>"; };
921E575D27FAD25300CDC913 /* IDSTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IDSTextField.swift; sourceTree = "<group>"; };
921E575F27FAD3AA00CDC913 /* IDSButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IDSButton.swift; sourceTree = "<group>"; };
921E576727FADA4C00CDC913 /* TempAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempAPI.swift; sourceTree = "<group>"; };
921E576927FADA5700CDC913 /* TempDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempDataModel.swift; sourceTree = "<group>"; };
921E576B27FADA5F00CDC913 /* TempService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempService.swift; sourceTree = "<group>"; };
921E576D27FADA7800CDC913 /* BaseResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseResponse.swift; sourceTree = "<group>"; };
921E576F27FADA8900CDC913 /* GeneralAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralAPI.swift; sourceTree = "<group>"; };
921E577127FADA9800CDC913 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -308,7 +308,6 @@
isa = PBXGroup;
children = (
92BF252A2829676A00DE0205 /* Auth */,
921E576727FADA4C00CDC913 /* TempAPI.swift */,
);
path = API;
sourceTree = "<group>";
Expand All @@ -317,7 +316,6 @@
isa = PBXGroup;
children = (
92BF252F2829685000DE0205 /* Auth */,
921E576927FADA5700CDC913 /* TempDataModel.swift */,
);
path = DataModel;
sourceTree = "<group>";
Expand All @@ -326,7 +324,6 @@
isa = PBXGroup;
children = (
92BF25292829675400DE0205 /* Auth */,
921E576B27FADA5F00CDC913 /* TempService.swift */,
);
path = Service;
sourceTree = "<group>";
Expand Down Expand Up @@ -450,6 +447,7 @@
isa = PBXGroup;
children = (
92BF252D2829678F00DE0205 /* SignUpService.swift */,
9201FE51282E322A00443946 /* SignInService.swift */,
);
path = Auth;
sourceTree = "<group>";
Expand All @@ -458,6 +456,7 @@
isa = PBXGroup;
children = (
92BF252B2829678200DE0205 /* SignUpAPI.swift */,
9201FE55282E33E800443946 /* SignInAPI.swift */,
);
path = Auth;
sourceTree = "<group>";
Expand All @@ -469,6 +468,7 @@
92BF253428296A8800DE0205 /* SignUpRequest.swift */,
92BF25302829687300DE0205 /* SignInResponse.swift */,
92BF25322829689700DE0205 /* SignInRequest.swift */,
9201FE53282E327C00443946 /* AuthRequest.swift */,
);
path = Auth;
sourceTree = "<group>";
Expand Down Expand Up @@ -622,16 +622,16 @@
921E579627FAE33C00CDC913 /* CloseButton.swift in Sources */,
9244A9DF27FEDD0400D7C2EC /* SignInViewModel.swift in Sources */,
921E575527FAD0EE00CDC913 /* UIView+.swift in Sources */,
9201FE52282E322A00443946 /* SignInService.swift in Sources */,
921E579027FADF7B00CDC913 /* SignUpView.swift in Sources */,
92BF252E2829678F00DE0205 /* SignUpService.swift in Sources */,
9201FE56282E33E800443946 /* SignInAPI.swift in Sources */,
921E576E27FADA7800CDC913 /* BaseResponse.swift in Sources */,
92920C7527FAE95F00DCABC7 /* Assets+Generated.swift in Sources */,
921E579227FAE23B00CDC913 /* IDSNavigationBar.swift in Sources */,
921E576827FADA4C00CDC913 /* TempAPI.swift in Sources */,
92BF25332829689700DE0205 /* SignInRequest.swift in Sources */,
920995AF280DD9AD008C3491 /* ShopMainViewController.swift in Sources */,
92920C7927FAFE6800DCABC7 /* UserPasswordViewController.swift in Sources */,
921E576C27FADA5F00CDC913 /* TempService.swift in Sources */,
921E573F27FACB1A00CDC913 /* HomeMainViewController.swift in Sources */,
92BF252C2829678200DE0205 /* SignUpAPI.swift in Sources */,
921E575727FAD11800CDC913 /* UITextField+.swift in Sources */,
Expand All @@ -640,7 +640,6 @@
921E573B27FACB1A00CDC913 /* AppDelegate.swift in Sources */,
921E577B27FADC2E00CDC913 /* SignInViewController.swift in Sources */,
920995AB280DD965008C3491 /* SearchMainViewController.swift in Sources */,
921E576A27FADA5700CDC913 /* TempDataModel.swift in Sources */,
921E578E27FADD8E00CDC913 /* AuthCompleteViewController.swift in Sources */,
92BF253528296A8800DE0205 /* SignUpRequest.swift in Sources */,
92920C7727FAF71C00DCABC7 /* Reactive+.swift in Sources */,
Expand All @@ -651,6 +650,7 @@
921E579827FAE4C900CDC913 /* SignInView.swift in Sources */,
921E576027FAD3AA00CDC913 /* IDSButton.swift in Sources */,
921E575E27FAD25300CDC913 /* IDSTextField.swift in Sources */,
9201FE54282E327C00443946 /* AuthRequest.swift in Sources */,
92BF253728296A9300DE0205 /* SignUpResponse.swift in Sources */,
921E577027FADA8900CDC913 /* GeneralAPI.swift in Sources */,
921E579427FAE2BA00CDC913 /* BackButton.swift in Sources */,
Expand Down
50 changes: 50 additions & 0 deletions Instagram/Instagram/Network/API/Auth/SignInAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// SignInAPI.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

import Moya

final class SignInAPI {

// MARK: - Static Properties

static let shared: SignInAPI = SignInAPI()
private init() { }

// MARK: - Network Properties

var authProvider = MoyaProvider<SignInService>(plugins: [MoyaLoggerPlugin()])

public private(set) var signInResponse: BaseResponse<SignInResponse>?
public private(set) var signUpData: SignInResponse?

// MARK: - GET

func signUp(parameter: AuthRequest, completion: @escaping ((SignInResponse?, Error?) -> ())) {
authProvider.request(.signIn(parameter: parameter)) { [weak self] response in
switch response {
case .success(let result):
do {
self?.signInResponse = try result.map(BaseResponse<SignInResponse>.self)
guard let data = self?.signInResponse?.data else {
completion(nil, Error.self as? Error)
return
}
completion(data, nil)
} catch(let err) {
print(err.localizedDescription)
completion(nil, err)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil, err)
}
}
}
}

1 change: 0 additions & 1 deletion Instagram/Instagram/Network/API/Auth/SignUpAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation

import Moya
import Accelerate

final class SignUpAPI {

Expand Down
12 changes: 12 additions & 0 deletions Instagram/Instagram/Network/DataModel/Auth/AuthRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// AuthRequest.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

struct AuthRequest: Codable {
let name, email, password: String
}
59 changes: 59 additions & 0 deletions Instagram/Instagram/Network/Service/Auth/SignInService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// SignInService.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

import Moya

enum SignInService {
case signIn(parameter: AuthRequest)
}

extension SignInService: TargetType {
var baseURL: URL {
return URL(string: GeneralAPI.baseURL)!
}

var path: String {
switch self {
case .signIn:
return GeneralAPI.signInURL
}
}

var parameterEncoding: ParameterEncoding {
switch self {
case .signIn:
return JSONEncoding.default
}
}

var method: Moya.Method {
switch self {
case .signIn:
return .post
}
}

var task: Task {
switch self {
case .signIn(let parameter):
let parameter: [String: Any] = ["name": parameter.name,
"email": parameter.email,
"password": parameter.password]
return .requestParameters(parameters: parameter, encoding: JSONEncoding.default)
}
}

var headers: [String : String]? {
switch self {
case .signIn:
return ["Content-Type": "application/json"]
}
}
}

2 changes: 1 addition & 1 deletion Instagram/Instagram/Network/Utility/GeneralAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ struct GeneralAPI {

// MARK: - Feature URL

static let loginURL = "/auth/signin"
static let signInURL = "/auth/signin"
static let signUpURL = "/auth/signup"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import Then

final class SignInViewController: UIViewController {

// MARK: - Network

private let signInAPI = SignInAPI.shared

// MARK: - Properties

var disposeBag = DisposeBag()
Expand Down Expand Up @@ -73,13 +77,7 @@ final class SignInViewController: UIViewController {
rootView.tapSignInObservable
.withUnretained(self)
.subscribe(onNext: { (`self`, _ ) in
let vc = AuthCompleteViewController()
vc.userName = self.rootView.userName

let dvc = UINavigationController(rootViewController: vc)
dvc.modalPresentationStyle = .fullScreen

self.present(dvc, animated: true)
self.signIn()
})
.disposed(by: disposeBag)

Expand Down Expand Up @@ -126,4 +124,22 @@ final class SignInViewController: UIViewController {
completeViewController.modalPresentationStyle = .fullScreen
present(completeViewController, animated: true)
}

private func signIn() {
guard let password = rootView.pwTextField.text else { return }

self.signInAPI.signUp(parameter: AuthRequest(name: self.rootView.userName, email: self.rootView.userName, password: password)) { data, err in
guard let data = data else { return }

let alertVC = UIAlertController(title: "로그인 성공", message: nil, preferredStyle: .alert)
let okAction = UIAlertAction(title: "확인", style: .default) { action in
print("action")
let vc = TabBarController()
self.navigationController?.pushViewController(vc, animated: true)
}

alertVC.addAction(okAction)
self.present(alertVC, animated: true)
}
}
}

0 comments on commit 28b42d9

Please sign in to comment.