feat(character-detail) 대화하기 버튼 액션 추가
- 채팅방 생성 API 호출
This commit is contained in:
		@@ -163,4 +163,6 @@ enum AppStep {
 | 
				
			|||||||
    case audition
 | 
					    case audition
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    case characterDetail(characterId: Int)
 | 
					    case characterDetail(characterId: Int)
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    case chatRoom(id: Int)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -340,7 +340,12 @@ extension CharacterDetailView {
 | 
				
			|||||||
            .cornerRadius(16)
 | 
					            .cornerRadius(16)
 | 
				
			||||||
            .padding(.horizontal, 24)
 | 
					            .padding(.horizontal, 24)
 | 
				
			||||||
            .onTapGesture {
 | 
					            .onTapGesture {
 | 
				
			||||||
                // TODO: 대화하기 액션
 | 
					                viewModel.createChatRoom {
 | 
				
			||||||
 | 
					                    AppState.shared
 | 
				
			||||||
 | 
					                        .setAppStep(
 | 
				
			||||||
 | 
					                            step: .chatRoom(id: $0)
 | 
				
			||||||
 | 
					                        )
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,4 +67,44 @@ final class CharacterDetailViewModel: ObservableObject {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            .store(in: &subscription)
 | 
					            .store(in: &subscription)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    func createChatRoom(onSuccess: @escaping (Int) -> Void) {
 | 
				
			||||||
 | 
					        isLoading = true
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        repository.createChatRoom(characterId: characterId)
 | 
				
			||||||
 | 
					            .receive(on: DispatchQueue.main)
 | 
				
			||||||
 | 
					            .sink { result in
 | 
				
			||||||
 | 
					                switch result {
 | 
				
			||||||
 | 
					                case .finished:
 | 
				
			||||||
 | 
					                    DEBUG_LOG("finish")
 | 
				
			||||||
 | 
					                case .failure(let error):
 | 
				
			||||||
 | 
					                    ERROR_LOG(error.localizedDescription)
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } receiveValue: { [weak self] response in
 | 
				
			||||||
 | 
					                let responseData = response.data
 | 
				
			||||||
 | 
					                self?.isLoading = false
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                do {
 | 
				
			||||||
 | 
					                    let jsonDecoder = JSONDecoder()
 | 
				
			||||||
 | 
					                    let decoded = try jsonDecoder.decode(ApiResponse<CreateChatRoomResponse>.self, from: responseData)
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                    if let data = decoded.data, decoded.success {
 | 
				
			||||||
 | 
					                        onSuccess(data.chatRoomId)
 | 
				
			||||||
 | 
					                    } else {
 | 
				
			||||||
 | 
					                        if let message = decoded.message {
 | 
				
			||||||
 | 
					                            self?.errorMessage = message
 | 
				
			||||||
 | 
					                        } else {
 | 
				
			||||||
 | 
					                            self?.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        
 | 
				
			||||||
 | 
					                        self?.isShowPopup = true
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                } catch {
 | 
				
			||||||
 | 
					                    ERROR_LOG(String(describing: error))
 | 
				
			||||||
 | 
					                    self?.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
 | 
				
			||||||
 | 
					                    self?.isShowPopup = true
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            .store(in: &subscription)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,8 @@ struct ChatRoomView: View {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    @AppStorage("can") private var can: Int = UserDefaults.int(forKey: .can)
 | 
					    @AppStorage("can") private var can: Int = UserDefaults.int(forKey: .can)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    let roomId: Int
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    var body: some View {
 | 
					    var body: some View {
 | 
				
			||||||
        BaseView(isLoading: $viewModel.isLoading) {
 | 
					        BaseView(isLoading: $viewModel.isLoading) {
 | 
				
			||||||
            ChatRoomBgView()
 | 
					            ChatRoomBgView()
 | 
				
			||||||
@@ -207,5 +209,5 @@ struct ChatRoomBgView: View {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Preview {
 | 
					#Preview {
 | 
				
			||||||
    ChatRoomView()
 | 
					    ChatRoomView(roomId: 0)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,5 +6,5 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct CreateChatRoomResponse: Decodable {
 | 
					struct CreateChatRoomResponse: Decodable {
 | 
				
			||||||
    let chatRoomId: Int64
 | 
					    let chatRoomId: Int
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -251,6 +251,9 @@ struct ContentView: View {
 | 
				
			|||||||
            case .characterDetail(let characterId):
 | 
					            case .characterDetail(let characterId):
 | 
				
			||||||
                CharacterDetailView(characterId: characterId)
 | 
					                CharacterDetailView(characterId: characterId)
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
 | 
					            case .chatRoom(let id):
 | 
				
			||||||
 | 
					                ChatRoomView(roomId: id)
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                EmptyView()
 | 
					                EmptyView()
 | 
				
			||||||
                    .frame(width: 0, height: 0, alignment: .topLeading)
 | 
					                    .frame(width: 0, height: 0, alignment: .topLeading)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user