Skip to content

Commit

Permalink
[feat/#12] โœจ moya network serivce add
Browse files Browse the repository at this point in the history
# <ํƒ€์ž…>: <์ œ๋ชฉ>

##### ์ œ๋ชฉ์€ ์ตœ๋Œ€ 50 ๊ธ€์ž๊นŒ์ง€๋งŒ ์ž…๋ ฅ ############## -> |

# ๋ณธ๋ฌธ์€ ์œ„์— ์ž‘์„ฑ
######## ๋ณธ๋ฌธ์€ ํ•œ ์ค„์— ์ตœ๋Œ€ 72 ๊ธ€์ž๊นŒ์ง€๋งŒ ์ž…๋ ฅ ########################### -> |

# ๊ผฌ๋ฆฟ๋ง์€ ์•„๋ž˜์— ์ž‘์„ฑ: ex) #์ด์Šˆ ๋ฒˆํ˜ธ

# --- COMMIT END ---
# <ํƒ€์ž…> ๋ฆฌ์ŠคํŠธ
# feat       sparkles               : ๊ธฐ๋Šฅ(์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ)
# fix        beetle                 : ๋ฒ„๊ทธ(๋ฒ„๊ทธ ์ˆ˜์ •)
# refactor   hammer                 : refacetor ๋ฆฌํŒฉํ† ๋ง
# style      art                    : ์Šคํƒ€์ผ( ์ฝ”๋“œ ํ˜•์‹ ๋ณ€๊ฒฝ, ๋กœ์ง ๋ณ€๊ฒฝ ์—†์Œ)
# doc        pencil                 : ๋ฌธ์„œ(๋ฌธ์„œ ์ถ”๊ฐ€, ์ˆ˜์ •, ์‚ญ์ œ)
# test       white_check_mark       : ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ถ”๊ฐ€
# chore      moyai                  : ๊ธฐํƒ€ ๋ณ€๊ฒฝ์‚ฌํ•ญ
# ------------------
#     ์ œ๋ชฉ ์ฒซ ๊ธ€์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ
#     ์ œ๋ชฉ์€ ๋ช…๋ น๋ฌธ์œผ๋กœ
#     ์ œ๋ชฉ ๋์— ๋งˆ์นจํ‘œ(.) ๊ธˆ์ง€
#     ์ œ๋ชฉ๊ณผ ๋ณธ๋ฌธ์„ ํ•œ ์ค„ ๋„์›Œ ๋ถ„๋ฆฌํ•˜๊ธฐ
#     ๋ณธ๋ฌธ์€ "์–ด๋–ป๊ฒŒ" ๋ณด๋‹ค "๋ฌด์—‡์„", "์™œ"๋ฅผ ์„ค๋ช…ํ•œ๋‹ค.
#     ๋ณธ๋ฌธ์— ์—ฌ๋Ÿฌ์ค„์˜ ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•  ๋• "-"๋กœ ๊ตฌ๋ถ„
# ------------------
  • Loading branch information
i-colours-u committed Nov 14, 2021
1 parent 5e646b8 commit 95ad258
Show file tree
Hide file tree
Showing 19 changed files with 432 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
FDCD3A2E271C8DD20072AB10 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCD3A2D271C8DD20072AB10 /* SceneDelegate.swift */; };
FDCD3A30271CAFD60072AB10 /* MainNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCD3A2F271CAFD60072AB10 /* MainNavigationController.swift */; };
FDCD3A32271CB03E0072AB10 /* UIColor + Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCD3A31271CB03E0072AB10 /* UIColor + Extension.swift */; };
FDCDE61C274143BD00B2F413 /* AccountNC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCDE61B274143BD00B2F413 /* AccountNC.swift */; };
FDCDE61F27414FF600B2F413 /* BaseAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCDE61E27414FF600B2F413 /* BaseAPI.swift */; };
FDCDE62127414FFD00B2F413 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCDE62027414FFD00B2F413 /* Config.swift */; };
FDCDE6242741528900B2F413 /* BaseService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCDE6232741528900B2F413 /* BaseService.swift */; };
FDCDE6262741529F00B2F413 /* AccountService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCDE6252741529F00B2F413 /* AccountService.swift */; };
FDCDE6292741531700B2F413 /* AccountDataGettable.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDCDE6282741531700B2F413 /* AccountDataGettable.swift */; };
FDD7A6B9270AB1BC0099F245 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD7A6B8270AB1BC0099F245 /* AppDelegate.swift */; };
FDD7A6BD270AB1BC0099F245 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDD7A6BC270AB1BC0099F245 /* ViewController.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -173,6 +179,12 @@
FDCD3A2D271C8DD20072AB10 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
FDCD3A2F271CAFD60072AB10 /* MainNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainNavigationController.swift; sourceTree = "<group>"; };
FDCD3A31271CB03E0072AB10 /* UIColor + Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor + Extension.swift"; sourceTree = "<group>"; };
FDCDE61B274143BD00B2F413 /* AccountNC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountNC.swift; sourceTree = "<group>"; };
FDCDE61E27414FF600B2F413 /* BaseAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseAPI.swift; sourceTree = "<group>"; };
FDCDE62027414FFD00B2F413 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
FDCDE6232741528900B2F413 /* BaseService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseService.swift; sourceTree = "<group>"; };
FDCDE6252741529F00B2F413 /* AccountService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountService.swift; sourceTree = "<group>"; };
FDCDE6282741531700B2F413 /* AccountDataGettable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountDataGettable.swift; sourceTree = "<group>"; };
FDD7A6B5270AB1BC0099F245 /* sopt_29th_Assignment.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = sopt_29th_Assignment.app; sourceTree = BUILT_PRODUCTS_DIR; };
FDD7A6B8270AB1BC0099F245 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
FDD7A6BC270AB1BC0099F245 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -231,6 +243,7 @@
FD5B934927104B5E00BE2364 /* Global */ = {
isa = PBXGroup;
children = (
FDCDE61D27414FE400B2F413 /* Network */,
FD9D45A1272AA4F1006C108F /* Protocols */,
FD9D4581272A5E60006C108F /* Models */,
FD5B93752710637E00BE2364 /* UIComponents */,
Expand Down Expand Up @@ -334,6 +347,7 @@
FD5B936827105F7A00BE2364 /* SignInVC.swift */,
FD5B936A27105F8900BE2364 /* SignUpVC.swift */,
FD5B936C27105F9300BE2364 /* SignUpCompleteVC.swift */,
FDCDE61B274143BD00B2F413 /* AccountNC.swift */,
);
path = Account;
sourceTree = "<group>";
Expand All @@ -352,6 +366,7 @@
FD9D4581272A5E60006C108F /* Models */ = {
isa = PBXGroup;
children = (
FDCDE6272741530600B2F413 /* Account */,
FD9D4585272A5F5D006C108F /* Subscribe */,
);
path = Models;
Expand Down Expand Up @@ -565,6 +580,33 @@
path = Library;
sourceTree = "<group>";
};
FDCDE61D27414FE400B2F413 /* Network */ = {
isa = PBXGroup;
children = (
FDCDE6222741528000B2F413 /* Service */,
FDCDE61E27414FF600B2F413 /* BaseAPI.swift */,
FDCDE62027414FFD00B2F413 /* Config.swift */,
);
path = Network;
sourceTree = "<group>";
};
FDCDE6222741528000B2F413 /* Service */ = {
isa = PBXGroup;
children = (
FDCDE6232741528900B2F413 /* BaseService.swift */,
FDCDE6252741529F00B2F413 /* AccountService.swift */,
);
path = Service;
sourceTree = "<group>";
};
FDCDE6272741530600B2F413 /* Account */ = {
isa = PBXGroup;
children = (
FDCDE6282741531700B2F413 /* AccountDataGettable.swift */,
);
path = Account;
sourceTree = "<group>";
};
FDD7A6AC270AB1BC0099F245 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -721,6 +763,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FDCDE6292741531700B2F413 /* AccountDataGettable.swift in Sources */,
FD5B936D27105F9300BE2364 /* SignUpCompleteVC.swift in Sources */,
FD5B936B27105F8900BE2364 /* SignUpVC.swift in Sources */,
FDCD3A2C271C87580072AB10 /* LibraryCoordinator.swift in Sources */,
Expand All @@ -738,6 +781,7 @@
FDCD3A0A271C7C2D0072AB10 /* ShortsVC.swift in Sources */,
FD9D4593272A74AF006C108F /* CustomCollectionViewDataSource.swift in Sources */,
FD5B937E27106CB500BE2364 /* CustomBlueButton.swift in Sources */,
FDCDE62127414FFD00B2F413 /* Config.swift in Sources */,
FD5B938027106DBD00BE2364 /* ColorLiterals.swift in Sources */,
FDCD39E2271C50650072AB10 /* CoordinatorFinishOutput.swift in Sources */,
FDCD39FE271C773B0072AB10 /* MainTabCoordinator.swift in Sources */,
Expand All @@ -757,13 +801,15 @@
FD9D45C4272AC726006C108F /* SubscribeVC + UIScrollViewDelegate.swift in Sources */,
FDCD3A0E271C7C430072AB10 /* SubscribeVC.swift in Sources */,
FD5B935227104F4900BE2364 /* calculateTopInset.swift in Sources */,
FDCDE61C274143BD00B2F413 /* AccountNC.swift in Sources */,
FD5B9365271056BE00BE2364 /* ModuleFactory.swift in Sources */,
FD5B936927105F7A00BE2364 /* SignInVC.swift in Sources */,
FD9D458B272A5FC8006C108F /* SubscribeFilterList + Load.swift in Sources */,
FD9D4590272A6F91006C108F /* CustomTableViewDataSource.swift in Sources */,
FDCD3A10271C7CB10072AB10 /* LibraryVC.swift in Sources */,
FDCD3A08271C7C250072AB10 /* HomeVC.swift in Sources */,
FD5B9362271055A100BE2364 /* Storyboards.swift in Sources */,
FDCDE6262741529F00B2F413 /* AccountService.swift in Sources */,
FDD7A6B9270AB1BC0099F245 /* AppDelegate.swift in Sources */,
FD9D4589272A5F78006C108F /* YoutuberDataModel.swift in Sources */,
FD9D45AA272AAC2D006C108F /* MainHeaderView.swift in Sources */,
Expand All @@ -774,6 +820,7 @@
FDCD3A12271C83DD0072AB10 /* UIImage + Extension.swift in Sources */,
FDCD39FA271C63A30072AB10 /* SigningCoordinator.swift in Sources */,
FD5B934E27104DC700BE2364 /* makeVibrate.swift in Sources */,
FDCDE61F27414FF600B2F413 /* BaseAPI.swift in Sources */,
FDCD3A2E271C8DD20072AB10 /* SceneDelegate.swift in Sources */,
FD9D458D272A6455006C108F /* VideoDataModel.swift in Sources */,
FD9D45BC272ABDD5006C108F /* SubscribeFilterContainerView.swift in Sources */,
Expand All @@ -783,6 +830,7 @@
FD9D4587272A5F69006C108F /* SubscribeDataModel.swift in Sources */,
FD5B93872710841B00BE2364 /* addToolbar.swift in Sources */,
FD9D45A0272A97C0006C108F /* calculateDate.swift in Sources */,
FDCDE6242741528900B2F413 /* BaseService.swift in Sources */,
FDCD39E4271C507A0072AB10 /* BaseControllable.swift in Sources */,
FDCD3A28271C873C0072AB10 /* WritingCoordinator.swift in Sources */,
FD5B938527107DD000BE2364 /* ImageLiterals.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class MainTabCoordinator : BaseCoordinator, CoordinatorFinishOutput{
private let coordinatorFactory: CoordinatorFactoryProtocol
private let moduleFactory: ModuleFactoryProtocol
private var mainTabController: MainTabBarControllable?
private var launchInstructor = LaunchInstructor.configure()


// MARK: - Init
init(
Expand Down Expand Up @@ -51,6 +53,9 @@ class MainTabCoordinator : BaseCoordinator, CoordinatorFinishOutput{
extension MainTabCoordinator {
private func showMainTabBarController() {
self.mainTabController = self.moduleFactory.instantiateMainTabBarController()
self.mainTabController?.showSigningScene = { [weak self] in
self?.runSigningScene()
}
self.mainTabController?.onHomeScene = runHomeScene()
self.mainTabController?.onShortScene = runShortScene()
self.mainTabController?.onWritingScene = runWritingScene()
Expand Down Expand Up @@ -135,5 +140,19 @@ extension MainTabCoordinator {
}
}
}
private func runSigningScene() {
var coordinator = self.coordinatorFactory.makeSigningCoordinator(
router: self.router,
coordinatorFactory: self.coordinatorFactory,
moduleFactory: self.moduleFactory)
coordinator.finishScene = { [unowned self, unowned coordinator] in
self.launchInstructor = LaunchInstructor.configure(Logged.wasLoggedIn)
self.removeDependency(coordinator)
self.start()
}

self.addDependency(coordinator)
coordinator.start()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SubscribeCoordinator: BaseCoordinator, CoordinatorFinishOutput {
private let router: RouterProtocol
private let coordinatorFactory: CoordinatorFactoryProtocol
private let moduleFactory: ModuleFactoryProtocol
private var launchInstructor = LaunchInstructor.configure()

// MARK: - Init
init(
Expand All @@ -38,6 +39,10 @@ class SubscribeCoordinator: BaseCoordinator, CoordinatorFinishOutput {
extension SubscribeCoordinator {
private func showSubscribeVC() {
let vc = moduleFactory.instantitateSubscribeVC()
vc.onLoginButtonClicked = { [weak self] in
NotificationCenter.default.post(name: .showLoginScene, object: nil)
}
self.router.setRootModule(vc)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import Foundation
extension Notification.Name {
// MARK: - Tab Bar
static let selectTab = Notification.Name("selectTab")
static let showLoginScene = Notification.Name("showLoginScene")

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AccountDataGettable.swift
// sopt_29th_Assignment
//
// Created by ์†ก์ง€ํ›ˆ on 2021/11/14.
//

import Foundation

struct AccountDataGettable: Codable {
let status: Int
let success: Bool
let message: String
let data: UserData?
}

// MARK: - DataClass
struct UserData: Codable {
let id: Int
let name, email: String
}
151 changes: 151 additions & 0 deletions sopt_29th_Assignment/sopt_29th_Assignment/Global/Network/BaseAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//
// BaseAPI.swift
// sopt_29th_Assignment
//
// Created by ์†ก์ง€ํ›ˆ on 2021/11/14.
//

import Moya
import Alamofire


enum BaseAPI{
case sampleAPI(sample : String)
// ๊ณ„์ •๊ด€๋ จ
case postSignIn(email : String, pw : String)
case postSignUp(email : String, pw : String, name : String)
}


extension BaseAPI: TargetType {


// MARK: - Base URL

public var baseURL: URL {
var base = Config.Network.baseURL
switch self{
case .sampleAPI:
base += "๋”ํ•  ์ฃผ์†Œ"

case .postSignIn,.postSignUp:
base += "/user"
}
guard let url = URL(string: base) else {
fatalError("baseURL could not be configured")
}
return url
}

// MARK: - Path
var path: String {
switch self{
case .sampleAPI:
return "๋’ค์—๋ถ™๋Š” ์ฃผ์†Œ"
case .postSignIn:
return "/signin"
case .postSignUp:
return "/signin"
default :
return ""
}
}


// MARK: - Method
var method: Moya.Method {
switch self{

case .postSignIn,.postSignUp :
return .post
default :
return .get

}
}

// MARK: - Data
var sampleData: Data {
return Data()
}

// MARK: - Parameters
private var bodyParameters: Parameters? {
var params: Parameters = [:]
switch self{
case .sampleAPI:
params[""] = ""
case .postSignIn(let email, let password) :
params["email"] = email
params["password"] = password
case .postSignUp(let email, let password, let name):
params["email"] = email
params["name"] = name
params["password"] = password
default :
break
}
return params
}


// MARK: - MultiParts

private var multiparts: [Moya.MultipartFormData] {
switch self{
case .sampleAPI(_):
var multiparts : [Moya.MultipartFormData] = []
multiparts.append(.init(provider: .data("".data(using: .utf8) ?? Data()), name: ""))
return multiparts
default : return []
// images.forEach {
// multiparts.append(.init(provider: .data($0), name: "images", fileName: "image.jpeg", mimeType: "image/jpeg"))
// }
}
}


private var parameterEncoding : ParameterEncoding{
switch self {
case .sampleAPI:
return URLEncoding.init(destination: .queryString, arrayEncoding: .noBrackets, boolEncoding: .literal)
default :
return JSONEncoding.default
}
}








var task: Task {
switch self{
case .sampleAPI
:
return .uploadMultipart(multiparts)

case .postSignIn,.postSignUp:
return .requestParameters(parameters: bodyParameters ?? [:], encoding: parameterEncoding)

default :
return .requestPlain

}
}

public var headers: [String: String]? {
if let userToken = UserDefaults.standard.string(forKey: "userToken") {
return ["Authorization": userToken,
"Content-Type": "application/json"]
}else{
return ["Content-Type": "application/json"]
}
}

public var validationType: ValidationType {
return .successCodes
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Config.swift
// sopt_29th_Assignment
//
// Created by ์†ก์ง€ํ›ˆ on 2021/11/14.
//

import Foundation

struct Config
{
enum Network {
static var baseURL: String {
return "https://asia-northeast3-we-sopt-29.cloudfunctions.net/api"
}
}
}

Loading

0 comments on commit 95ad258

Please sign in to comment.