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

Fix [#65] 세부사항 수정 #68

Merged
merged 7 commits into from
Jan 14, 2024
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
11 changes: 0 additions & 11 deletions DontBe-iOS/DontBe-iOS/Global/Extension/UIViewController+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,3 @@ extension UIViewController {
return UIApplication.shared.windows.filter({$0.isKeyWindow}).first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 20
}
}

extension UINavigationController: UIGestureRecognizerDelegate {
override open func viewDidLoad() {
super.viewDidLoad()
interactivePopGestureRecognizer?.delegate = self
}

public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return viewControllers.count > 1
}
}

Choose a reason for hiding this comment

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

주어진 코드에 대한 간단한 코드 리뷰입니다.

변경된 부분:

  • extension UIViewController에서 statusBarHeight라는 계산된 프로퍼티가 추가되었습니다. 이 프로퍼티는 상태 표시줄의 높이를 반환합니다.
  • UINavigationController extension이 삭제되었습니다.

버그 위험 및 개선 제안:

  • 주어진 코드 패치에는 큰 문제가 보이지 않습니다. 단, 사용자 인터페이스와 관련하여 어떤 기능을 달성하려는지 명확하게 이해할 필요가 있습니다. 즉, 코드가 속하는 프로젝트의 전반적인 구조와 목적을 파악한 다음에야 더 정확한 리뷰를 할 수 있습니다.

일반적으로 코드 리뷰에는 다음과 같은 몇 가지 체크 포인트가 있을 수 있습니다:

  1. 이름 짓기: 변수, 함수 및 클래스의 이름이 명확하고 일관성 있으며 의미있는지 확인합니다.
  2. 가독성: 코드의 가독성을 향상시키기 위해 주석, 들여쓰기, 공백 등을 확인합니다.
  3. 성능 및 메모리 관리: 코드가 효율적이고 자원을 효과적으로 사용하는지 확인합니다.
  4. 잠재적인 오류: 코드에 잠재적인 버그가 있는지 확인합니다.

다만, 주어진 코드 패치가 개별 프로젝트의 일부분이기 때문에 상황에 따라 다른 리뷰 포인트가 필요할 수 있습니다.

19 changes: 11 additions & 8 deletions DontBe-iOS/DontBe-iOS/Network/Foundation/NetworkService.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// KakaoLoginService.swift
// NetworkService.swift
// DontBe-iOS
//
// Created by 변희주 on 1/14/24.
Expand Down Expand Up @@ -36,17 +36,20 @@ final class NetworkService: NetworkServiceType {
request.addValue($0.value, forHTTPHeaderField: $0.key)
}

// 리퀘스트 바디 설정 (구조체)
do {
let jsonData = try JSONEncoder().encode(body)
request.httpBody = jsonData
} catch {
print("Failed to encode request body: \(error)")
if type == .get {
request.httpBody = nil
} else {
// 리퀘스트 바디 설정 (구조체)
do {
let jsonData = try JSONEncoder().encode(body)
request.httpBody = jsonData
} catch {
print("Failed to encode request body: \(error)")
}
}

return request
}


