Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GWL-312] UserDefatuls를 통한 프로필 이미지 및, 닉네임 저장 하는 UseCase연결 #328

Merged
merged 3 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ extension AppCoordinator: SplashCoordinatorFinishDelegate {
// MARK: SignUpFeatureCoordinatorFinishDelegate

extension AppCoordinator: SignUpFeatureCoordinatorFinishDelegate {
func signUpFeatureCooridnatorDidFinished() {
func signUpFeatureCoordinatorDidFinished() {
showTabBarFlow()
}
}
Expand Down
2 changes: 1 addition & 1 deletion iOS/Projects/Features/SignUp/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let project = Project.makeModule(
targets: .feature(
.signUp,
testingOptions: [.unitTest],
dependencies: [.trinet, .keychain, .combineCocoa, .coordinator, .log, .designSystem, .commonNetworkingKeyManager, .auth, .downSampling],
dependencies: [.trinet, .keychain, .combineCocoa, .coordinator, .log, .designSystem, .commonNetworkingKeyManager, .auth, .downSampling, .userInformationManager],
testDependencies: [],
resources: "Resources/**"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SignUpUserDefaultsManagerUseCase.swift
// SignUpFeature
//
// Created by MaraMincho on 12/10/23.
// Copyright © 2023 kr.codesquad.boostcamp8. All rights reserved.
//

import Foundation
import UserInformationManager

// MARK: - SignUpUserDefaultsManagerUseCaseRepresentable

protocol SignUpUserDefaultsManagerUseCaseRepresentable {
func setSignUpUserInformation(signUpUser: SignUpUser)
}

// MARK: - SignUpUserDefaultsManagerUseCase

struct SignUpUserDefaultsManagerUseCase {
let manager = UserInformationManager.shared
func setSignUpUserInformationAtUserDefaults(_ signUpUserInformation: SignUpUser) {
// UserDefaults에 nickName을 저장합니다.
manager.setUserName(signUpUserInformation.nickname)

// UserDefaults에 ProfileImage URL을 저장합니다.
manager.setUserProfileImageURLString(url: signUpUserInformation.profileImage)

// UserDefaults에 ProfileImage Data를 저장합니다.
manager.setUserProfileImageData(url: signUpUserInformation.profileImage)

// UserDefaults에 생년 월일을 저장합니다.
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
let date = formatter.date(from: signUpUserInformation.birthDate)
manager.setBirthDayDate(date)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import UIKit
// MARK: - SignUpFeatureCoordinatorFinishDelegate

public protocol SignUpFeatureCoordinatorFinishDelegate: AnyObject {
func signUpFeatureCooridnatorDidFinished()
func signUpFeatureCoordinatorDidFinished()
}

// MARK: - SignUpFeatureCoordinator
Expand Down Expand Up @@ -47,7 +47,7 @@ public final class SignUpFeatureCoordinator: SignUpFeatureCoordinating {

public func finish() {
finishDelegate?.flowDidFinished(childCoordinator: self)
signUpFeatureFinishDelegate?.signUpFeatureCooridnatorDidFinished()
signUpFeatureFinishDelegate?.signUpFeatureCoordinatorDidFinished()
}

public func pushSingUpContainerViewController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class UserInformationManager {
case userNickName = "UserNickName"
case userProfileImage = "UserProfileImage"
case birthDayDate = "BirthDayDate"
case userProfileImageURL = "UserImageURL"
case userProfileImageURL = "UserProfileImageURL"
}
}

Expand All @@ -45,29 +45,50 @@ public extension UserInformationManager {
defaults.setValue(nameData, forKey: UserInformation.userNickName.rawValue)
}

func setUserProfileImageData(url: URL?) {
guard let url else {
return
}

DispatchQueue.global().async { [weak self] in
guard let data = try? Data(contentsOf: url) else {
return
}
self?.setUserProfileImageData(data)
}
}

func setUserProfileImageData(_ imageData: Data) {
defaults.setValue(imageData, forKey: UserInformation.userNickName.rawValue)
}

func setBirthDayDate(_ date: Date) {
func setBirthDayDate(_ date: Date?) {
let date = date ?? .now
Comment on lines +65 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3

Date값은 안들어오면 다음창으로 넘어갈 수 없어서 옵셔널이 아니어도 좋을것 같습니다!

let dateString = dateFormatter.string(from: date)
let data = Data(dateString.utf8)
defaults.setValue(data, forKey: UserInformation.birthDayDate.rawValue)
}

func setUserProfileImageURLString(url: URL?) {
guard let urlString = url?.absoluteString else {
return
}
let data = Data(urlString.utf8)
defaults.setValue(data, forKey: UserInformation.userProfileImageURL.rawValue)
}
}

/// Defaults이미지를 저장합니다.
private extension UserInformationManager {
/// 만약 userDefaults에 값이 존재한다면 fakeData를 설정합니다.
/// 만약 userDefaults에 값이 존재하지 않는다면 fakeData를 설정합니다.
func setDefaultsData() {
// guard
// data(.userNickName) == nil,
// data(.birthDayDate) == nil,
// data(.userProfileImage) == nil,
// data(.userProfileImageURL) == nil
// else {
// return
// }
if
data(.userNickName) != nil ||
data(.birthDayDate) != nil ||
data(.userProfileImage) != nil ||
data(.userProfileImageURL) != nil {
return
}

let date = Date.now
let formatter = DateFormatter()
Expand All @@ -79,9 +100,8 @@ private extension UserInformationManager {
let name = Data("슈퍼맨".utf8)
defaults.setValue(name, forKey: UserInformation.userNickName.rawValue)

let imageURLString = "https://www.catster.com/wp-content/uploads/2017/08/Pixiebob-cat.jpg"
let imageURLData = Data(imageURLString.utf8)
defaults.setValue(imageURLData, forKey: UserInformation.userProfileImageURL.rawValue)
let url = URL(string: "https://www.catster.com/wp-content/uploads/2017/08/Pixiebob-cat.jpg")
setUserProfileImageURLString(url: url)

guard
let path = Bundle(for: Self.self).path(forResource: DefaultsKey.imageKey, ofType: DefaultsKey.imageType),
Expand Down