Skip to content

Commit

Permalink
#5 Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zzisun committed Apr 21, 2021
1 parent eb4d438 commit 03b77e2
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 48 deletions.
4 changes: 4 additions & 0 deletions ios/sidedishApp/sidedishApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
764CE0BD26300A3000DED09C /* DetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0BC26300A3000DED09C /* DetailViewModel.swift */; };
764CE0C22630110500DED09C /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0C12630110500DED09C /* DetailViewController.swift */; };
764CE0C72630167E00DED09C /* DetailItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0C62630167E00DED09C /* DetailItem.swift */; };
764CE0CC26301E7000DED09C /* DetailViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0CB26301E7000DED09C /* DetailViewModelType.swift */; };
9386C100262D7400008645D9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9386C0FF262D7400008645D9 /* AppDelegate.swift */; };
9386C102262D7400008645D9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9386C101262D7400008645D9 /* SceneDelegate.swift */; };
9386C104262D7400008645D9 /* SidedishViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9386C103262D7400008645D9 /* SidedishViewController.swift */; };
Expand Down Expand Up @@ -65,6 +66,7 @@
764CE0BC26300A3000DED09C /* DetailViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewModel.swift; sourceTree = "<group>"; };
764CE0C12630110500DED09C /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = "<group>"; };
764CE0C62630167E00DED09C /* DetailItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailItem.swift; sourceTree = "<group>"; };
764CE0CB26301E7000DED09C /* DetailViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewModelType.swift; sourceTree = "<group>"; };
9386C0FC262D7400008645D9 /* sidedishApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = sidedishApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
9386C0FF262D7400008645D9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9386C101262D7400008645D9 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -243,6 +245,7 @@
9386C161262D8BA9008645D9 /* SidedishViewModel.swift */,
9386C1D1262FC561008645D9 /* SidedishViewModelType.swift */,
764CE0BC26300A3000DED09C /* DetailViewModel.swift */,
764CE0CB26301E7000DED09C /* DetailViewModelType.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -416,6 +419,7 @@
9386C162262D8BA9008645D9 /* SidedishViewModel.swift in Sources */,
9386C1A5262E54D5008645D9 /* SidedishUseCase.swift in Sources */,
9386C184262DC53B008645D9 /* Side.swift in Sources */,
764CE0CC26301E7000DED09C /* DetailViewModelType.swift in Sources */,
764CE0BD26300A3000DED09C /* DetailViewModel.swift in Sources */,
764CE0B8263008E200DED09C /* DetailUseCasePort.swift in Sources */,
764CE0A9263003A200DED09C /* Detail.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "A425890E-D712-4246-878C-15EF841646D3"
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "sidedishApp/Presentation/ViewModels/DetailViewModel.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
startingLineNumber = "39"
endingLineNumber = "39"
landmarkName = "fetchData(path:path:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -62,8 +62,8 @@
filePath = "sidedishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "19"
endingLineNumber = "19"
startingLineNumber = "18"
endingLineNumber = "18"
landmarkName = "get(type:url:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -94,8 +94,8 @@
filePath = "sidedishApp/Presentation/UI/ViewControllers/DetailViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "34"
endingLineNumber = "34"
startingLineNumber = "22"
endingLineNumber = "22"
landmarkName = "fetchData()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -110,8 +110,8 @@
filePath = "sidedishApp/Presentation/UI/ViewControllers/DetailViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "42"
endingLineNumber = "42"
startingLineNumber = "30"
endingLineNumber = "30"
landmarkName = "fetchData()"
landmarkType = "7">
</BreakpointContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ protocol HttpMethodProtocol: class {
class NetworkManager: HttpMethodProtocol {
func get<T>(type: T.Type, url: URL) -> AnyPublisher<T, Error> where T : Decodable {
let urlRequest = URLRequest(url: url)
print(urlRequest)

return URLSession.shared.dataTaskPublisher(for: urlRequest)
.map(\.data)
Expand Down
6 changes: 3 additions & 3 deletions ios/sidedishApp/sidedishApp/Domain/Entity/Detail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import Foundation
struct Detail: Codable {
private let item: DetailItem

init(){
init() {
let id = 0
let detailImages = [""]
let descriptionImages = [""]
let name = ""
let description = ""
let normalPrice = 0
let salePrice = 0
// let eventBadgeList = ["]
let eventBadgeList = [EventBadge(name: "", colorHex: "")]
let pointRate = 1
let isPurchasable = false
let deliveryInfo = ""
let deliveryFee = ""
self.item = DetailItem(id: id, detailImages: detailImages, descriptionImages: descriptionImages, name: name, description: description, normalPrice: normalPrice, salePrice: salePrice, pointRate: pointRate, isPurchasable: isPurchasable, deliveryInfo: deliveryInfo, deliveryFee: deliveryFee)
self.item = DetailItem(id: id, detailImages: detailImages, descriptionImages: descriptionImages, name: name, description: description, normalPrice: normalPrice, salePrice: salePrice, eventBadgeList: eventBadgeList, pointRate: pointRate, isPurchasable: isPurchasable, deliveryInfo: deliveryInfo, deliveryFee: deliveryFee)

}
}
24 changes: 4 additions & 20 deletions ios/sidedishApp/sidedishApp/Domain/Entity/DetailItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct DetailItem: Codable {
private let description: String
private let normalPrice: Int
private let salePrice: Int
// private let eventBadgeList: [EventBadge]
private let eventBadgeList: [EventBadge]
private let pointRate: Int
private let isPurchasable: Bool
private let deliveryInfo: String
Expand All @@ -29,41 +29,25 @@ struct DetailItem: Codable {
case description
case normalPrice
case salePrice
// case eventBadgeList
case eventBadgeList
case pointRate
case isPurchasable
case deliveryInfo = "delivery_info"
case deliveryFee = "delivery_fee"
}

init(id: Int, detailImages: [String], descriptionImages: [String], name: String, description: String, normalPrice: Int, salePrice: Int, pointRate: Int, isPurchasable: Bool, deliveryInfo: String, deliveryFee: String) {
init(id: Int, detailImages: [String], descriptionImages: [String], name: String, description: String, normalPrice: Int, salePrice: Int, eventBadgeList: [EventBadge],pointRate: Int, isPurchasable: Bool, deliveryInfo: String, deliveryFee: String) {
self.id = id
self.detailImages = detailImages
self.descriptionImages = descriptionImages
self.name = name
self.description = description
self.normalPrice = normalPrice
self.salePrice = salePrice
// self.eventBadgeList = eventBadgeList
self.eventBadgeList = eventBadgeList
self.pointRate = pointRate
self.isPurchasable = isPurchasable
self.deliveryInfo = deliveryInfo
self.deliveryFee = deliveryFee
}

// convenience init() {
// let id = 0
// let detailImages = [""]
// let descriptionImages = [""]
// let name = ""
// let description = ""
// let normalPrice = 0
// let salePrice = 0
//// let eventBadgeList = ["]
// let pointRate = 1
// let isPurchasable = false
// let deliveryInfo = ""
// let deliveryFee = ""
// self.init(id: id, detailImages: detailImages, descriptionImages: descriptionImages, name: name, description: description, normalPrice: normalPrice, salePrice: salePrice, pointRate: pointRate, isPurchasable: isPurchasable, deliveryInfo: deliveryInfo, deliveryFee: deliveryFee)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,13 @@ class DetailViewController: UIViewController {
private var category: String!
private var id: Int!
private var cancellables: Set<AnyCancellable> = []
private var detailViewModel: DetailViewModel!
private var detailViewModel: DetailViewModelType!
override func viewDidLoad() {
super.viewDidLoad()
detailViewModel = DetailViewModel()
fetchData()
// detailViewModel.fetchData(path: <#T##String#>, path: <#T##Int#>)
// Do any additional setup after loading the view.
}


/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
private func fetchData() {
detailViewModel.dataChanged
.receive(on: DispatchQueue.main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Combine

class DetailViewModel {
class DetailViewModel: DetailViewModelType {
private var item = Detail()
private(set) var dataChanged = PassthroughSubject<Void, Never>()
private var cancellables = Set<AnyCancellable>()
Expand Down Expand Up @@ -36,7 +36,6 @@ class DetailViewModel {
case .failure(let error): print(error.localizedDescription) } },
receiveValue: { item in
self.item = item
dump(self.item)
self.dataChanged.send()
})
.store(in: &cancellables)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// DetailViewModelType.swift
// sidedishApp
//
// Created by 김지선 on 2021/04/21.
//

import Foundation
import Combine

protocol DetailViewModelType {
var dataChanged: PassthroughSubject<Void, Never> { get }
func getDetailItem() -> Detail
func fetchData(path category: String, path id: Int)
}

0 comments on commit 03b77e2

Please sign in to comment.