generated from 30th-THE-SOPT-iOS-Part/KimTaeHyeon
-
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.
[Feature/#8 week04] 4차과제
- Loading branch information
Showing
72 changed files
with
17,153 additions
and
1,281 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
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 { | ||
|
||
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.