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

[iOS] 여정 기록 중 지도 위에 Spot 등록 로직 구현 #289

Merged
merged 6 commits into from
Dec 10, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public final class MapViewController: UIViewController {
for: annotation)
}

public func addAnnotations(with journeys: [Journey]) {
private func addAnnotations(with journeys: [Journey]) {
let datas = journeys.flatMap { journey in
journey.spots.map { (location: journey.title, spot: $0) }
}
Expand Down Expand Up @@ -215,6 +215,24 @@ public final class MapViewController: UIViewController {
self.mapView.addAnnotation(annotation)
}

public func addSpotInRecording(spot: Spot) {
Task {

let imageFetcher = MSImageFetcher.shared
guard let photoData = await imageFetcher.fetchImage(from: spot.photoURL,
forKey: spot.photoURL.paath()) else {
throw ImageFetchError.imageFetchFailed
}

let coordinate = CLLocationCoordinate2D(latitude: spot.coordinate.latitude,
longitude: spot.coordinate.longitude)

self.addAnnotation(title: "",
coordinate: coordinate,
photoData: photoData)
}
}

// MARK: - Functions: Polyline

private func drawPolyLinesToMap(with journeys: [Journey]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public protocol SpotNavigationDelegate: AnyObject {
func presentSpotSave(using image: UIImage, coordinate: Coordinate)
func dismissToSpot()
func popToHome()
func popToHomeWithSpot(spot: Spot)

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by 전민건 on 11/22/23.
//

import Combine
import UIKit

import MSData
Expand Down Expand Up @@ -62,6 +63,8 @@ public final class SpotSaveViewController: UIViewController {
private let viewModel: SpotSaveViewModel
private let image: UIImage

private var cancellables: Set<AnyCancellable> = []

// MARK: - UI Components

private let imageView: UIImageView = {
Expand Down Expand Up @@ -96,6 +99,7 @@ public final class SpotSaveViewController: UIViewController {
public override func viewDidLoad() {
super.viewDidLoad()
self.configure()
self.bind()
}

// MARK: - Configure
Expand All @@ -106,6 +110,18 @@ public final class SpotSaveViewController: UIViewController {
self.configureAction()
self.configureState()
}

// MARK: - Combine Binding

private func bind() {
self.viewModel.state.spot
.receive(on: DispatchQueue.main)
.sink { [weak self] spot in
guard let spot = spot else { return }
self?.navigationDelegate?.popToHomeWithSpot(spot: spot)
}
.store(in: &self.cancellables)
}

// MARK: - UI Components: Layout

Expand Down Expand Up @@ -250,7 +266,6 @@ public final class SpotSaveViewController: UIViewController {
return
}
self.viewModel.trigger(.startUploadSpot, using: jpegData)
self.navigationDelegate?.popToHome()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by 전민건 on 11/29/23.
//

import Foundation
import Combine
import Foundation

import MSData
import MSDomain
Expand All @@ -18,6 +18,10 @@ public final class SpotSaveViewModel {
case startUploadSpot
}

public struct State {
public var spot = PassthroughSubject<Spot?, Never>()
}

// MARK: - Properties

private let journeyRepository: JourneyRepository
Expand All @@ -27,6 +31,8 @@ public final class SpotSaveViewModel {

private let coordinate: Coordinate

public var state = State()

// MARK: - Initializer

public init(journeyRepository: JourneyRepository,
Expand Down Expand Up @@ -58,6 +64,7 @@ internal extension SpotSaveViewModel {
let result = await self.spotRepository.upload(spot: spot)
switch result {
case .success(let spot):
self.state.spot.send(spot)
MSLogger.make(category: .network).debug("성공적으로 업로드되었습니다: \(spot)")
case .failure(let error):
MSLogger.make(category: .network).error("\(error): 업로드에 실패하였습니다.")
Expand Down
15 changes: 15 additions & 0 deletions iOS/MusicSpot/MusicSpot/MSCoordinator/HomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import NavigateMap
protocol HomeCoordinatorDelegate: AnyObject {

func popToHome(from coordinator: Coordinator)
func popToHomeWithSpot(from coordinator: Coordinator, spot: Spot)

}

Expand Down Expand Up @@ -104,6 +105,7 @@ extension HomeCoordinator: JourneyListNavigationDelegate {

extension HomeCoordinator: HomeCoordinatorDelegate {


func popToHome(from coordinator: Coordinator) {
guard let homeViewController = self.navigationController.viewControllers.first(where: { viewController in
viewController is HomeViewController
Expand All @@ -116,4 +118,17 @@ extension HomeCoordinator: HomeCoordinatorDelegate {
}
}

func popToHomeWithSpot(from coordinator: Coordinator, spot: Spot) {
guard let homeViewController = self.navigationController.viewControllers.first(where: { viewController in
viewController is HomeViewController
}) as? HomeBottomSheetViewController else {
return
}
homeViewController.contentViewController.addSpotInRecording(spot: spot)
self.navigationController.dismiss(animated: true) { [weak self] in
self?.navigationController.popToViewController(homeViewController, animated: true)
self?.childCoordinators.removeAll()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit

import MSData
import MSDomain
import RewindJourney

final class RewindJourneyCoordinator: Coordinator {
Expand Down Expand Up @@ -51,6 +52,10 @@ extension RewindJourneyCoordinator: RewindJourneyNavigationDelegate {
// MARK: - HomeMap Coordinator

extension RewindJourneyCoordinator: HomeCoordinatorDelegate {
func popToHomeWithSpot(from coordinator: Coordinator, spot: Spot) {
// 미사용 함수
}

Copy link
Member

Choose a reason for hiding this comment

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

이건 구현 예정이신가요?


func popToHome(from coordinator: Coordinator) {
self.childCoordinators.removeAll()
Expand Down
10 changes: 10 additions & 0 deletions iOS/MusicSpot/MusicSpot/MSCoordinator/SpotCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ extension SpotCoordinator: SpotNavigationDelegate {
self.popToHome(from: self)
}

func popToHomeWithSpot(spot: Spot) {
self.popToHomeWithSpot(from: self, spot: spot)
}

}

// MARK: - HomeMap Coordinator
Expand All @@ -92,4 +96,10 @@ extension SpotCoordinator: HomeCoordinatorDelegate {
self.delegate?.popToHome(from: self)
}

func popToHomeWithSpot(from coordinator: Coordinator, spot: Spot) {
self.childCoordinators.removeAll()
self.navigationController.popViewController(animated: true)
self.delegate?.popToHomeWithSpot(from: self, spot: spot)
}

}