Skip to content

Commit

Permalink
✨ Feat: 로그인하기 UI제작 + action바인딩 ++ 하는김에 그냥 API연결 로그인&회원가입 한번에 진행 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
usa4060 authored Oct 27, 2023
1 parent d3af09b commit aec21b6
Show file tree
Hide file tree
Showing 29 changed files with 627 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CMC/Resources/Configure/Dev.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

BASE_URL = http:/$()/cmcapiserverdev-env.eba-au6k5x3x.ap-northeast-2.elasticbeanstalk.com
2 changes: 1 addition & 1 deletion CMC/Sources/App/Splash/SplashViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SplashViewModel: ViewModelType{
}

private func checkAutoSignIn(){
if let _: String = UserDefaultManager.shared.load(for: .jwtToken) {
if let _: String = UserDefaultManager.shared.load(for: .accessToken) {
self.coordinator?.userActionState.accept(.tabBar)
} else {
self.coordinator?.userActionState.accept(.auth)
Expand Down
30 changes: 30 additions & 0 deletions CMC/Sources/Data/DTO/Auth/SignInDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SignInDTO.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

// MARK: - SignInDTO
struct SignInDTO: Codable {
let isSuccess: Bool
let code, message: String
let result: SignInResponse

struct SignInResponse: Codable {
let userId: Int
let accessToken: String
let refreshToken: String
}

func toDomain() -> SignInModel {
return SignInModel(
userId: result.userId,
accessToken: result.accessToken,
refreshToken: result.refreshToken
)
}
}
30 changes: 30 additions & 0 deletions CMC/Sources/Data/DTO/Auth/SignUpDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SignUpDTO.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

// MARK: - SignUpDTO
struct SignUpDTO: Codable {
let isSuccess: Bool
let code, message: String
let result: SignUpResponse

struct SignUpResponse: Codable {
let userId: Int
let accessToken: String
let refreshToken: String
}

func toDomain() -> SignUpModel {
return SignUpModel(
userId: result.userId,
accessToken: result.accessToken,
refreshToken: result.refreshToken
)
}
}
File renamed without changes.
45 changes: 45 additions & 0 deletions CMC/Sources/Data/Endpoint/AuthEndpoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// AuthEndpoint.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

enum AuthEndpoint: Endpoint {

case signIn(body: SignInBody), signUp(body: SignUpBody)

var baseURL: URL? {
return URL(string: Xcconfig.BASE_URL + "/auth")
}

var method: HTTPMethod {
switch self {
case .signUp, .signIn:
return .POST
}
}

var path: String {
switch self {
case .signUp:
return "/signUp"
case .signIn:
return "/signIn"
}

}

var parameters: HTTPRequestParameterType? {
switch self {
case .signUp(let body):
return .body(body)
case .signIn(let body):
return .body(body)
}
}

}
9 changes: 0 additions & 9 deletions CMC/Sources/Data/Endpoint/Body/Body.swift

This file was deleted.

4 changes: 2 additions & 2 deletions CMC/Sources/Data/Endpoint/LaunchEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import Foundation

enum EmailEndpoint: Endpoint {
enum LaunchEndpoint: Endpoint {

case health

var baseURL: URL? {
return URL(string: "http://cmcapiserverdev-env.eba-au6k5x3x.ap-northeast-2.elasticbeanstalk.com")
return URL(string: Xcconfig.BASE_URL)
}

var method: HTTPMethod {
Expand Down
15 changes: 15 additions & 0 deletions CMC/Sources/Data/NetworkService/Body/Auth/SignInBody.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SignInBody.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

// MARK: - SignInBody
struct SignInBody: Codable {
let email: String
let password: String
}
19 changes: 19 additions & 0 deletions CMC/Sources/Data/NetworkService/Body/Auth/SignUpBody.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// SignUpBody.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

// MARK: - SignUpBody
struct SignUpBody: Codable {
let email: String
let password: String
let nickname: String
let name: String
let generation: Int
let part: String
}
43 changes: 43 additions & 0 deletions CMC/Sources/Data/Repositories/Auth/DefaultAuthRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// DefaultAuthRepository.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation
import RxSwift

final class DefaultAuthRepository: AuthRepository {

private let networkService: NetworkService

init() {
self.networkService = DefaultNetworkService()
}

func signUp(body: SignUpBody) -> Single<SignUpDTO> {
let endpoint = AuthEndpoint.signUp(body: body)
return networkService.request(endpoint)
.flatMap { data in
guard let dto = Utility.decode(SignUpDTO.self, from: data) else {
return Single.error(NetworkError.decodingFailed)
}
return Single.just(dto)
}
}

func signIn(body: SignInBody) -> Single<SignInDTO> {
let endpoint = AuthEndpoint.signIn(body: body)
return networkService.request(endpoint)
.flatMap { data in
guard let dto = Utility.decode(SignInDTO.self, from: data) else {
return Single.error(NetworkError.decodingFailed)
}
return Single.just(dto)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class DefaultLaunchRepository: LaunchRepository {
}

func health() -> Single<LaunchDTO> {
let endpoint = EmailEndpoint.health
let endpoint = LaunchEndpoint.health
return networkService.request(endpoint)
.flatMap { data in
guard let dto = Utility.decode(LaunchDTO.self, from: data) else {
Expand Down
17 changes: 17 additions & 0 deletions CMC/Sources/Domain/Models/Auth/SignInModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// SignInModel.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

// MARK: - SignInModel
struct SignInModel: Codable {
let userId: Int
let accessToken: String
let refreshToken: String
}

17 changes: 17 additions & 0 deletions CMC/Sources/Domain/Models/Auth/SignUpModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// SignUpModel.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation

// MARK: - SignUpModel
struct SignUpModel: Codable {
let userId: Int
let accessToken: String
let refreshToken: String
}

File renamed without changes.
15 changes: 15 additions & 0 deletions CMC/Sources/Domain/Repositories/Auth/AuthRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AuthRepository.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation
import RxSwift

protocol AuthRepository {
func signUp(body: SignUpBody) -> Single<SignUpDTO>
func signIn(body: SignInBody) -> Single<SignInDTO>
}
15 changes: 15 additions & 0 deletions CMC/Sources/Domain/Usecases/Auth/AuthUsecase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AuthUsecase.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation
import RxSwift

protocol AuthUsecase {
func signUp(body: SignUpBody) -> Single<SignUpModel>
func signIn(body: SignInBody) -> Single<SignInModel>
}
34 changes: 34 additions & 0 deletions CMC/Sources/Domain/Usecases/Auth/DefaultAuthUsecase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// DefaultAuthUsecase.swift
// CMC
//
// Created by Siri on 10/27/23.
// Copyright © 2023 com.centralMakeusChallenge. All rights reserved.
//

import Foundation
import RxSwift

final class DefaultAuthUsecase: AuthUsecase {

private let authRepository: AuthRepository

init(authRepository: AuthRepository) {
self.authRepository = authRepository
}

func signUp(body: SignUpBody) -> Single<SignUpModel> {
return authRepository.signUp(body: body)
.map { dto in
return dto.toDomain()
}
}

func signIn(body: SignInBody) -> Single<SignInModel> {
return authRepository.signIn(body: body)
.map { dto in
return dto.toDomain()
}
}

}
36 changes: 17 additions & 19 deletions CMC/Sources/Presenter/Auth/Coordinators/AuthCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class AuthCoordinator: CoordinatorType {
// MARK: - Navigation DEPTH 1 -
enum AuthCoordinatorChild{
case main
case emailSignUp
case emailSignIn
case signUp
case signIn
/// SignIn이 AuthHome의 역할
}

Expand Down Expand Up @@ -53,7 +53,7 @@ class AuthCoordinator: CoordinatorType {
}else {
self.pushViewController(viewController: mainAuthViewController)
}
case .emailSignUp:
case .signUp:
print("111111")
CMCToastManager.shared.addToast(message: "🍎 여기는 아직이지롱~ 😀")
// let emailSignUpViewController = EmailSignUpViewController(
Expand All @@ -69,22 +69,20 @@ class AuthCoordinator: CoordinatorType {
// }else {
// self.pushViewController(viewController: emailSignUpViewController)
// }
case .emailSignIn:
print("2222222")
CMCToastManager.shared.addToast(message: "🍎 여기도 아직이지롱~ 😀")
// let emailSignInViewController = EmailSignInViewController(
// viewModel: EmailSignInViewModel(
// coordinator: self,
// userEmailSignInUsecase: DefaultUserEmailSignInUsecase(
// userRepository: DefaultUserRepository()
// )
// )
// )
// if self.navigationController.viewControllers.contains(where: {$0 is EmailSignInViewController}) {
// self.navigationController.popViewController(animated: true)
// }else {
// self.pushViewController(viewController: emailSignInViewController)
// }
case .signIn:
let signInViewController = SignInViewController(
viewModel: SignInViewModel(
coordinator: self,
authUsecase: DefaultAuthUsecase(
authRepository: DefaultAuthRepository()
)
)
)
if self.navigationController.viewControllers.contains(where: {$0 is SignInViewController}) {
self.navigationController.popViewController(animated: true)
}else {
self.pushViewController(viewController: signInViewController)
}
}
}).disposed(by: disposeBag)
}
Expand Down
Loading

0 comments on commit aec21b6

Please sign in to comment.