Skip to content

Commit 4884ad0

Browse files
authored
Merge pull request #203 from DSM-PICK/feeture/(#202)-resign
🔗 :: (#202) 회원탈퇴 및 회원가입 로직 수정
2 parents 4f78549 + 9afff03 commit 4884ad0

18 files changed

Lines changed: 151 additions & 32 deletions

File tree

Projects/Data/Sources/API/AuthAPI.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public enum AuthAPI {
1111
case refreshToken
1212
case signup(req: SignupRequestParams)
1313
case passwordChange(req: PasswordChangeRequestParams)
14+
case resign
1415
}
1516

1617
extension AuthAPI: PiCKAPI {
@@ -30,6 +31,8 @@ extension AuthAPI: PiCKAPI {
3031
return "/refresh"
3132
case .passwordChange:
3233
return "/password"
34+
case .resign:
35+
return ""
3336
}
3437
}
3538

@@ -39,6 +42,8 @@ extension AuthAPI: PiCKAPI {
3942
return .post
4043
case .refreshToken:
4144
return .put
45+
case .resign:
46+
return .delete
4247
}
4348
}
4449

@@ -59,6 +64,8 @@ extension AuthAPI: PiCKAPI {
5964
switch self {
6065
case .refreshToken:
6166
return .refreshToken
67+
case .resign:
68+
return .accessToken
6269
default:
6370
return .tokenIsEmpty
6471
}

Projects/Data/Sources/DI/UseCaseAssembly.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public final class UseCaseAssembly: Assembly {
1818
container.register(LogoutUseCase.self) { resolver in
1919
LogoutUseCase(repository: resolver.resolve(AuthRepository.self)!)
2020
}
21+
container.register(ResignUseCase.self) { resolver in
22+
ResignUseCase(repository: resolver.resolve(AuthRepository.self)!)
23+
}
2124
container.register(RefreshTokenUseCase.self) { resolver in
2225
RefreshTokenUseCase(repository: resolver.resolve(AuthRepository.self)!)
2326
}

Projects/Data/Sources/DataSource/AuthDataSource.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import AppNetwork
1010

1111
protocol AuthDataSource {
1212
func signin(req: SigninRequestParams) -> Single<TokenDTO>
13-
func signup(req: SignupRequestParams) -> Completable
13+
func signup(req: SignupRequestParams) -> Single<TokenDTO>
1414
func passwordChange(req: PasswordChangeRequestParams) -> Completable
1515
func logout()
16+
func resign() -> Completable
1617
func refreshToken() -> Single<TokenDTO>
1718
}
1819

@@ -31,10 +32,10 @@ class AuthDataSourceImpl: BaseDataSource<AuthAPI>, AuthDataSource {
3132
.map(TokenDTO.self)
3233
}
3334

34-
func signup(req: SignupRequestParams) -> Completable {
35+
func signup(req: SignupRequestParams) -> Single<TokenDTO> {
3536
return request(.signup(req: req))
3637
.filterSuccessfulStatusCodes()
37-
.asCompletable()
38+
.map(TokenDTO.self)
3839
}
3940

4041
func passwordChange(req: PasswordChangeRequestParams) -> Completable {
@@ -51,6 +52,20 @@ class AuthDataSourceImpl: BaseDataSource<AuthAPI>, AuthDataSource {
5152
UserDefaultStorage.shared.remove(forKey: .userInfoData)
5253
}
5354

55+
func resign() -> Completable {
56+
return request(.resign)
57+
.filterSuccessfulStatusCodes()
58+
.asCompletable()
59+
.do(onCompleted: { [weak self] in
60+
guard let self else { return }
61+
self.keychain.delete(type: .accessToken)
62+
self.keychain.delete(type: .refreshToken)
63+
self.keychain.delete(type: .id)
64+
self.keychain.delete(type: .password)
65+
UserDefaultStorage.shared.remove(forKey: .userInfoData)
66+
})
67+
}
68+
5469
func refreshToken() -> Single<TokenDTO> {
5570
return request(.refreshToken)
5671
.filterSuccessfulStatusCodes()

Projects/Data/Sources/Repository/AuthRepositoryImpl.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,26 @@ class AuthRepositoryImpl: AuthRepository {
4242
}
4343

4444
func signup(req: SignupRequestParams) -> Completable {
45-
return remoteDataSource.signup(req: req)
45+
return Completable.create { [weak self] completable in
46+
guard let self = self else { return Disposables.create {} }
47+
48+
self.remoteDataSource.signup(req: req)
49+
.subscribe(onSuccess: { tokenData in
50+
self.keyChain.save(type: .accessToken, value: tokenData.accessToken)
51+
self.keyChain.save(type: .refreshToken, value: tokenData.refreshToken)
52+
53+
self.keyChain.save(type: .id, value: req.accountID)
54+
self.keyChain.save(type: .password, value: req.password)
55+
56+
self.watchDataSource.activate()
57+
completable(.completed)
58+
}, onFailure: {
59+
completable(.error($0))
60+
})
61+
.disposed(by: self.disposeBag)
62+
63+
return Disposables.create {}
64+
}
4665
}
4766

4867
func passwordChange(req: PasswordChangeRequestParams) -> Completable {
@@ -53,6 +72,10 @@ class AuthRepositoryImpl: AuthRepository {
5372
return remoteDataSource.logout()
5473
}
5574

75+
func resign() -> Completable {
76+
return remoteDataSource.resign()
77+
}
78+
5679
func refreshToken() -> Completable {
5780
return Completable.create { [weak self] completable in
5881
guard let self = self else { return Disposables.create {} }

Projects/Domain/Sources/Parameter/Auth/SignUpRequestParams.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public struct SignupRequestParams: Encodable {
88
public let classNum: Int
99
public let num: Int
1010
public let code: String
11+
public let deviceToken: String?
1112

1213
public init(
1314
accountID: String,
@@ -16,7 +17,8 @@ public struct SignupRequestParams: Encodable {
1617
grade: Int,
1718
classNum: Int,
1819
num: Int,
19-
code: String
20+
code: String,
21+
deviceToken: String?
2022

2123
) {
2224
self.accountID = accountID
@@ -26,6 +28,7 @@ public struct SignupRequestParams: Encodable {
2628
self.classNum = classNum
2729
self.num = num
2830
self.code = code
31+
self.deviceToken = deviceToken
2932
}
3033

3134
enum CodingKeys: String, CodingKey {
@@ -36,6 +39,7 @@ public struct SignupRequestParams: Encodable {
3639
case classNum = "class_num"
3740
case num
3841
case code
42+
case deviceToken = "device_token"
3943
}
4044

4145
}

Projects/Domain/Sources/Parameter/Auth/SigninRequestParams.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import Foundation
33
public struct SigninRequestParams: Encodable {
44
public let accountID: String
55
public let password: String
6-
public let deviceToken: String
6+
public let deviceToken: String?
77

88
public init(
99
accountID: String,
1010
password: String,
11-
deviceToken: String
11+
deviceToken: String?
1212
) {
1313
self.accountID = accountID
1414
self.password = password

Projects/Domain/Sources/Repository/AuthRepository.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public protocol AuthRepository {
77
func signup(req: SignupRequestParams) -> Completable
88
func passwordChange(req: PasswordChangeRequestParams) -> Completable
99
func logout()
10+
func resign() -> Completable
1011
func refreshToken() -> Completable
1112
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
3+
import RxSwift
4+
5+
public struct ResignUseCase {
6+
let repository: AuthRepository
7+
8+
public init(repository: AuthRepository) {
9+
self.repository = repository
10+
}
11+
12+
public func execute() -> Completable {
13+
repository.resign()
14+
}
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "resign.svg",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)