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

REFACT :: [#324] pose 리펙 #343

Merged
merged 2 commits into from
Jun 16, 2024
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
4 changes: 2 additions & 2 deletions Projects/Core/Sources/Base/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class BaseViewController<T>: UIViewController {
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

open override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

Expand All @@ -37,8 +37,8 @@ open class BaseViewController<T>: UIViewController {

open override func viewDidLoad() {
super.viewDidLoad()
bindViewModel()
bindActions()
bindViewModel()
layout()
setupKeyboardHandling()
attribute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PickleStepper: Stepper {
public var steps = PublishRelay<Step>()

public var initialStep: Step {
return MGStep.home
return MGStep.pickleRequired
}

public init() {
Expand Down
18 changes: 18 additions & 0 deletions Projects/Core/Sources/Coordinator/Stepper/ShopStepper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

import RxFlow
import RxCocoa

public class ShopStepper: Stepper {
public static let shared = ShopStepper()

public var steps = PublishRelay<Step>()

public var initialStep: Step {
return MGStep.shopIsRequired
}

public init() {

}
}
33 changes: 33 additions & 0 deletions Projects/Core/Sources/CoreData/CoreData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import CoreData

public class CoreDataStack {
public static let shared = CoreDataStack()

lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Model")
container.loadPersistentStores { storeDescription, error in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
}
return container
}()

public var context: NSManagedObjectContext {
return persistentContainer.viewContext
}

public func saveContext() {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}

}

1 change: 1 addition & 0 deletions Projects/Data/Sources/Repository/AuthRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class AuthRepository: AuthRepositoryInterface {
self.networkService = networkService
}


// public func appleSingup(nickname: String, accessToken: String) -> Single<String> {
// return networkService.appleSignup(nickname: nickname, accessToken: accessToken)
// }
Expand Down
12 changes: 10 additions & 2 deletions Projects/Data/Sources/Repository/PostureRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ public class PostureRepository: PostureRepositoryInterface {
return networkService.requestPartData(type: type)
}

public func getDetailData(type: PostureDetailType) -> Single<PostureDetailModel> {
return networkService.requestDetailData(type: type)
public func getDetailData(accessToken: String, id: Int) -> Single<PostureDetailModel> {
return networkService.requestDetailData(accessToken: accessToken, id: id)
.map(PoseDetailDTO.self)
.map { $0.toDomain() }
}

public func getSearchData() -> Single<PostureSearchModel> {
return networkService.requestSearchData()
}

public func getAllPoseData(accessToken: String, lastUpdated: String) -> Single<PostureAllModel> {
return networkService.getAllPoseData(accessToken: accessToken, lastUpdated: lastUpdated)
.map(PostureAllDTO.self)
.map{ $0.toDomain() }
}

public init(networkService: PostureService) {
self.networkService = networkService
}
Expand Down
154 changes: 73 additions & 81 deletions Projects/Domain/Sources/Model/Posture/PostureDetailModel.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import UIKit
import CoreData

public struct PostureDetailModel_temporary {
import Core

public struct PostureDetailModel {
public var needMachine: Bool
public var category: [String]
public var simpleName, exactName: String
Expand All @@ -9,7 +12,7 @@ public struct PostureDetailModel_temporary {
public var simplePart, exactPart, startPose, exerciseWay: [String]
public var breatheWay, caution: [String]
public var pickleImage: [UIImage]

public init(needMachine: Bool, category: [String], simpleName: String, exactName: String, thumbnail: String, video: String, simplePart: [String], exactPart: [String], startPose: [String], exerciseWay: [String], breatheWay: [String], caution: [String], pickleImage: [UIImage]) {
self.needMachine = needMachine
self.category = category
Expand All @@ -27,89 +30,78 @@ public struct PostureDetailModel_temporary {
}
}

public struct PostureDetailModel {
public var detailImage: UIImage
public var titleTextData: PostureDetailTitleTextModel
public var exerciseKindData: [PostureDetailExerciseKindModel]
public var exercisePartData: PostureDetailInfoModel
public var exerciseStartData: PostureDetailInfoModel
public var exerciseWayData: PostureDetailInfoModel
public var exerciseBreathData: PostureDetailInfoModel
public var exerciseCautionData: PostureDetailInfoModel
public var relatedPickleData: PostureDetailPickleModel

public init(detailImage: UIImage,
titleTextData: PostureDetailTitleTextModel,
exerciseKindData: [PostureDetailExerciseKindModel],
exercisePartData: PostureDetailInfoModel,
exerciseStartData: PostureDetailInfoModel,
exerciseWayData: PostureDetailInfoModel,
exerciseBreathData: PostureDetailInfoModel,
exerciseCautionData: PostureDetailInfoModel,
relatedPickleData: PostureDetailPickleModel)
{
self.detailImage = detailImage
self.titleTextData = titleTextData
self.exerciseKindData = exerciseKindData
self.exercisePartData = exercisePartData
self.exerciseStartData = exerciseStartData
self.exerciseWayData = exerciseWayData
self.exerciseBreathData = exerciseBreathData
self.exerciseCautionData = exerciseCautionData
self.relatedPickleData = relatedPickleData
}
}

public struct PostureDetailTitleTextModel {
public var englishName: String
public var koreanName: String

public init(englishName: String, koreanName: String) {
self.englishName = englishName
self.koreanName = koreanName
}
}

public struct PostureDetailExerciseKindModel {
public var exerciseTag: String

public init(exerciseTag: String) {
self.exerciseTag = exerciseTag
}
}

public struct PostureDetailInfoModel {
public var titleText: String
public var infoText: [PostureDetailInfoTextModel]

public init(titleText: String, infoText: [PostureDetailInfoTextModel]) {
self.titleText = titleText
self.infoText = infoText
}
}
public struct PostureAllDataModel {
public var id: Int
public var category: [String]
public var needMachine: Bool
public var name: String
public var simplePart: [String]
public var exactPart: [String]
public var thumbnail: String

public struct PostureDetailInfoTextModel {
public var text: String

public init(text: String) {
self.text = text
init(id: Int, category: [String], needMachine: Bool, name: String, simplePart: [String], exactPart: [String], thumbnail: String) {
self.id = id
self.category = category
self.needMachine = needMachine
self.name = name
self.simplePart = simplePart
self.exactPart = exactPart
self.thumbnail = thumbnail
}
}

public struct PostureDetailPickleModel{
public var titleText: String
public var pickleImage: [PostureDetailPickleImageModel]
public struct PostureAllModel {
public var responses: [PostureAllDataModel]

public init(titleText: String, pickleImage: [PostureDetailPickleImageModel]) {
self.titleText = titleText
self.pickleImage = pickleImage
}
}

public struct PostureDetailPickleImageModel {
public var image: UIImage

public init(image: UIImage) {
self.image = image
init(responses: [PostureAllDataModel]) {
self.responses = responses
}
}
//
//extension CoreDataStack {
// public func savePostureAllModel(posture: PostureAllModel) {
// guard let entity = NSEntityDescription.entity(forEntityName: "PostureAllModel", in: context) else {
// fatalError("Failed to find entity description for PostureAllModel")
// }
//
// for pose in posture.responses {
// let postureObject = NSManagedObject(entity: entity, insertInto: context)
// postureObject.setValue(pose.id, forKey: "id")
// postureObject.setValue(pose.category, forKey: "category")
// postureObject.setValue(pose.needMachine, forKey: "needMachine")
// postureObject.setValue(pose.name, forKey: "name")
// postureObject.setValue(pose.simplePart, forKey: "simplePart")
// postureObject.setValue(pose.exactPart, forKey: "exactPart")
// postureObject.setValue(pose.thumbnail, forKey: "thumbnail")
// }
// saveContext()
// }
//
// public func fetchPostureAllModels() -> PostureAllModel {
// let fetchRequest: NSFetchRequest<NSManagedObject> = NSFetchRequest(entityName: "PostureAllModel")
//
// do {
// let postureObjects = try context.fetch(fetchRequest)
// var postures: PostureAllModel = PostureAllModel(responses: [])
//
// for postureObject in postureObjects {
// let id = postureObject.value(forKey: "id") as! Int
// let category = postureObject.value(forKey: "category") as! [String]
// let needMachine = postureObject.value(forKey: "needMachine") as! Bool
// let name = postureObject.value(forKey: "name") as! String
// let simplePart = postureObject.value(forKey: "simplePart") as! [String]
// let exactPart = postureObject.value(forKey: "exactPart") as! [String]
// let thumbnail = postureObject.value(forKey: "thumbnail") as! String
//
// let posture = PostureAllDataModel(id: id, category: category, needMachine: needMachine, name: name, simplePart: simplePart, exactPart: exactPart, thumbnail: thumbnail)
// postures.responses.append(posture)
// }
//
// return postures
// } catch {
// print("Failed to fetch postures: \(error)")
// return PostureAllModel(responses: [])
// }
// }
//}
//
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ public enum PosturePartType {
case back
}

public enum PostureDetailType {
case pushUp
}

public protocol PostureRepositoryInterface {
func getRecommandData() -> Single<[PostureRecommandModel]>
func getPartData(type: PosturePartType) -> Single<PosturePartModel>
func getDetailData(type: PostureDetailType) -> Single<PostureDetailModel>
func getDetailData(accessToken: String, id: Int) -> Single<PostureDetailModel>
func getSearchData() -> Single<PostureSearchModel>
func getAllPoseData(accessToken: String, lastUpdated: String) -> Single<PostureAllModel>
}
48 changes: 27 additions & 21 deletions Projects/Domain/Sources/Response/PoseDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import Foundation

import DSKit

struct PostureAllDTO: Decodable {
let responses: [PostureAllResponse]
public struct PostureAllDTO: Decodable {
public let responses: [PostureAllResponse]
}

struct PostureAllResponse: Decodable {
let id: Int
let category: [String]
let needMachine: Bool
let name: String
let simplePart, exactPart: [String]
let thumbnail: String
public struct PostureAllResponse: Decodable {
public let id: Int
public let category: [String]
public let needMachine: Bool
public let name: String
public let simplePart, exactPart: [String]
public let thumbnail: String

enum CodingKeys: String, CodingKey {
case id, category
Expand All @@ -24,18 +24,24 @@ struct PostureAllResponse: Decodable {
}
}

extension PostureAllDTO {
// func toDomain() -> SelfCareDetailProfileModel {
// return .init(
// userImage: profileImage,
// userName: nickName,
// userWakaTime: userWakaTime,
// userBageLevel: userBageLevel
// )
// }
public extension PostureAllDTO {
public func toDomain() -> PostureAllModel {
let dataModels = responses.map { response in
PostureAllDataModel(
id: response.id,
category: response.category,
needMachine: response.needMachine,
name: response.name,
simplePart: response.simplePart,
exactPart: response.exactPart,
thumbnail: response.thumbnail
)
}
return PostureAllModel(responses: dataModels)
}
}

struct PoseDetailDTO: Decodable {
public struct PoseDetailDTO: Decodable {
let needMachine: Bool
let category: [String]
let simpleName, exactName: String
Expand All @@ -59,8 +65,8 @@ struct PoseDetailDTO: Decodable {
}
}

extension PoseDetailDTO {
func toDomain() -> PostureDetailModel_temporary {
public extension PoseDetailDTO {
func toDomain() -> PostureDetailModel {
return .init(needMachine: needMachine, category: category, simpleName: simpleName, exactName: exactName, thumbnail: thumbnail, video: video, simplePart: simplePart, exactPart: exactPart, startPose: startPose, exerciseWay: exerciseWay, breatheWay: breatheWay, caution: caution, pickleImage: [
DSKitAsset.Assets.posturePickleTest1.image,
DSKitAsset.Assets.posturePickleTest2.image,
Expand Down
Loading
Loading