Skip to content

Commit

Permalink
[Feat/#122] myUseCase 리펙토링
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Nov 26, 2024
1 parent ea0ddfc commit a6228a7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions HMH_Tuist_iOS/Projects/Domain/Sources/Entity/User/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import Foundation

public struct User: Equatable {
let name: String
let point: Int
public let name: String
public let point: Int

public init(name: String, point: Int) {
self.name = name
Expand Down
48 changes: 48 additions & 0 deletions HMH_Tuist_iOS/Projects/Domain/Sources/UseCase/My/MyUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// MyUseCase.swift
// Domain
//
// Created by 류희재 on 11/26/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation
import Combine
import Core

public protocol MyPageUseCaseType {
func getUserDate() -> AnyPublisher<User, UserError>
func logout()
func revokeUser()
}

final class MyPageUseCase: MyPageUseCaseType {
private let userRepository: UserRepositoryType
private var cancelBag = CancelBag()

init(userRepository: UserRepositoryType) {
self.userRepository = userRepository
}

func getUserDate() -> AnyPublisher<User, UserError> {
userRepository.getUserData()
.map { $0 }
.eraseToAnyPublisher()
}

func logout() {
userRepository.logout()
.sink { _ in
} receiveValue: { _ in
UserManager.shared.clearLogout()
}.store(in: cancelBag)
}

func revokeUser() {
userRepository.deleteAccount()
.sink { _ in
} receiveValue: { _ in
UserManager.shared.revokeData()
}.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Combine

import Core
import DSKit
import Domain

class MyPageViewModel: ObservableObject {

Expand Down

0 comments on commit a6228a7

Please sign in to comment.