diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..349726f --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +# Xcode +*.xcodeproj/xcuserdata/ +*.xcodeproj/project.xcworkspace/xcuserdata/ +*.xcworkspace/xcuserdata/ +DerivedData/ +build/ +*.ipa +*.dSYM.zip +*.dSYM + +# CocoaPods +Pods/ + +# SPM +.build/ +Package.resolved + +# oh-my-claudecode +.omc/ + +# Claude Code +.claude/ + +# OS +.DS_Store +*.swp +*~ + +# Firebase +GoogleService-Info.plist + +# Secrets +*.env +*.pem +*.p12 +*.key diff --git a/BanGiDa/Application/DIContainer.swift b/BanGiDa/Application/DIContainer.swift index b863d5a..a5109aa 100644 --- a/BanGiDa/Application/DIContainer.swift +++ b/BanGiDa/Application/DIContainer.swift @@ -48,6 +48,13 @@ final class AppDIContainer { return CheckUserRegistrationUseCaseImpl(userRepository: userRepository) } + container.register(UpdateLastSeenAtUseCase.self) { resolver in + guard let userRepository = resolver.resolve(UserRepository.self) else { + fatalError("UserRepository dependency has not been registered.") + } + return UpdateLastSeenAtUseCaseImpl(userRepository: userRepository) + } + container.register(UpdateNicknameUseCase.self) { resolver in guard let userRepository = resolver.resolve(UserRepository.self) else { fatalError("UserRepository dependency has not been registered.") diff --git a/BanGiDa/Application/SceneDelegate.swift b/BanGiDa/Application/SceneDelegate.swift index b91d95a..848e549 100644 --- a/BanGiDa/Application/SceneDelegate.swift +++ b/BanGiDa/Application/SceneDelegate.swift @@ -13,6 +13,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { @Injected private var checkUserRegistrationUseCase: CheckUserRegistrationUseCase @Injected private var createAuthUserUseCase: CreateAuthUserUseCase + @Injected private var updateLastSeenAtUseCase: UpdateLastSeenAtUseCase func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. @@ -48,6 +49,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { func sceneWillEnterForeground(_ scene: UIScene) { // Called as the scene transitions from the background to the foreground. // Use this method to undo the changes made on entering the background. + updateLastSeenAt() } func sceneDidEnterBackground(_ scene: UIScene) { @@ -68,5 +70,15 @@ private extension SceneDelegate { } } } + + func updateLastSeenAt() { + Task { + do { + try await updateLastSeenAtUseCase.execute() + } catch { + print("updateLastSeenAt Error: ", error) + } + } + } } diff --git a/BanGiDa/UseCase/User/CheckUserRegistrationUseCase.swift b/BanGiDa/UseCase/User/CheckUserRegistrationUseCase.swift index 323c3f3..4a7c9a0 100644 --- a/BanGiDa/UseCase/User/CheckUserRegistrationUseCase.swift +++ b/BanGiDa/UseCase/User/CheckUserRegistrationUseCase.swift @@ -21,12 +21,6 @@ public final class CheckUserRegistrationUseCaseImpl: CheckUserRegistrationUseCas public func execute() async throws -> Bool { guard let uid = userRepository.loadUID() else { return false } - let result = try await userRepository.checkRegistration(uid: uid) - - if result { - try await userRepository.updateLastSeenAt() - } - - return result + return try await userRepository.checkRegistration(uid: uid) } } diff --git a/BanGiDa/UseCase/User/UpdateLastSeenAtUseCase.swift b/BanGiDa/UseCase/User/UpdateLastSeenAtUseCase.swift new file mode 100644 index 0000000..c91b842 --- /dev/null +++ b/BanGiDa/UseCase/User/UpdateLastSeenAtUseCase.swift @@ -0,0 +1,25 @@ +// +// UpdateLastSeenAtUseCase.swift +// BanGiDa +// +// Created by 홍석준 on 3/28/26. +// + +import Foundation + +public protocol UpdateLastSeenAtUseCase { + func execute() async throws +} + +public final class UpdateLastSeenAtUseCaseImpl: UpdateLastSeenAtUseCase { + private let userRepository: UserRepository + + public init(userRepository: UserRepository) { + self.userRepository = userRepository + } + + public func execute() async throws { + guard userRepository.loadUID() != nil else { return } + try await userRepository.updateLastSeenAt() + } +}