func donNetwork<T: Decodable>(type: HttpMethod,
baseURL: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,15 @@ extension LoginViewController {

output.userInfoPublisher
.receive(on: RunLoop.main)
.sink { isFirstUser in
if isFirstUser {
.sink { value in
if value {
// 첫 로그인 유저면 여기
let viewController = JoinAgreementViewController(viewModel: JoinAgreeViewModel())
self.navigationController?.pushViewController(viewController, animated: true)
} else {
// 이미 가입한 유저면 여기
let isJoinedUser = loadUserData()?.isJoinedApp ?? false

// 회원가입 약관동의를 한 유저
if isJoinedUser {
let viewController = OnboardingViewController()
let viewController = OnboardingViewController()
viewController.originView.isFirstUser = false
self.navigationController?.pushViewController(viewController, animated: true)
} else {
// 회원가입 약관동의를 안한 유저
let viewController = JoinAgreementViewController(viewModel: JoinAgreeViewModel())
self.navigationController?.pushViewController(viewController, animated: true)
}
}
}
.store(in: self.cancelBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,56 +37,49 @@ final class LoginViewModel: ViewModelType {
func transform(from input: Input, cancelBag: CancelBag) -> Output {
input.kakaoButtonTapped
.sink {
Task {
do {
if UserApi.isKakaoTalkLoginAvailable() {
let oauthToken = try await self.loginWithKakaoTalk()
let isNewUser = try await self.getSocialLoginAPI(oauthToken: oauthToken)?.data?.isNewUser ?? false
self.userInfoPublisher.send(isNewUser)
} else {
let oauthToken = try await self.loginWithKakaoAccount()
let isNewUser = try await self.getSocialLoginAPI(oauthToken: oauthToken)?.data?.isNewUser ?? false
self.userInfoPublisher.send(isNewUser)
}
print("👻👻👻👻👻카카오 로그인 성공👻👻👻👻👻")
} catch {
print(error)
}
}
self.performKakaoLogin()
}
.store(in: self.cancelBag)
.store(in: cancelBag)

return Output(userInfoPublisher: userInfoPublisher)
}
}

extension LoginViewModel {
private func loginWithKakaoTalk() async throws -> OAuthToken {
return try await withCheckedThrowingContinuation { continuation in
UserApi.shared.loginWithKakaoTalk { oauthToken, error in
if let error = error {
continuation.resume(throwing: error)
} else if let oauthToken = oauthToken {
continuation.resume(returning: oauthToken)
}

private func performKakaoLogin() {
if UserApi.isKakaoTalkLoginAvailable() {
UserApi.shared.loginWithKakaoTalk { [weak self] (oauthToken, error) in
self?.handleKakaoLoginResult(oauthToken: oauthToken, error: error)
}
} else {
UserApi.shared.loginWithKakaoAccount { [weak self] (oauthToken, error) in
self?.handleKakaoLoginResult(oauthToken: oauthToken, error: error)
}
}
}

private func loginWithKakaoAccount() async throws -> OAuthToken {
return try await withCheckedThrowingContinuation { continuation in
UserApi.shared.loginWithKakaoAccount { oauthToken, error in
if let error = error {
continuation.resume(throwing: error)
} else if let oauthToken = oauthToken {
continuation.resume(returning: oauthToken)
private func handleKakaoLoginResult(oauthToken: OAuthToken?, error: Error?) {
if let error = error {
print(error)
} else if let accessToken = oauthToken?.accessToken {
Task {
do {
let isNewUser = try await self.getSocialLoginAPI(accessToken: accessToken)?.data?.isNewUser ?? false
let nickname = try await self.getSocialLoginAPI(accessToken: accessToken)?.data?.nickName ?? ""

if !isNewUser && !nickname.isEmpty {
self.userInfoPublisher.send(false)
} else {
self.userInfoPublisher.send(true)
}
} catch {
print(error)
}
}
}
}

private func getSocialLoginAPI(oauthToken: OAuthToken) async throws -> BaseResponse<SocialLoginResponseDTO>? {
let accessToken = oauthToken.accessToken
}

extension LoginViewModel {
private func getSocialLoginAPI(accessToken: String) async throws -> BaseResponse<SocialLoginResponseDTO>? {
do {
let data: BaseResponse<SocialLoginResponseDTO>? = try await self.networkProvider.donNetwork(
type: .post,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

import SnapKit

final class MyPageAccountInfoViewController: UIViewController {
final class MyPageAccountInfoViewController: UIViewController, UIGestureRecognizerDelegate {

// MARK: - Properties

Choose a reason for hiding this comment

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

주어진 코드 패치의 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험성과/또는 개선 제안 사항을 언급하겠습니다:

  • UIGestureRecognizerDelegate 프로토콜을 추가하여 MyPageAccountInfoViewController가 제스처 인식자(delegate)를 처리할 수 있도록 했습니다.
  • 주석인 // MARK: - Properties은 현재 존재하지 않아 추가되어야 합니다.
  • 다른 부분에 대한 리뷰 또는 수정이 없으므로 해당 부분에서는 문제가 없습니다.

지금까지 코드 리뷰였습니다. 추가적인 정보나 질문이 있다면 알려주세요!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

import SnapKit

final class MyPageEditProfileViewController: UIViewController {
final class MyPageEditProfileViewController: UIViewController, UIGestureRecognizerDelegate {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ extension MyPageViewController {
self.view.backgroundColor = .donBlack
self.tabBarController?.tabBar.isTranslucent = true
self.navigationController?.navigationBar.backgroundColor = .donBlack

self.navigationController?.navigationBar.barTintColor = .donBlack

let image = ImageLiterals.MyPage.icnMenu
let renderedImage = image.withRenderingMode(.alwaysOriginal)
let hambergerButton = UIBarButtonItem(image: renderedImage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ final class OnboardingEndingViewController: UIViewController {
private var cancelBag = CancelBag()
private let viewModel: OnboardingEndingViewModel

private lazy var startButtonTapped = self.originView.startButton.publisher(for: .touchUpInside).map { _
in saveUserData(UserInfo(isSocialLogined:
loadUserData()?.isSocialLogined ?? true,
isFirstUser: false,
isJoinedApp: true,
isOnboardingFinished: true,
userNickname: loadUserData()?.userNickname ?? ""))
}.eraseToAnyPublisher()
private lazy var startButtonTapped = self.originView.startButton.publisher(for: .touchUpInside).map { _ in }.eraseToAnyPublisher()
private lazy var skipButtonTapped = self.originView.laterButton.publisher(for: .touchUpInside).map { _ in }.eraseToAnyPublisher()
private lazy var backButtonTapped = self.originView.backButton.publisher(for: .touchUpInside).map { _ in }.eraseToAnyPublisher()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,27 @@ final class OnboardingEndingViewModel: ViewModelType {
.sink { _ in
// 온보딩 완료 서버통신
// 서버통신 완료되면 신호
saveUserData(UserInfo(isSocialLogined:
loadUserData()?.isSocialLogined ?? true,
isFirstUser: false,
isJoinedApp: true,
isOnboardingFinished: true,
userNickname: loadUserData()?.userNickname ?? ""))
publisher.send("start")

}
.store(in: self.cancelBag)

input.skipButtonTapped
.sink { _ in
// 이때는 서버통신 X
publisher.send("skip")
saveUserData(UserInfo(isSocialLogined:
loadUserData()?.isSocialLogined ?? true,
isFirstUser: false,
isJoinedApp: true,
isOnboardingFinished: true,
userNickname: loadUserData()?.userNickname ?? ""))
}
.store(in: self.cancelBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

final class PostViewController: UIViewController {
final class PostViewController: UIViewController, UIGestureRecognizerDelegate {

// MARK: - Properties
var tabBarHeight: CGFloat = 0
Expand Down