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-308] 운동 세션 중 소켓 버그와 디자인 일부 수정 #325

Merged
merged 6 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 @@ -22,9 +22,8 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window = UIWindow(windowScene: windowScene)
let navigationController = UINavigationController()
window?.rootViewController = navigationController
let coordinator = SignUpFeatureCoordinator(navigationController: navigationController, newUserInformation: NewUserInformation(mappedUserID: "", provider: .apple), isMockEnvironment: true)
// let coordinator = AppCoordinator(navigationController: navigationController)
// coordinating = coordinator
let coordinator = AppCoordinator(navigationController: navigationController)
coordinating = coordinator
coordinator.start()
window?.makeKeyAndVisible()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class AppCoordinator: AppCoordinating {
}

func start() {
showTabBarFlow()
showSplashFlow()
}

private func showSplashFlow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public final class MockWebSocketTask<DataModel: Codable>: WebSocketTaskProtocol

public func send(_ message: URLSessionWebSocketTask.Message) async throws {
switch message {
case let .data(data):
let socketFrame = try jsonDecoder.decode(WebSocketFrame<DataModel>.self, from: data)
let jsonData = try jsonEncoder.encode(socketFrame.data)
case let .data(jsonData):
guard let jsonString = String(data: jsonData, encoding: .utf8) else {
throw MockWebSocketError.stringConversionFailed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public struct TNSocketProvider<EndPoint: TNEndPoint>: TNSocketProvidable {

// MARK: - WebSocketFrame

struct WebSocketFrame<T: Codable>: Codable {
let event: String
let data: T
public struct WebSocketFrame<T: Codable>: Codable {
public let event: String
public let data: T

init(event: String = "workout_session", data: T) {
self.event = event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class SessionWebSocketProtocolTests: XCTestCase {
return
}

let receivedModel = try JSONDecoder().decode(TestModel.self, from: jsonData)
XCTAssertEqual(receivedModel, testModel, "Received model does not match sent model")
let receivedModel = try JSONDecoder().decode(WebSocketFrame<TestModel>.self, from: jsonData)
XCTAssertEqual(receivedModel.data, testModel, "Received model does not match sent model")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct WorkoutSocketRepository {
Log.make().debug("StringToWorkoutRealTimeModel에서 Decode에러 ")
throw WorkoutSocketRepositoryError.invalidStringForConversion
}
guard let workoutSessionModel = try? jsonDecoder.decode(WorkoutSession.self, from: jsonData) else {
guard let workoutSessionModel = try? jsonDecoder.decode(WebSocketFrame<WorkoutRealTimeModel>.self, from: jsonData) else {
Log.make().debug("StringToWorkoutRealTimeModel에서 Decode에러 ")
throw WorkoutSocketRepositoryError.invalidStringForConversion
}
Expand All @@ -56,7 +56,7 @@ struct WorkoutSocketRepository {
health: .init(
distance: workoutSessionModel.data.health.distance,
calories: workoutSessionModel.data.health.calories,
heartRate: nil
heartRate: workoutSessionModel.data.health.heartRate
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,6 @@

import Foundation

// MARK: - WorkoutSession

/// 소켓을 통해 받은 데이터 형식 입니다.
struct WorkoutSession: Codable {
let event: String
let data: SessionData
}

// MARK: - SessionData

struct SessionData: Codable {
let nickname: String
let health: HealthData
let id: String
let roomID: String

enum CodingKeys: String, CodingKey {
case nickname
case health
case id
case roomID = "roomId"
}
}

// MARK: - HealthData

struct HealthData: Codable {
let calories: Double
let distance: Double
}

// MARK: - WorkoutRealTimeModel

/// 운동 데이터를 송수신하는 모델입니다. 소켓 통신 시 사용합니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ extension WorkoutEnvironmentSetupViewModel: WorkoutEnvironmentSetupViewModelRepr
coordinator?.finish(
workoutSessionComponents: .init(
participants: [sessionPeerTypeOfMe],
startDate: .now + 3,
startDate: .now + 6,
roomID: "",
id: "",
workoutTypeCode: workoutSetting.workoutType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ extension WorkoutPeerRandomMatchingViewModel: WorkoutPeerRandomMatchingViewModel
else {
return
}

let peers = peersResponse.map { SessionPeerType(nickname: $0.nickname, id: $0.publicID, profileImageURL: URL(string: $0.profileImage)) }
let sessionPeerTypeOfMe = SessionPeerType(
nickname: userInformationUseCase.userNickName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public final class WorkoutSessionViewController: UIViewController {
self.viewModel = viewModel
for participant in dependency.participants {
Log.make().debug("사람 id는 \(participant.id), nickName: \(participant.nickname)")
userInfoByID[participant.id] = participant
realTimeModelByID[participant.id] = .init(distance: 0, calories: 0, heartRate: 0)
userInfoByID[participant.nickname] = participant
realTimeModelByID[participant.nickname] = .init(distance: 0, calories: 0, heartRate: 0)
}

super.init(nibName: nil, bundle: nil)
Expand Down Expand Up @@ -131,10 +131,10 @@ public final class WorkoutSessionViewController: UIViewController {
self?.healthData = myHealthForm
case let .fetchParticipantsIncludedMySelf(model):
Log.make().debug("\(model)")
self?.realTimeModelByID[model.id] = model.health
self?.realTimeModelByID[model.nickname] = model.health
var snapshot = self?.participantsDataSource?.snapshot()

snapshot?.reconfigureItems([model.id])
snapshot?.reconfigureItems([model.nickname])
if let snapshot {
let temp = snapshot.itemIdentifiers
Log.make().debug("현재 snpahot의 아이템은 다음과 같습니다. \(temp)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ final class WorkoutSummaryCardView: UIView {
// 지도 설정
configureMapPolyline(with: model.locations)

distanceItemView.configure(withTitle: "거리", value: "\(model.distance)")
caloriesItemView.configure(withTitle: "칼로리", value: "\(model.calorie)")
distanceItemView.configure(withTitle: "거리", value: "\(model.distance)m")
caloriesItemView.configure(withTitle: "칼로리", value: "\(model.calorie)kcal")

averageHeartRateItemView.configure(withTitle: "Avg.HR", value: "\(model.averageHeartRate.flatMap(String.init) ?? "-")")
minimumHeartRateItemView.configure(withTitle: "Min.HR", value: "\(model.minimumHeartRate.flatMap(String.init) ?? "-")")
maximumHeartRateItemView.configure(withTitle: "Max.HR", value: "\(model.maximumHeartRate.flatMap(String.init) ?? "-")")
averageHeartRateItemView.configure(withTitle: "Avg.HR", value: "\(model.averageHeartRate.flatMap(String.init) ?? "-")bpm")
minimumHeartRateItemView.configure(withTitle: "Min.HR", value: "\(model.minimumHeartRate.flatMap(String.init) ?? "-")bpm")
maximumHeartRateItemView.configure(withTitle: "Max.HR", value: "\(model.maximumHeartRate.flatMap(String.init) ?? "-")bpm")
}

private func createLocations(from locations: [LocationModel]) -> [CLLocation] {
Expand Down
Loading