-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feat: 로그인하기 UI제작 + action바인딩 ++ 하는김에 그냥 API연결 로그인&회원가입 한번에 진행 (#21)
- Loading branch information
Showing
29 changed files
with
627 additions
and
39 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
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
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 @@ | ||
// | ||
// 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 | ||
) | ||
} | ||
} |
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 @@ | ||
// | ||
// 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.
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,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) | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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
15 changes: 15 additions & 0 deletions
15
CMC/Sources/Data/NetworkService/Body/Auth/SignInBody.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,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
19
CMC/Sources/Data/NetworkService/Body/Auth/SignUpBody.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,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
43
CMC/Sources/Data/Repositories/Auth/DefaultAuthRepository.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,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) | ||
} | ||
} | ||
|
||
|
||
} |
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
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,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 | ||
} | ||
|
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,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.
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,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> | ||
} |
File renamed without changes.
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,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> | ||
} |
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,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() | ||
} | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.