generated from 30th-THE-SOPT-iOS-Part/KimTaeHyeon
-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feature/#8 week04] 4차과제 #9
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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
25 changes: 25 additions & 0 deletions
25
Instagram-Clone/Instagram-Clone/Application/Extensions/UIViewController+.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,25 @@ | ||
// | ||
// UIViewController+.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIViewController { | ||
|
||
func makeOKAlert(title: String, | ||
message: String, | ||
okAction: ((UIAlertAction) -> Void)? = nil, | ||
completion: (() -> Void)? = nil) { | ||
let alertViewController = UIAlertController(title: title, | ||
message: message, | ||
preferredStyle: .alert) | ||
|
||
let okAction = UIAlertAction(title: "확인", style: .default, handler: okAction) | ||
alertViewController.addAction(okAction) | ||
|
||
self.present(alertViewController, animated: true, completion: completion) | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
Instagram-Clone/Instagram-Clone/Network/Base/GeneralResponse.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,23 @@ | ||
// | ||
// GeneralResponse.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GeneralResponse<T: Codable>: Codable { | ||
var status: Int | ||
var success: Bool? | ||
var message: String? | ||
var data: T? | ||
|
||
init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
message = (try? values.decode(String.self, forKey: .message)) ?? "" | ||
success = (try? values.decode(Bool.self, forKey: .success)) ?? nil | ||
data = (try? values.decode(T.self, forKey: .data)) ?? nil | ||
status = (try? values.decode(Int.self, forKey: .status)) ?? 0 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Instagram-Clone/Instagram-Clone/Network/Base/GeneralService.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,30 @@ | ||
// | ||
// GeneralService.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GeneralService { | ||
|
||
static func judgeStatus<T: Codable>(by statusCode: Int, _ data: Data, _ type: T.Type) -> NetworkResult<Any> { | ||
let decoder = JSONDecoder() | ||
guard let decodedData = try? decoder.decode(GeneralResponse<T>.self, from: data) | ||
else { return .pathErr } | ||
print(decodedData) | ||
switch statusCode { | ||
case 200: | ||
return .success(decodedData.data) | ||
case 201..<300: | ||
return .success(decodedData.status) | ||
case 400..<500: | ||
return .requestErr(decodedData.status) | ||
case 500: | ||
return .serverErr | ||
default: | ||
return .networkFail | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Instagram-Clone/Instagram-Clone/Network/Base/NetworkConstants.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,13 @@ | ||
// | ||
// NetworkConstant.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
struct NetworkConstants { | ||
|
||
static let header = ["Content-Type": "application/json"] | ||
} |
16 changes: 16 additions & 0 deletions
16
Instagram-Clone/Instagram-Clone/Network/Base/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,16 @@ | ||
// | ||
// NetworkResult.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
enum NetworkResult<T> { | ||
case success(T) | ||
case requestErr(T) | ||
case pathErr | ||
case serverErr | ||
case networkFail | ||
} |
16 changes: 16 additions & 0 deletions
16
Instagram-Clone/Instagram-Clone/Network/Base/URLConstants.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,16 @@ | ||
// | ||
// URLConstants.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
struct URLConstants { | ||
|
||
static let baseURL = "http://13.124.62.236" | ||
|
||
static let authSignup = "/auth/signup" | ||
static let authSignin = "/auth/signin" | ||
} |
12 changes: 12 additions & 0 deletions
12
Instagram-Clone/Instagram-Clone/Network/NetworkModel/AuthRequest.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,12 @@ | ||
// | ||
// SigninRequest.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AuthRequest: Codable { | ||
let name, email, password: String | ||
} |
16 changes: 16 additions & 0 deletions
16
Instagram-Clone/Instagram-Clone/Network/NetworkModel/AuthResponse.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,16 @@ | ||
// | ||
// SigninResponse.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
struct SigninResponse: Codable { | ||
let name, email: String | ||
} | ||
|
||
struct SignupResponse: Codable { | ||
let id: Int | ||
} |
71 changes: 71 additions & 0 deletions
71
Instagram-Clone/Instagram-Clone/Network/Router/AuthRouter.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,71 @@ | ||
// | ||
// AuthRouter.swift | ||
// Instagram-Clone | ||
// | ||
// Created by 김혜수 on 2022/05/15. | ||
// | ||
|
||
import Foundation | ||
|
||
import Alamofire | ||
|
||
enum UserRouter: URLRequestConvertible { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 우왕 |
||
|
||
case authSignin(login: AuthRequest) | ||
case authSignup(join: AuthRequest) | ||
|
||
var baseURL: URL { | ||
return URL(string: URLConstants.baseURL)! | ||
} | ||
|
||
var method: HTTPMethod { | ||
switch self { | ||
case .authSignin, .authSignup: | ||
return .post | ||
} | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .authSignin: | ||
return URLConstants.authSignin | ||
case .authSignup: | ||
return URLConstants.authSignup | ||
} | ||
} | ||
|
||
var headers: [String: String] { | ||
switch self { | ||
case .authSignin, .authSignup: | ||
return NetworkConstants.header | ||
} | ||
} | ||
|
||
var parameters: [String: String] { | ||
switch self { | ||
case .authSignin(let signin): | ||
return ["name": signin.name, | ||
"email": signin.email, | ||
"password": signin.password] | ||
case .authSignup(let signup): | ||
return ["email": signup.email, | ||
"name": signup.name, | ||
"password": signup.password] | ||
} | ||
} | ||
|
||
func asURLRequest() throws -> URLRequest { | ||
let url = baseURL.appendingPathComponent(path) | ||
|
||
var request = URLRequest(url: url) | ||
request.method = method | ||
request.headers = HTTPHeaders(headers) | ||
|
||
switch self { | ||
case .authSignin, .authSignup: | ||
request = try JSONParameterEncoder().encode(parameters, into: request) | ||
} | ||
|
||
return request | ||
} | ||
} |
Oops, something went wrong.
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.
와웅 대박 멋있어.