-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Fix] QA 반영 #359
[Fix] QA 반영 #359
Changes from 5 commits
4a3739e
ea8172e
2437173
095db04
33b6624
40fb08d
ebdb48a
a50ee78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ import RxSwift | |
import RxCocoa | ||
|
||
class NicknameViewController: BaseViewController { | ||
|
||
private let nicknameView = NicknameView() | ||
private let viewModel: NicknameViewModel | ||
private let disposeBag = DisposeBag() | ||
|
@@ -35,6 +35,8 @@ class NicknameViewController: BaseViewController { | |
setupTextField() | ||
setupTapGesture() | ||
setupNavigationBarTitle(with: "닉네임 설정") | ||
navigationItem.leftBarButtonItem = nil | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 빈 줄 삭제 부탁드려요! |
||
} | ||
|
||
private func setupBindings() { | ||
|
@@ -136,6 +138,7 @@ class NicknameViewController: BaseViewController { | |
.disposed(by: disposeBag) | ||
view.addGestureRecognizer(tapGesture) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빈 줄 삭제! |
||
} | ||
|
||
extension NicknameViewController: UITextFieldDelegate { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
// | ||
|
||
import UIKit | ||
|
||
import Kingfisher | ||
|
||
class ProfileSetupViewModel { | ||
|
@@ -17,52 +18,73 @@ class ProfileSetupViewModel { | |
private let authService: AuthServiceProtocol | ||
private var imageData: Data? | ||
private let maxImageSizeBytes = 4 * 1024 * 1024 | ||
|
||
init(nickname: String, authService: AuthServiceProtocol = AuthService()) { | ||
self.nickname = nickname | ||
self.authService = authService | ||
} | ||
|
||
func updateProfileImage(_ image: UIImage?) { | ||
profileImage.value = image | ||
if let image = image, let data = image.jpegData(compressionQuality: 1.0) { | ||
imageData = data | ||
print("이미지 크기: \(data.count) bytes") | ||
if let image = image { | ||
imageData = compressImage(image) | ||
print("압축된 이미지 크기: \(imageData?.count ?? 0) bytes") | ||
} else { | ||
imageData = nil | ||
} | ||
isConfirmButtonEnabled.value = imageData != nil | ||
clearImageCache() | ||
} | ||
|
||
private func compressImage(_ image: UIImage) -> Data? { | ||
var compression: CGFloat = 1.0 | ||
var imageData = image.jpegData(compressionQuality: compression) | ||
|
||
while (imageData?.count ?? 0) > maxImageSizeBytes && compression > 0.1 { | ||
compression -= 0.1 | ||
imageData = image.jpegData(compressionQuality: compression) | ||
} | ||
|
||
return imageData | ||
} | ||
|
||
func uploadProfileImage() async -> Bool { | ||
print("uploadProfileImage 함수 호출됨") | ||
guard let imageData = imageData else { | ||
print("이미지 데이터가 없습니다.") | ||
serverResponse.value = "이미지 데이터가 없습니다." | ||
return false | ||
} | ||
|
||
print("업로드할 이미지 데이터 크기: \(imageData.count) bytes") | ||
|
||
let fileName = "profile_image.jpg" | ||
let mimeType = "image/jpeg" | ||
|
||
do { | ||
let _: EmptyModel = try await authService.performRequest( | ||
.updateProfileImage( | ||
image: imageData, | ||
fileName: fileName, | ||
mimeType: mimeType | ||
) | ||
) | ||
serverResponse.value = "프로필 이미지가 성공적으로 업로드되었습니다." | ||
print("프로필 이미지 업로드 성공") | ||
return true | ||
} catch { | ||
handleError(error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다.")) | ||
return false | ||
} | ||
} | ||
print("uploadProfileImage 함수 호출됨") | ||
Comment on lines
-65
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 정도의 |
||
guard let imageData = imageData else { | ||
print("이미지 데이터가 없습니다.") | ||
serverResponse.value = "이미지 데이터가 없습니다." | ||
return false | ||
} | ||
|
||
if imageData.count > maxImageSizeBytes { | ||
print("이미지 크기가 최대 허용 크기를 초과합니다.") | ||
serverResponse.value = "이미지 크기가 너무 큽니다. 더 작은 이미지를 선택해주세요." | ||
return false | ||
} | ||
|
||
print("업로드할 이미지 데이터 크기: \(imageData.count) bytes") | ||
|
||
let fileName = "profile_image.jpg" | ||
let mimeType = "image/jpeg" | ||
|
||
do { | ||
let _: EmptyModel = try await authService.performRequest( | ||
.updateProfileImage( | ||
image: imageData, | ||
fileName: fileName, | ||
mimeType: mimeType | ||
) | ||
) | ||
serverResponse.value = "프로필 이미지가 성공적으로 업로드되었습니다." | ||
print("프로필 이미지 업로드 성공") | ||
|
||
Comment on lines
+79
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 성공했을 때의 |
||
clearImageCache() | ||
return true | ||
} catch { | ||
handleError(error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다.")) | ||
return false | ||
} | ||
} | ||
|
||
private func handleError(_ error: NetworkError) { | ||
switch error { | ||
|
@@ -81,4 +103,9 @@ class ProfileSetupViewModel { | |
} | ||
print("프로필 이미지 업로드 실패: \(error.message)") | ||
} | ||
|
||
private func clearImageCache() { | ||
KingfisherManager.shared.cache.clearMemoryCache() | ||
KingfisherManager.shared.cache.clearDiskCache() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