Skip to content
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 5 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions Instagram-Clone/Instagram-Clone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
15963F7D2800AFC2003C7A14 /* Storyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15963F7C2800AFC2003C7A14 /* Storyboard.swift */; };
15963F7F2800B05A003C7A14 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15963F7E2800B05A003C7A14 /* ViewController.swift */; };
15963F812800B0FB003C7A14 /* InstagramTitleLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15963F802800B0FB003C7A14 /* InstagramTitleLabel.swift */; };
15F0B9402830945C008A300E /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B93F2830945C008A300E /* NetworkResult.swift */; };
15F0B94228309474008A300E /* URLConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B94128309474008A300E /* URLConstants.swift */; };
15F0B944283094F2008A300E /* AuthRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B943283094F2008A300E /* AuthRouter.swift */; };
15F0B94A2830964E008A300E /* AuthRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B9492830964E008A300E /* AuthRequest.swift */; };
15F0B94C28309655008A300E /* AuthResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B94B28309655008A300E /* AuthResponse.swift */; };
15F0B94E2830996D008A300E /* GeneralResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B94D2830996D008A300E /* GeneralResponse.swift */; };
15F0B95028309BE5008A300E /* NetworkConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B94F28309BE5008A300E /* NetworkConstants.swift */; };
15F0B95228309C2C008A300E /* GeneralService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B95128309C2C008A300E /* GeneralService.swift */; };
15F0B95428309C90008A300E /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B95328309C90008A300E /* AuthService.swift */; };
15F0B9562830B6FF008A300E /* UIViewController+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B9552830B6FF008A300E /* UIViewController+.swift */; };
15F0B8922822455B008A300E /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B8912822455B008A300E /* HomeViewController.swift */; };
15F0B89628224A66008A300E /* StoryCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F0B89428224A66008A300E /* StoryCollectionViewCell.swift */; };
15F0B89728224A66008A300E /* StoryCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 15F0B89528224A66008A300E /* StoryCollectionViewCell.xib */; };
Expand Down Expand Up @@ -81,6 +91,16 @@
15963F7C2800AFC2003C7A14 /* Storyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storyboard.swift; sourceTree = "<group>"; };
15963F7E2800B05A003C7A14 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
15963F802800B0FB003C7A14 /* InstagramTitleLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstagramTitleLabel.swift; sourceTree = "<group>"; };
15F0B93F2830945C008A300E /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
15F0B94128309474008A300E /* URLConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLConstants.swift; sourceTree = "<group>"; };
15F0B943283094F2008A300E /* AuthRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRouter.swift; sourceTree = "<group>"; };
15F0B9492830964E008A300E /* AuthRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthRequest.swift; sourceTree = "<group>"; };
15F0B94B28309655008A300E /* AuthResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthResponse.swift; sourceTree = "<group>"; };
15F0B94D2830996D008A300E /* GeneralResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralResponse.swift; sourceTree = "<group>"; };
15F0B94F28309BE5008A300E /* NetworkConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConstants.swift; sourceTree = "<group>"; };
15F0B95128309C2C008A300E /* GeneralService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralService.swift; sourceTree = "<group>"; };
15F0B95328309C90008A300E /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = "<group>"; };
15F0B9552830B6FF008A300E /* UIViewController+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+.swift"; sourceTree = "<group>"; };
15F0B8912822455B008A300E /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
15F0B89428224A66008A300E /* StoryCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryCollectionViewCell.swift; sourceTree = "<group>"; };
15F0B89528224A66008A300E /* StoryCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StoryCollectionViewCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -153,6 +173,7 @@
isa = PBXGroup;
children = (
15858D942802A04200332653 /* UITextField+.swift */,
15F0B9552830B6FF008A300E /* UIViewController+.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand All @@ -179,6 +200,7 @@
15963F3427FF634A003C7A14 /* Instagram-Clone */ = {
isa = PBXGroup;
children = (
15F0B93C2830943E008A300E /* Network */,
15963F692800A27B003C7A14 /* Resource */,
15963F682800A267003C7A14 /* Application */,
15963F5428009F9F003C7A14 /* Presentation */,
Expand Down Expand Up @@ -318,6 +340,54 @@
path = Main;
sourceTree = "<group>";
};
15F0B93C2830943E008A300E /* Network */ = {
isa = PBXGroup;
children = (
15F0B94628309514008A300E /* Service */,
15F0B9452830950D008A300E /* NetworkModel */,
15F0B93E2830944A008A300E /* Router */,
15F0B93D28309444008A300E /* Base */,
);
path = Network;
sourceTree = "<group>";
};
15F0B93D28309444008A300E /* Base */ = {
isa = PBXGroup;
children = (
15F0B93F2830945C008A300E /* NetworkResult.swift */,
15F0B94F28309BE5008A300E /* NetworkConstants.swift */,
15F0B94128309474008A300E /* URLConstants.swift */,
15F0B94D2830996D008A300E /* GeneralResponse.swift */,
15F0B95128309C2C008A300E /* GeneralService.swift */,
);
path = Base;
sourceTree = "<group>";
};
15F0B93E2830944A008A300E /* Router */ = {
isa = PBXGroup;
children = (
15F0B943283094F2008A300E /* AuthRouter.swift */,
);
path = Router;
sourceTree = "<group>";
};
15F0B9452830950D008A300E /* NetworkModel */ = {
isa = PBXGroup;
children = (
15F0B9492830964E008A300E /* AuthRequest.swift */,
15F0B94B28309655008A300E /* AuthResponse.swift */,
);
path = NetworkModel;
sourceTree = "<group>";
};
15F0B94628309514008A300E /* Service */ = {
isa = PBXGroup;
children = (
15F0B95328309C90008A300E /* AuthService.swift */,
);
path = Service;
sourceTree = "<group>";
};
15F0B89328224A34008A300E /* CommonCells */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -509,28 +579,39 @@
files = (
15F0B89628224A66008A300E /* StoryCollectionViewCell.swift in Sources */,
15963F632800A0C9003C7A14 /* AuthCompleteViewController.swift in Sources */,
15F0B94228309474008A300E /* URLConstants.swift in Sources */,
15963F6E2800A65D003C7A14 /* InstagramTextField.swift in Sources */,
15F0B94A2830964E008A300E /* AuthRequest.swift in Sources */,
15F0B8A3282388B9008A300E /* FeedCollectionViewCell.swift in Sources */,
15963F6E2800A65D003C7A14 /* InstagramTextField.swift in Sources */,
15F0B8922822455B008A300E /* HomeViewController.swift in Sources */,
1521D083281280C700A9C29B /* MainTabBarController.swift in Sources */,
15963F582800A06F003C7A14 /* SigninViewController.swift in Sources */,
15F0B95228309C2C008A300E /* GeneralService.swift in Sources */,
15963F7F2800B05A003C7A14 /* ViewController.swift in Sources */,
15F0B89A28224D16008A300E /* HomeViewController+CollectionView.swift in Sources */,
15963F7D2800AFC2003C7A14 /* Storyboard.swift in Sources */,
15F0B95028309BE5008A300E /* NetworkConstants.swift in Sources */,
15F0B944283094F2008A300E /* AuthRouter.swift in Sources */,
15858D562800B7BD00332653 /* InstagramSubtitleLabel.swift in Sources */,
15F0B89E282382D0008A300E /* User.swift in Sources */,
15963F3627FF634A003C7A14 /* AppDelegate.swift in Sources */,
15963F7A2800AAF9003C7A14 /* BaseViewController.swift in Sources */,
15F0B9562830B6FF008A300E /* UIViewController+.swift in Sources */,
15963F3827FF634A003C7A14 /* SceneDelegate.swift in Sources */,
15F0B94E2830996D008A300E /* GeneralResponse.swift in Sources */,
15963F652800A0D7003C7A14 /* SignupNameViewController.swift in Sources */,
15963F812800B0FB003C7A14 /* InstagramTitleLabel.swift in Sources */,
15963F6C2800A2F6003C7A14 /* InstagramBlueButton.swift in Sources */,
15963F672800A0E2003C7A14 /* SignupPasswordViewController.swift in Sources */,
15963F772800A8F4003C7A14 /* Image.swift in Sources */,
15F0B95428309C90008A300E /* AuthService.swift in Sources */,
15858D972802B5CC00332653 /* AuthProtocol.swift in Sources */,
15F0B94C28309655008A300E /* AuthResponse.swift in Sources */,
15F0B8A0282382D5008A300E /* Feed.swift in Sources */,
15963F752800A8CD003C7A14 /* Const.swift in Sources */,
15858D952802A04200332653 /* UITextField+.swift in Sources */,
15F0B9402830945C008A300E /* NetworkResult.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
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)
}
}
2 changes: 1 addition & 1 deletion Instagram-Clone/Instagram-Clone/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
<string>Signin</string>
</dict>
</array>
</dict>
Expand Down
23 changes: 23 additions & 0 deletions Instagram-Clone/Instagram-Clone/Network/Base/GeneralResponse.swift
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
}
Comment on lines +16 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와웅 대박 멋있어.

}
30 changes: 30 additions & 0 deletions Instagram-Clone/Instagram-Clone/Network/Base/GeneralService.swift
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
}
}
}
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 Instagram-Clone/Instagram-Clone/Network/Base/NetworkResult.swift
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 Instagram-Clone/Instagram-Clone/Network/Base/URLConstants.swift
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"
}
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
}
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 Instagram-Clone/Instagram-Clone/Network/Router/AuthRouter.swift
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우왕 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
}
}
Loading