Skip to content

Commit

Permalink
Merge pull request #228 from APP-iOS2/refactor/code
Browse files Browse the repository at this point in the history
[Refactor/code] Lint warning , 코드 제거, 폴더 구조 및 컴포넌트 분리
  • Loading branch information
hyeonghwan authored May 7, 2024
2 parents 2eb5b99 + aedd3ab commit b09835f
Show file tree
Hide file tree
Showing 83 changed files with 1,273 additions and 1,231 deletions.
198 changes: 140 additions & 58 deletions Pickle/Pickle.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"originHash" : "182db11c87d1734fe53a6366b674339f70901a93290bd85def29b63e25e34c43",
"pins" : [
{
"identity" : "realm-core",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/realm-core.git",
"state" : {
"revision" : "f8e1a38a4099785af597ab813ae01f9901858b65",
"version" : "13.21.0"
"revision" : "9cf7ef4ad8e2f4c7a519c9a395ca3d253bb87aa8",
"version" : "14.6.2"
}
},
{
Expand All @@ -15,7 +16,7 @@
"location" : "https://github.com/realm/realm-swift.git",
"state" : {
"branch" : "master",
"revision" : "9e1358bebf2c9e12e67c8b78a46f1ac7aff1f4fe"
"revision" : "6f8d5e390139c32b5b27d54a26a0b5f7b5cfe857"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1530"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Pickle/Pickle/Data/Extension/Todo-extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Todo: MappableProtocol {
TodoObject(id: self.id,
content: self.content,
startTime: self.startTime,
targetTime: self.targetTime, //self.targetTime,
targetTime: self.targetTime,
spendTime: self.spendTime,
status: TodoStatusPersisted(rawValue: self.status.value) ?? .ready)

Expand Down
3 changes: 0 additions & 3 deletions Pickle/Pickle/Data/Extension/User-extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ extension User: MappableProtocol {
}

static func mapFromPersistenceObject(_ object: PersistenceType) -> Self {
let list = object.currentPizzaList
//
let pizzas = list.map { value in CurrentPizza.mapFromPersistenceObject(value) }
return User(id: object.id,
nickName: object.nickName,
currentPizzaCount: object.currentPizzaCount,
Expand Down
7 changes: 6 additions & 1 deletion Pickle/Pickle/Data/Model/Mission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ struct BehaviorMission: Mission, Identifiable {
var status3: MissionStatus
var date: Date // 투두 생성 날짜,시간

init(id: String, title: String = "", status: MissionStatus = .ready, status2: MissionStatus = .ready, status3: MissionStatus = .ready, date: Date = Date()) {
init(id: String,
title: String = "",
status: MissionStatus = .ready,
status2: MissionStatus = .ready,
status3: MissionStatus = .ready,
date: Date = Date()) {
self.id = id
self.title = title
self.status = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ final class BehaviorMissionRepository: BaseRepository<BehaviorMissionObject>, Be
return []
}

func create(item: BehaviorMission,_ completion: @escaping (BehaviorMissionObject) -> Void) {
func create(item: BehaviorMission, _ completion: @escaping (BehaviorMissionObject) -> Void) {
let object = item.mapToPersistenceObject()
do {
try super.create(BehaviorMissionObject.self, item: object ,completion: completion)
try super.create(BehaviorMissionObject.self, item: object, completion: completion)
} catch {
Log.error("error occur : \(error)")
}
Expand Down Expand Up @@ -83,7 +83,7 @@ final class BehaviorMissionRepository: BaseRepository<BehaviorMissionObject>, Be

let objectCompletion: ObjectCompletion<BehaviorMissionObject> = { change in
switch change {
case .change(let object, let properties):
case .change(let object, _):
let behavior = BehaviorMission.mapFromPersistenceObject(object)
completion(behavior)
case .error(let error):
Expand Down
17 changes: 9 additions & 8 deletions Pickle/Pickle/Data/Repository/Repositories/Midiator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ struct MissionMediator {

typealias DTO = Mission
typealias Persisted = MissionObject
typealias A = Adpater

private func setRepository(mission: MissionType) {
let missionType = mission.type
if Adpater.type == missionType { return }
else { Adpater.type = missionType }
if Adpater.type == missionType {
return
} else {
Adpater.type = missionType
}

switch missionType {
case .time:
Expand All @@ -41,27 +43,26 @@ struct MissionMediator {

func fetch<T: Persisted>(sorted: Sorted, type: MissionType) async throws -> T {
setRepository(mission: type)
let value = await A.repository?.fetch(sorted: sorted)
let value = await Adpater.repository?.fetch(sorted: sorted)
guard let value = value as? T
else { throw MissionError.castingError }
return value
}

func create<T: Persisted>(type: MissionType, _ completion: @escaping (T) -> Void) {
// TODO: 추후 수정
// A.repository?.create(item: .init()) { value in
// Log.debug("create: \(value)")
// }
}

func add(type: MissionType, value: some Mission) {
setRepository(mission: type)
A.repository?.save(model: value)
Adpater.repository?.save(model: value)
}

func delete<T: DTO>(type: MissionType, value: T) where T: MappableProtocol {
setRepository(mission: type)
if let repo = A.repository {
}
// if let repo = Adpater.repository {
// }
}
}
16 changes: 1 addition & 15 deletions Pickle/Pickle/Data/Repository/Repositories/PizzaRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

import Foundation


protocol PizzaRepositoryProtocol: Dependency {
func fetch(sorted: Sorted, _ completion: @escaping ([Pizza]) -> Void)
func create(pizza: Pizza) async throws -> Pizza
func save(pizza: Pizza) throws
func delete(pizza: Pizza) throws
func deleteAll() throws
func update(pizza: Pizza) throws
}
Expand All @@ -32,7 +30,7 @@ final class PizzaRepository: BaseRepository<PizzaObject>, PizzaRepositoryProtoco
try await withCheckedThrowingContinuation { continuation in
do {
let data = try JSONEncoder().encode(pizza)
try super.create(PizzaObject.self,data: data, completion: { pizzaObject in
try super.create(PizzaObject.self, data: data, completion: { pizzaObject in
let model = Pizza.mapFromPersistenceObject(pizzaObject)
continuation.resume(returning: model)
})
Expand All @@ -50,18 +48,6 @@ final class PizzaRepository: BaseRepository<PizzaObject>, PizzaRepositoryProtoco
throw PersistentedError.saveFailed
}
}

func delete(pizza: Pizza) throws {
let object = pizza.mapToPersistenceObject()
do {
// let fitler: RFilter = .filter({value in value == object.name })

// try super.delete(object: object, id: object.id.stringValue)
} catch {
Log.error("\(error)")
throw PersistentedError.deleteFailed
}
}

func deleteAll() throws {
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ final class TimeMissionRepository: BaseRepository<TimeMissionObject>, TimeReposi
_ completion: @escaping (TimeMission) -> Void)
throws -> RNotificationToken {

let objectCompletion: ObjectCompletion<TimeMissionObject> = {
change in
let objectCompletion: ObjectCompletion<TimeMissionObject> = { change in
switch change {
case .change(let object, let properties):
// Log.error(object)
Log.error("timeMIssion Properties : \(properties)")
let timeMission = TimeMission.mapFromPersistenceObject(object)
completion(timeMission)
Expand Down
35 changes: 2 additions & 33 deletions Pickle/Pickle/Data/Repository/Repositories/UserRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
import Foundation
import RealmSwift
import Combine
// TODO: User Interactor 적용 해보기
// 1. 현재 뷰 OR Store(ViewModel) 에서 Bussiness로직이 강하게 결합되어있음
// 2. Interactor를 사용하여 도메인 로직 분리 필요해 보임 - 논의 해보기
// 3. 상속 여부 현재 BaseRepository를 사용하여 상속 관계를 형성하여 메소드 자동생성 편의성이 올라가긴했음
// 3-1 DownSide고려하여 Repository 추상화 결정해야함


protocol UserRepositoryProtocol: Dependency, AnyObject {
func getUser(_ completion: @escaping (Result<User, PersistentedError>) -> Void)
func fetchUser() throws -> User
func addUser(model: User) throws
func updateUser(model: User) throws
func updatePizza(model: User, specific data: Date) throws
func deleteAll() throws
/// User Notification Change Observe function
/// - Parameters:
Expand All @@ -28,7 +22,7 @@ protocol UserRepositoryProtocol: Dependency, AnyObject {
/// - Returns: NotificationToken
func observeUser(id: String,
keyPaths: [PartialKeyPath<UserObject>],
_ completion: @escaping ObjectCompletion<UserObject>) throws -> RNotificationToken
_ completion: @escaping ObjectCompletion<UserObject>) throws -> RNotificationToken

func update(seleted user: User) -> Future<User, Error>
}
Expand Down Expand Up @@ -73,12 +67,6 @@ final class UserRepository: BaseRepository<UserObject>, UserRepositoryProtocol {
}
}

func addCurrentPizza(current pizza: CurrentPizza) throws {
let object = pizza.mapToPersistenceObject()
// let realm = try! Realm()

}

func updateUser(model: User) throws {
let object = model.mapToPersistenceObject()
do {
Expand Down Expand Up @@ -107,25 +95,6 @@ final class UserRepository: BaseRepository<UserObject>, UserRepositoryProtocol {
}
}

/// Realm FilterTest
/// - Parameters:
/// - model: userModel
/// - data: not using
func updatePizza(model: User, specific data: Date) throws {
// TODO: 변경 필요
// let object = model.pizzas.map { $0.mapToPersistenceObject() }
// let object2: RealmFilter<PizzaObject> = { value in
// value.lock
// }
// do {
// _ = try dbStore.update(PizzaObject.self,
// item: object.first!,
// query: object2)
// } catch {
// Log.error("update User Pizza \(error)")
// }
}

func deleteAll() throws {
do {
try super.deleteAll(UserObject.self)
Expand Down
11 changes: 3 additions & 8 deletions Pickle/Pickle/Data/Service/RealmMigrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ class RealmMigrator {
func updateSchema() {
let config = Realm.Configuration(fileURL: URL.inDocumentsFolder("main.realm"),
schemaVersion: 3, migrationBlock: { migration, oldSchemaVersion in

Log.info("migration: \(migration)")
Log.info("oldSchemaVersion : \(oldSchemaVersion)")

if oldSchemaVersion < 2 { migrationFromV1ToV2(migration: migration) }
if oldSchemaVersion < 3 { migrationFromV2ToV3(migration: migration) }
}, deleteRealmIfMigrationNeeded: true)

func migrationFromV1ToV2(migration: Migration) {
migration.enumerateObjects(ofType: UserObject.className()) { oldObject, newObject in
guard let oldObject = oldObject else { return }
guard oldObject != nil else { return }
let userObjectPizzaList = newObject?.dynamicList("pizza")

migration.enumerateObjects(ofType: PizzaObject.className()) { pizzaObject, newPizzaObject in
guard let object = pizzaObject else { return }
guard pizzaObject != nil else { return }
if let newPizzaObject {
userObjectPizzaList?.append(newPizzaObject)
}
Expand All @@ -47,7 +42,7 @@ class RealmMigrator {

func migrationFromV2ToV3(migration: Migration) {
migration.enumerateObjects(ofType: TimeMissionObject.className(), { oldObject, newObject in
guard let oldObject else { return }
guard oldObject != nil else { return }
newObject!["changeWakeupTime"] = Date()
})
}
Expand Down
4 changes: 2 additions & 2 deletions Pickle/Pickle/Global/Common/Alert/FaildAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct AlertContent {
let primaryButtonTitle: String
let secondaryButtonTitle: String
let primaryAction: () -> Void
var secondaryAction: (() -> Void)? = nil
var externalTapAction: (() -> Void)? = nil
var secondaryAction: () -> Void = {}
var externalTapAction: () -> Void = {}
}

struct FaildAlertModifier: ViewModifier {
Expand Down
4 changes: 2 additions & 2 deletions Pickle/Pickle/Global/Common/Alert/PizzaAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct PizzaAlertModifier: ViewModifier {
puchaseButtonTitle: puchaseButtonTitle,
primaryButtonTitle: primaryButtonTitle,
puchaseAction: primaryAction,
pizzaMakeNavAction: pizzaMakeNavAction ?? { } )
pizzaMakeNavAction: pizzaMakeNavAction ?? {})
.transition(.move(edge: .bottom).combined(with: .opacity))
}
}
Expand Down Expand Up @@ -208,5 +208,5 @@ struct PizzaAlert: View {
puchaseButtonTitle: "안녕하세요",
primaryButtonTitle: "안녕하세요",
primaryAction: { },
pizzaMakeNavAction: { } ))
pizzaMakeNavAction: { }))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

extension View {
func clearModalBackground()->some View {
func clearModalBackground() -> some View {
self.modifier(ClearBackgroundViewModifier())
}
}
Expand Down
4 changes: 2 additions & 2 deletions Pickle/Pickle/Global/Common/Picker/PickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

struct PickerView: View {

@Binding var isTimeMissionSettingModalPresented: Bool
@Binding var showTimeMissionModal: Bool
@Binding var changedWakeupTime: Date
var title: String
var action: () -> Void
Expand All @@ -20,7 +20,7 @@ struct PickerView: View {
Spacer()
HStack {
Button {
isTimeMissionSettingModalPresented.toggle()
showTimeMissionModal.toggle()
} label: {
Text("취소")
.font(.pizzaBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import Foundation

struct DependencyContainer {

struct Container {
private static var factories: [String: () -> Any] = [:]
private static var cache: [String: Any] = [:]

Expand All @@ -29,7 +28,7 @@ struct DependencyContainer {
factories[String(describing: name.self)] = factory
}

static func resolve<Dependency>(_ resolveType: DependencyType = .automatic,
static func resolve<Dependency>(_ resolveType: InstanceType = .automatic,
_ type: Any.Type?) -> Dependency? {
let serviceName = type.map { String(describing: $0) } ?? String(describing: Dependency.self)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Injected<Dependency> {
var service: Dependency

// MARK: After
init<T>(_ key: T.Type, _ type: DependencyType = .automatic) where T: InjectionKey, Dependency == T.Value {
init<T>(_ key: T.Type, _ type: InstanceType = .automatic) where T: InjectionKey, Dependency == T.Value {
let service: Dependency = key.currentValue
self.service = service
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

enum DependencyType {
enum InstanceType {
case singleton
case newSingleton
case new
Expand Down
Loading

0 comments on commit b09835f

Please sign in to comment.