-
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.
- Loading branch information
1 parent
cddd177
commit c23df63
Showing
160 changed files
with
920 additions
and
86 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Uncomment the next line to define a global platform for your project | ||
# platform :ios, '9.0' | ||
|
||
target 'iOS_Week1_Exercise_Login' do | ||
# Comment the next line if you don't want to use dynamic frameworks | ||
use_frameworks! | ||
|
||
# Pods for iOS_Week1_Exercise_Login | ||
pod 'Alamofire', '~> 4.8.2' | ||
pod 'Kingfisher', '~> 5.0' | ||
end |
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,22 @@ | ||
PODS: | ||
- Alamofire (4.8.2) | ||
- Kingfisher (5.14.0): | ||
- Kingfisher/Core (= 5.14.0) | ||
- Kingfisher/Core (5.14.0) | ||
|
||
DEPENDENCIES: | ||
- Alamofire (~> 4.8.2) | ||
- Kingfisher (~> 5.0) | ||
|
||
SPEC REPOS: | ||
trunk: | ||
- Alamofire | ||
- Kingfisher | ||
|
||
SPEC CHECKSUMS: | ||
Alamofire: ae5c501addb7afdbb13687d7f2f722c78734c2d3 | ||
Kingfisher: 7b64389a43139c903ec434788344c288217c792d | ||
|
||
PODFILE CHECKSUM: b6ab108c6bf59e4a237a898ad00979def63c26b6 | ||
|
||
COCOAPODS: 1.9.1 |
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
10 changes: 10 additions & 0 deletions
10
iOS_Week1_Exercise_Login/iOS_Week1_Exercise_Login.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...Exercise_Login/iOS_Week1_Exercise_Login.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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
14 changes: 14 additions & 0 deletions
14
iOS_Week1_Exercise_Login/iOS_Week1_Exercise_Login/Resource/APIConstants.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,14 @@ | ||
// | ||
// APIConstants.swift | ||
// iOS_Week1_Exercise_Login | ||
// | ||
// Created by 양지영 on 2020/05/16. | ||
// Copyright © 2020 양지영. All rights reserved. | ||
// | ||
import Foundation | ||
|
||
struct APIConstants { | ||
static let baseURL = "http://13.209.144.115:3333" | ||
static let signinURL = APIConstants.baseURL + "/user/signin" | ||
static let signupURL = APIConstants.baseURL + "/user/signup" | ||
} |
49 changes: 49 additions & 0 deletions
49
iOS_Week1_Exercise_Login/iOS_Week1_Exercise_Login/Resource/LoginService.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,49 @@ | ||
// | ||
// LoginService.swift | ||
// iOS_Week1_Exercise_Login | ||
// | ||
// Created by 양지영 on 2020/05/16. | ||
// Copyright © 2020 양지영. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import Alamofire | ||
|
||
struct LoginService { | ||
static let shared = LoginService() // shared:전역으로 사용가능, static let어디서든 접근 가능 | ||
private func makeParameter(_ id: String, _ pwd: String) -> Parameters { | ||
return ["id": id, "password":pwd] | ||
} | ||
func login(id: String, pwd: String, completion: @escaping (NetworkResult<Any>) -> Void) { | ||
let header: HTTPHeaders = ["Content-Type": "application/json"] //httpheaders는 alanmofire 레퍼런스 | ||
// 요청에해당하는 객체 생성 | ||
let dataRequest = Alamofire.request(APIConstants.signinURL, method: .post, parameters: makeParameter(id, pwd), encoding: JSONEncoding.default, headers: header) | ||
//데이터 통신시작 | ||
dataRequest.responseData { dataResponse in | ||
switch dataResponse.result { | ||
case .success: | ||
// statuscode를 헤더에 넣을경우 분기처리 적게해서 더 좋음(?), 지금은 쪼개면서 2번 분기처리 | ||
guard let statusCode = dataResponse.response?.statusCode else { return } | ||
guard let value = dataResponse.result.value else { return } | ||
let networkResult = self.judge(by: statusCode, value) | ||
completion(networkResult) | ||
case .failure: completion(.networkFail) | ||
} | ||
} | ||
} | ||
private func judge(by statusCode: Int, _ data: Data) -> NetworkResult<Any> { | ||
switch statusCode { | ||
case 200: return isUser(by: data) //데이터를 넣어서 판단 시작 | ||
case 400: return .pathErr | ||
case 500: return .serverErr | ||
default: return .networkFail | ||
} | ||
} | ||
// 디코딩해줄 객체 | ||
private func isUser(by data: Data) -> NetworkResult<Any> { | ||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(SigininData.self, from: data) else { return .pathErr } | ||
guard let tokenData = decodedData.data else { return .requestErr(decodedData.message) } | ||
return .success(tokenData.jwt) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
iOS_Week1_Exercise_Login/iOS_Week1_Exercise_Login/Resource/NetworkResult.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,17 @@ | ||
// | ||
// NetworkResult.swift | ||
// iOS_Week1_Exercise_Login | ||
// | ||
// Created by 양지영 on 2020/05/16. | ||
// Copyright © 2020 양지영. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum NetworkResult<T> { | ||
case success(T) | ||
case requestErr(T) | ||
case pathErr | ||
case serverErr | ||
case networkFail | ||
} |
Oops, something went wrong.