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

Create Repository layers #32

Closed
wants to merge 4 commits into from
Closed
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
22 changes: 21 additions & 1 deletion iOS/Pog/Pog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
D3CA088028688CA9006147BB /* LocationManager+Env.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3CA087F28688CA9006147BB /* LocationManager+Env.swift */; };
D3CA088228688D56006147BB /* PlaceManager+Env.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3CA088128688D56006147BB /* PlaceManager+Env.swift */; };
D3CA088828689FD4006147BB /* Pog.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = D3CA088328689FD4006147BB /* Pog.xcdatamodeld */; };
D3D0F9DE28748E3800AE9033 /* PlaceLogRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D0F9DD28748E3800AE9033 /* PlaceLogRepository.swift */; };
D3D0F9E028748E4700AE9033 /* LocationSettingsRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D0F9DF28748E4700AE9033 /* LocationSettingsRepository.swift */; };
D3D0F9E228748E7500AE9033 /* InterestingPlaceRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3D0F9E128748E7500AE9033 /* InterestingPlaceRepository.swift */; };
D3E0AACA28408CC300597C1A /* PlaceLogModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3E0AAC928408CC300597C1A /* PlaceLogModel.swift */; };
D3E0AACC2840957800597C1A /* MapViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3E0AACB2840957800597C1A /* MapViewRepresentable.swift */; };
D3E0AACE2840AB7D00597C1A /* CLLocationCoordinate2D.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3E0AACD2840AB7D00597C1A /* CLLocationCoordinate2D.swift */; };
Expand Down Expand Up @@ -124,6 +127,9 @@
D3CA088528689FD4006147BB /* Pog.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Pog.xcdatamodel; sourceTree = "<group>"; };
D3CA088628689FD4006147BB /* Pog 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Pog 2.xcdatamodel"; sourceTree = "<group>"; };
D3CA088728689FD4006147BB /* Pog 4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Pog 4.xcdatamodel"; sourceTree = "<group>"; };
D3D0F9DD28748E3800AE9033 /* PlaceLogRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceLogRepository.swift; sourceTree = "<group>"; };
D3D0F9DF28748E4700AE9033 /* LocationSettingsRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationSettingsRepository.swift; sourceTree = "<group>"; };
D3D0F9E128748E7500AE9033 /* InterestingPlaceRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterestingPlaceRepository.swift; sourceTree = "<group>"; };
D3E0AAC928408CC300597C1A /* PlaceLogModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceLogModel.swift; sourceTree = "<group>"; };
D3E0AACB2840957800597C1A /* MapViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewRepresentable.swift; sourceTree = "<group>"; };
D3E0AACD2840AB7D00597C1A /* CLLocationCoordinate2D.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLLocationCoordinate2D.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -236,7 +242,6 @@
D3BFA9322833796D00606CD4 /* Pog */ = {
isa = PBXGroup;
children = (
D33BFEDC287025B8007C7CA9 /* Networking */,
D3BFA9902833CC6700606CD4 /* Pog.entitlements */,
D31F91B9285CE71300B55DCE /* GoogleService-Info-Debug.plist */,
D31F91C0285CEA8300B55DCE /* GoogleService-Info-Release.plist */,
Expand All @@ -247,9 +252,11 @@
D3F794BD2865ED2000B84905 /* Env */,
D3BFA96328337C4D00606CD4 /* Manager */,
D3BFA96028337BC100606CD4 /* Models */,
D33BFEDC287025B8007C7CA9 /* Networking */,
D3BFA95D28337B0700606CD4 /* Pages */,
D3CA088328689FD4006147BB /* Pog.xcdatamodeld */,
D3BFA9392833796F00606CD4 /* Preview Content */,
D3D0F9DC28748DFF00AE9033 /* Repositories */,
D3A9A37C283A4C74006F3CE6 /* Store */,
D3BFA9882833C47B00606CD4 /* Utils */,
);
Expand Down Expand Up @@ -344,6 +351,16 @@
path = Reposnses;
sourceTree = "<group>";
};
D3D0F9DC28748DFF00AE9033 /* Repositories */ = {
isa = PBXGroup;
children = (
D3D0F9DD28748E3800AE9033 /* PlaceLogRepository.swift */,
D3D0F9DF28748E4700AE9033 /* LocationSettingsRepository.swift */,
D3D0F9E128748E7500AE9033 /* InterestingPlaceRepository.swift */,
);
path = Repositories;
sourceTree = "<group>";
};
D3F794BD2865ED2000B84905 /* Env */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -549,7 +566,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D3D0F9E228748E7500AE9033 /* InterestingPlaceRepository.swift in Sources */,
D3D0F9DE28748E3800AE9033 /* PlaceLogRepository.swift in Sources */,
D306F936286F0A83006293E9 /* InterestingPlace+CoreDataClass.swift in Sources */,
D3D0F9E028748E4700AE9033 /* LocationSettingsRepository.swift in Sources */,
D306F938286F0A83006293E9 /* LocationSettings+CoreDataClass.swift in Sources */,
D306F944286F188C006293E9 /* PlaceLog+CoreDataProperties.swift in Sources */,
D33BFEDE287025CE007C7CA9 /* APIClient.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions iOS/Pog/Pog/Manager/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public class LocationManagerImpl: NSObject, CLLocationManagerDelegate, LocationM

public func updateLocationManager<V>(keypath: ReferenceWritableKeyPath<CLLocationManager, V>, value: V) {
manager[keyPath: keypath] = value

// Perform side-effects for changes
if keypath == \CLLocationManager.allowsBackgroundLocationUpdates {
if manager.allowsBackgroundLocationUpdates {
manager.startMonitoringSignificantLocationChanges()
} else {
manager.stopMonitoringSignificantLocationChanges()
}
}
}

public func request() {
Expand Down
2 changes: 1 addition & 1 deletion iOS/Pog/Pog/Manager/PlaceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PlaceManagerImpl: NSObject, PlaceManager {
longitudinalMeters: 1500
)
}

public func search(text: String, useGooglePlaces: Bool) async {
if text.isEmpty {
return
Expand Down
38 changes: 38 additions & 0 deletions iOS/Pog/Pog/Repositories/InterestingPlaceRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// InterestingPlaceRepository.swift
// Pog
//
// Created by Fumiya Tanaka on 2022/07/06.
//

import Foundation
import Combine

public protocol InterestingPlaceRepository {
var interestingPlace: AnyPublisher<InterestingPlace, Never> { get }
var error: AnyPublisher<Error, Never> { get }
func update<Value>(keypath: ReferenceWritableKeyPath<LocationSettings, Value>, value: Value)
func reset()
}

public class InterestingPlaceRepositoryImpl {

private let _interestingPlace: CurrentValueSubject<InterestingPlace?, Never> = .init(nil)
private let _error: PassthroughSubject<Error, Never> = .init()
}

extension InterestingPlaceRepositoryImpl: InterestingPlaceRepository {
public var interestingPlace: AnyPublisher<InterestingPlace, Never> {
_interestingPlace.compactMap{ $0 }.eraseToAnyPublisher()
}

public var error: AnyPublisher<Error, Never> {
_error.eraseToAnyPublisher()
}

public func update<Value>(keypath: ReferenceWritableKeyPath<LocationSettings, Value>, value: Value) {
}

public func reset() {
}
}
22 changes: 22 additions & 0 deletions iOS/Pog/Pog/Repositories/LocationSettingsRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// LocationSettingsRepository.swift
// Pog
//
// Created by Fumiya Tanaka on 2022/07/06.
//

import Foundation
import Combine

public protocol LocationSettingsRepository {
var locationSettings: AnyPublisher<LocationSettings, Never> { get }
var error: AnyPublisher<Error, Never> { get }
}

public class LocationSettingsRepositoryImpl {

}

extension LocationSettingsRepositoryImpl {

}
54 changes: 54 additions & 0 deletions iOS/Pog/Pog/Repositories/PlaceLogRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// PlaceLogRepository.swift
// Pog
//
// Created by Fumiya Tanaka on 2022/07/06.
//

import Foundation
import SwiftUI
import Combine

public protocol PlaceLogRepository {
var logs: AnyPublisher<[PlaceLog], Never> { get }
var error: AnyPublisher<Error, Never> { get }
func createNewLog(lat: Double, lng: Double, date: Date)
}

public class PlaceLogRepositoryImpl {
private let _logs: CurrentValueSubject<[PlaceLog], Never> = .init([])
private let _error: PassthroughSubject<Error, Never> = .init()
private let store: Store
private var cancellables: Set<AnyCancellable> = []

public init(store: Store) {
self.store = store
store.logs
.sink {
self._logs.send($0)
}
.store(in: &cancellables)
}
}

extension PlaceLogRepositoryImpl: PlaceLogRepository {
public var logs: AnyPublisher<[PlaceLog], Never> {
_logs.eraseToAnyPublisher()
}

public var error: AnyPublisher<Error, Never> {
_error.eraseToAnyPublisher()
}

public func createNewLog(lat: Double, lng: Double, date: Date) {
let log = PlaceLog(context: store.context)
log.lat = lat
log.lng = lng
log.date = date
do {
try store.context.save()
} catch {
_error.send(error)
}
}
}