Skip to content

Commit

Permalink
Merge branch 'Dev' of github.com:DDD-Community/PINGPONG-IOS into Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Byeonjinha committed Dec 4, 2023
2 parents 78f8890 + fb4d38f commit 6e2d73d
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 47 deletions.
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public class AuthorizationViewModel: ObservableObject {
"uid" : result?.user.uid ?? ""]
Firestore.firestore().collection("users")
.document(result?.user.uid ?? "")
.setData(data) { data in
debugPrint("DEBUG : Upload user data : \(String(describing: data))")
}
// .setData(data) { data in
// debugPrint("DEBUG : Upload user data : \(String(describing: data))")
// }
print("로그인 uid", self.uid, APIHeaderManger.shared.firebaseUid)
}
}
Expand Down Expand Up @@ -327,7 +327,7 @@ public class AuthorizationViewModel: ObservableObject {

public func loginWithEmail(
email: String,
succesCompletion : @escaping () -> Void,
succesCompletion : @escaping (SignUPModel) -> Void,
failLoginCompletion: @escaping () -> Void
) async {
if let cancellable = loginEmailCancellable {
Expand All @@ -351,8 +351,9 @@ public class AuthorizationViewModel: ObservableObject {
self?.signupToViewModel(model)
self?.userid = model.data?.id ?? .zero
self?.userUid = model.data?.uid ?? ""

print("로그인 성공", model)
succesCompletion()
succesCompletion(model)
} else {
self?.signupToViewModel(model)
self?.userid = model.data?.id ?? .zero
Expand All @@ -367,12 +368,14 @@ public class AuthorizationViewModel: ObservableObject {
self.commonCodeModel = list
}

public func randomNameRequest(commCdTpCd: CommonType) async {
public func randomNameRequest(
commCdTpCd: CommonType,
completion: @escaping (CommonCdModel) -> Void) async {
if let cancellable = randomNameCancellable {
cancellable.cancel()
}

let provider = MoyaProvider<SearchService>(plugins: [MoyaLoggingPlugin()])
let provider = MoyaProvider<CommonService>(plugins: [MoyaLoggingPlugin()])
randomNameCancellable = provider.requestWithProgressPublisher(.searchCommCode(commCdTpCd: commCdTpCd.description))
.compactMap { $0.response?.data }
.receive(on: DispatchQueue.main)
Expand All @@ -388,13 +391,20 @@ public class AuthorizationViewModel: ObservableObject {
if model.status == NetworkCode.success.status {
self?.commCodeToViewModel(model)

if let randomCommNm = model.data.commCds.randomElement()?.commNm {
if let randomCommNm = model.data?.commCds.randomElement()?.commNm {
self?.randomAuthNickName = randomCommNm
Log.network("랜덤 이름", randomCommNm)
completion(model)
}
Log.network("랜덤 이름", model)
} else {
self?.commCodeToViewModel(model)
Log.network("유저 코드", model)

if let randomCommNm = model.data?.commCds.randomElement()?.commNm {
self?.randomAuthNickName = randomCommNm
Log.network("랜덤 이름", randomCommNm)
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Foundation

public struct CommonCdModel: Codable {
public let status: Int
public let data: CommonCdResponseModel
public let data: CommonCdResponseModel?
public let message: String?

public init(status: Int, data: CommonCdResponseModel, message: String?) {
public init(status: Int, data: CommonCdResponseModel?, message: String?) {
self.status = status
self.data = data
self.message = message
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// CommonService.swift
// Service
//
// Created by 서원지 on 12/4/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Foundation
import Moya
import API

public enum CommonService {
case searchCommCode(commCdTpCd: String)
}


extension CommonService: NoAuthBaseTargetType {
public var path: String {
switch self {
case .searchCommCode(let commCdTpCd):
return "\(PingPongAPISearch.searchCommonCode)\(commCdTpCd)"
}
}

public var method: Moya.Method {
switch self {
case .searchCommCode:
return .get
}
}

public var task: Moya.Task {
switch self {
case .searchCommCode(_):
let parameters : [String : Any] = [
:
]

return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ struct APIConstants{
extension APIConstants {
static var baseHeader: Dictionary<String, String> {
[ contentType : APIHeaderManger.shared.contentType,
authorization : "Bearer \(APIHeaderManger.shared.firebaseUid)"
authorization : "Bearer \(APIHeaderManger.shared.firebaseUid)"
]
}

static var noAuhtHeader: Dictionary<String, String> {
[ contentType : APIHeaderManger.shared.contentType
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// NoAuthBaseTargetType.swift
// Service
//
// Created by 서원지 on 12/4/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Foundation
import Moya
import API

public protocol NoAuthBaseTargetType: TargetType {}


extension NoAuthBaseTargetType {
public var baseURL: URL {
return URL(string: PingPongAPI.baseURL)!
}

public var headers: [String : String]? {
return APIConstants.noAuhtHeader
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ extension SearchService: BaseTargetType {

return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)

case .searchCommCode(let commCdTpCd):
case .searchCommCode(_):
let parameters : [String : Any] = [
"commCdTpCd": commCdTpCd
// "commCdTpCd": commCdTpCd
:

]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public struct ChoiceBreadView: View {
let sortedCommCds = commonData.commCds.filter { $0.commCD != "other" && $0.commCD != "proverb" && $0.commCD != "unknown"}
ForEach(sortedCommCds, id: \.self) { item in

let source: Source = Source(rawValue: item.commCD) ?? .anime
let source: Source = Source(rawValue: item.commCD ?? "") ?? .anime

VStack {
Circle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public struct ChoiceIngredentView: View {

ForEach(commonData.commCds, id: \.self) { item in

let flavor: Flavor = Flavor(rawValue: item.commCD) ?? .light
let flavor: Flavor = Flavor(rawValue: item.commCD ?? "") ?? .light

VStack {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public struct ChoiceToppingView: View {

ForEach(commonData.commCds, id: \.self) { item in

let mood: Mood = Mood(rawValue: item.commCD) ?? .motivation
let mood: Mood = Mood(rawValue: item.commCD ?? "") ?? .motivation

VStack {
Circle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ public struct HomeView: View {
}
.navigationBarHidden(true)
.task {
await authViewModel.loginWithEmail(email: authViewModel.userEmail, succesCompletion: {}, failLoginCompletion: {})
await authViewModel.loginWithEmail(email: authViewModel.userEmail, succesCompletion: { model in
authViewModel.userNickName = model.data?.nickname ?? ""
authViewModel.userid = model.data?.id ?? .zero
}, failLoginCompletion: {})
authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)")

}

.onAppear {
authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)")
if !homeViewModel.isOn.isEmpty {
homeViewModel.randomQuoteRequest(userID: "\(authViewModel.userid)") {
for quoteContent in homeViewModel.homeRandomQuoteModel?.data?.content ?? [] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ public struct SelectCategoryView: View {

ForEach(sortedCommCds, id: \.self) { item in
VStack {
let favoirte = Source(rawValue: item.commCD)
let favoirte = Source(rawValue: item.commCD ?? "")

if viewModel.selectedFavorite.contains(Source(rawValue: (favoirte ?? .anime).rawValue) ?? .anime){
Circle()
.frame(width: 96, height: 96)
.foregroundColor(.basicGray3)
.overlay(
Image(assetName: item.commCD)
Image(assetName: item.commCD ?? "")
)
} else {
Circle()
Expand All @@ -137,17 +137,17 @@ public struct SelectCategoryView: View {
)
}

Text(item.commNm)
Text(item.commNm ?? "")
.pretendardFont(family: .SemiBold, size: 14)
}
.onTapGesture {

let source = Source(rawValue: item.commCD)
let source = Source(rawValue: item.commCD ?? "")
if let favorite = source {
self.viewModel.appendAndPopFavorite(favorite: favorite)

}
self.viewModel.selectedFavoriteCategory = item.commCD
self.viewModel.selectedFavoriteCategory = item.commCD ?? ""


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public struct LoginJobSettingView: View {
LazyVGrid(columns: columns, spacing: 10) {
let searchUserJob = viewModel.onBoardingSearchUserModel?.data?.filter{$0.commCDTpID == 4}
if let firstSearchUserJob = searchUserJob?.first {
let sortedCommCds = firstSearchUserJob.commCds?.sorted(by: { $0.commCDID < $1.commCDID }) ?? []
let sortedCommCds = firstSearchUserJob.commCds?.sorted(by: { $0.commCDID ?? .zero < $1.commCDID ?? .zero }) ?? []
ForEach(sortedCommCds, id: \.self) { commCDItem in
VStack {
if viewModel.selectedJob == commCDItem.commCD {
Expand All @@ -93,23 +93,23 @@ public struct LoginJobSettingView: View {
.frame(width: 96, height: 96)
.foregroundColor(.primaryOrangeOpacity40)
.overlay(
Image(assetName: commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD)
Image(assetName: (commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD) ?? "")
)
)
} else {
Circle()
.frame(width: 96, height: 96)
.foregroundColor(.basicGray3)
.overlay(
Image(assetName: commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD )
Image(assetName: (commCDItem.commCD == "OTHER" ? "\(commCDItem.commCD)S" : commCDItem.commCD) ?? "" )
)
}
Text(commCDItem.commNm)
Text(commCDItem.commNm ?? "")
.pretendardFont(family: .SemiBold, size: 14)
}
.onTapGesture {
self.viewModel.selectedJob = commCDItem.commCD
self.viewModel.selectJobCode = commCDItem.commCDID
self.viewModel.selectJobCode = commCDItem.commCDID ?? .zero
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ public struct OnBoardingLoginView: View {
}
authViewModel.appleLogin(credential: credential)

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.8) {
Task {
await authViewModel.loginWithEmail(
email: authViewModel.userEmail,
succesCompletion: {

succesCompletion: { model in
commonViewViewModel.isLogin = true
commonViewViewModel.isLoginCheck = true
authViewModel.userid = model.data?.id ?? .zero
authViewModel.userNickName = model.data?.nickname ?? ""

}, failLoginCompletion: {
appState.signUPFaillPOPUP.toggle()
Expand All @@ -162,8 +163,10 @@ public struct OnBoardingLoginView: View {
}

case .failure(let error):
appState.signUPFaillPOPUP.toggle()
presentationMode.wrappedValue.dismiss()
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
appState.signUPFaillPOPUP.toggle()
presentationMode.wrappedValue.dismiss()
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct CompletOnBoardingView: View {

.task {
authViewModel.searchUserIdRequest(uid: "\(authViewModel.userid)")
await authViewModel.randomNameRequest(commCdTpCd: .userDesc)
await authViewModel.randomNameRequest(commCdTpCd: .userDesc, completion: {_ in })
}
}

Expand Down
Loading

0 comments on commit 6e2d73d

Please sign in to comment.