Skip to content

Commit

Permalink
[Feat] 회원가입/로그인 서버 연결 (#13)
Browse files Browse the repository at this point in the history
회원가입, 로그인 서버 연결
  • Loading branch information
pcsoyeon authored May 28, 2022
2 parents fd421e1 + ea6c003 commit 5bcf019
Show file tree
Hide file tree
Showing 122 changed files with 19,214 additions and 2,381 deletions.
130 changes: 105 additions & 25 deletions Instagram/Instagram.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions Instagram/Instagram/Network/API/Auth/SignInAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// SignInAPI.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

import Moya

final class SignInAPI {

// MARK: - Static Properties

static let shared: SignInAPI = SignInAPI()
private init() { }

// MARK: - Network Properties

var authProvider = MoyaProvider<SignInService>(plugins: [MoyaLoggerPlugin()])

public private(set) var signInResponse: BaseResponse<SignInResponse>?
public private(set) var signUpData: SignInResponse?

// MARK: - GET

func signUp(parameter: AuthRequest, completion: @escaping ((SignInResponse?, Error?) -> ())) {
authProvider.request(.signIn(parameter: parameter)) { [weak self] response in
switch response {
case .success(let result):
do {
self?.signInResponse = try result.map(BaseResponse<SignInResponse>.self)
guard let data = self?.signInResponse?.data else {
completion(nil, Error.self as? Error)
return
}
completion(data, nil)
} catch(let err) {
print(err.localizedDescription)
completion(nil, err)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil, err)
}
}
}
}

49 changes: 49 additions & 0 deletions Instagram/Instagram/Network/API/Auth/SignUpAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// SignUpAPI.swift
// Instagram
//
// Created by 소연 on 2022/05/10.
//

import Foundation

import Moya

final class SignUpAPI {

// MARK: - Static Properties

static let shared: SignUpAPI = SignUpAPI()
private init() { }

// MARK: - Network Properties

var authProvider = MoyaProvider<SignUpService>(plugins: [MoyaLoggerPlugin()])

public private(set) var signUpResponse: BaseResponse<SignUpResponse>?
public private(set) var signUpData: SignUpResponse?

// MARK: - GET

func signUp(parameter: SignUpRequest, completion: @escaping ((SignUpResponse?, Error?) -> ())) {
authProvider.request(.signUp(parameter: parameter)) { [weak self] response in
switch response {
case .success(let result):
do {
self?.signUpResponse = try result.map(BaseResponse<SignUpResponse>.self)
guard let data = self?.signUpResponse?.data else {
completion(nil, Error.self as? Error)
return
}
completion(data, nil)
} catch(let err) {
print(err.localizedDescription)
completion(nil, err)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil, err)
}
}
}
}
50 changes: 50 additions & 0 deletions Instagram/Instagram/Network/API/Home/HomeAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// HomeAPI.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

import Moya

final class HomeAPI {

// MARK: - Static Properties

static let shared: HomeAPI = HomeAPI()
private init() { }

// MARK: - Network Properties

private let homeProvider = MoyaProvider<HomeService>(plugins: [MoyaLoggerPlugin()])

public private(set) var homeResponse: BaseArrayResponseType<HomeResponse>?
public private(set) var homeData: [HomeResponse]?

func getImageList(completion: @escaping (([HomeResponse]?, Error?) -> ())) {
homeProvider.request(.imageList) { [weak self] response in
guard let self = self else { return }
switch response {
case .success(let result):
do {
self.homeResponse = try result.map(BaseArrayResponseType<HomeResponse>.self)
guard let data = self.homeResponse?.data else {
completion(nil, Error.self as? Error)
return
}
self.homeData = data

completion(data, nil)
} catch(let err) {
print(err.localizedDescription)
completion(nil, err)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil, err)
}
}
}
}
8 changes: 0 additions & 8 deletions Instagram/Instagram/Network/API/TempAPI.swift

This file was deleted.

12 changes: 12 additions & 0 deletions Instagram/Instagram/Network/APIModel/Auth/AuthRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// AuthRequest.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

struct AuthRequest: Codable {
let name, email, password: String
}
14 changes: 14 additions & 0 deletions Instagram/Instagram/Network/APIModel/Auth/SignInRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SignInRequest.swift
// Instagram
//
// Created by 소연 on 2022/05/10.
//

import Foundation

// MARK: - SignUp Request

struct SignInRequest: Codable {
let email, password: String
}
14 changes: 14 additions & 0 deletions Instagram/Instagram/Network/APIModel/Auth/SignInResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SignInResponse.swift
// Instagram
//
// Created by 소연 on 2022/05/10.
//

import Foundation

// MARK: - SignIn Response

struct SignInResponse: Codable {
let name, email: String
}
14 changes: 14 additions & 0 deletions Instagram/Instagram/Network/APIModel/Auth/SignUpRequest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SignUpRequest.swift
// Instagram
//
// Created by 소연 on 2022/05/10.
//

import Foundation

// MARK: - SignUp Request

struct SignUpRequest: Codable {
let name, email, password: String
}
15 changes: 15 additions & 0 deletions Instagram/Instagram/Network/APIModel/Auth/SignUpResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SignUpResponse.swift
// Instagram
//
// Created by 소연 on 2022/05/10.
//

import Foundation

// MARK: - SignUp Response

struct SignUpResponse: Codable {
let id: Int
}

21 changes: 21 additions & 0 deletions Instagram/Instagram/Network/APIModel/Home/HomeResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// HomeResponse.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

// MARK: - HomeResponse

struct HomeResponse: Codable {
let id, author: String
let width, height: Int
let url, downloadURL: String

enum CodingKeys: String, CodingKey {
case id, author, width, height, url
case downloadURL = "download_url"
}
}
8 changes: 0 additions & 8 deletions Instagram/Instagram/Network/DataModel/TempDataModel.swift

This file was deleted.

59 changes: 59 additions & 0 deletions Instagram/Instagram/Network/Service/Auth/SignInService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// SignInService.swift
// Instagram
//
// Created by 소연 on 2022/05/13.
//

import Foundation

import Moya

enum SignInService {
case signIn(parameter: AuthRequest)
}

extension SignInService: TargetType {
var baseURL: URL {
return URL(string: GeneralAPI.baseURL)!
}

var path: String {
switch self {
case .signIn:
return GeneralAPI.signInURL
}
}

var parameterEncoding: ParameterEncoding {
switch self {
case .signIn:
return JSONEncoding.default
}
}

var method: Moya.Method {
switch self {
case .signIn:
return .post
}
}

var task: Task {
switch self {
case .signIn(let parameter):
let parameter: [String: Any] = ["name": parameter.name,
"email": parameter.email,
"password": parameter.password]
return .requestParameters(parameters: parameter, encoding: JSONEncoding.default)
}
}

var headers: [String : String]? {
switch self {
case .signIn:
return ["Content-Type": "application/json"]
}
}
}

58 changes: 58 additions & 0 deletions Instagram/Instagram/Network/Service/Auth/SignUpService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// AuthService.swift
// Instagram
//
// Created by 소연 on 2022/05/10.
//

import Foundation

import Moya

enum SignUpService {
case signUp(parameter: SignUpRequest)
}

extension SignUpService: TargetType {
var baseURL: URL {
return URL(string: GeneralAPI.baseURL)!
}

var path: String {
switch self {
case .signUp:
return GeneralAPI.signUpURL
}
}

var parameterEncoding: ParameterEncoding {
switch self {
case .signUp:
return JSONEncoding.default
}
}

var method: Moya.Method {
switch self {
case .signUp:
return .post
}
}

var task: Task {
switch self {
case .signUp(let parameter):
let parameter: [String: Any] = ["name": parameter.name,
"email": parameter.email,
"password": parameter.password]
return .requestParameters(parameters: parameter, encoding: JSONEncoding.default)
}
}

var headers: [String : String]? {
switch self {
case .signUp:
return ["Content-Type": "application/json"]
}
}
}
Loading

0 comments on commit 5bcf019

Please sign in to comment.