Skip to content

Commit

Permalink
#4 Entity class이름을 Category로 합침
Browse files Browse the repository at this point in the history
  • Loading branch information
zombietux committed Apr 22, 2021
1 parent c5c7615 commit e09f4cb
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import Foundation
import Combine

protocol SidedishNetworkManagerProtocol: class {
func getMain() -> AnyPublisher<Main, Error>
func getSoup() -> AnyPublisher<Soup, Error>
func getSide() -> AnyPublisher<Side, Error>
func getCategory(path: String) -> AnyPublisher<Category, Error>
}

class SidedishNetworkManager: SidedishNetworkManagerProtocol {
Expand All @@ -26,18 +24,8 @@ class SidedishNetworkManager: SidedishNetworkManagerProtocol {
self.init(networkManager: networkManager)
}

func getMain() -> AnyPublisher<Main, Error> {
let endpoint = Endpoint.getCategory(path: "main")
return networkManager.get(type: Main.self, url: endpoint.url)
}

func getSoup() -> AnyPublisher<Soup, Error> {
let endpoint = Endpoint.getCategory(path: "soup")
return networkManager.get(type: Soup.self, url: endpoint.url)
}

func getSide() -> AnyPublisher<Side, Error> {
let endpoint = Endpoint.getCategory(path: "side")
return networkManager.get(type: Side.self, url: endpoint.url)
func getCategory(path: String) -> AnyPublisher<Category, Error> {
let endpoint = Endpoint.getCategory(path: path)
return networkManager.get(type: Category.self, url: endpoint.url)
}
}
4 changes: 4 additions & 0 deletions ios/sidedishApp/sidedishApp/Domain/Entity/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ struct Item: Codable, Equatable, Hashable {
func getEventBadgeColor(_ index: Int) -> String {
return self.eventBadgeList[index].getColorHex()
}

func isNotSale() -> Bool {
return self.salePrice == -1 ? true : false
}
}

struct EventBadge: Codable, Equatable, Hashable {
Expand Down
4 changes: 2 additions & 2 deletions ios/sidedishApp/sidedishApp/Domain/Entity/Main.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// Main.swift
// Category.swift
// sidedishApp
//
// Created by zombietux on 2021/04/19.
//

import Foundation

struct Main: Codable, Equatable, Hashable {
struct Category: Codable, Equatable, Hashable {
private var items: [Item]

init(items: [Item]) {
Expand Down
12 changes: 2 additions & 10 deletions ios/sidedishApp/sidedishApp/Domain/UseCase/SidedishUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,8 @@ class SidedishUseCase: SidedishUseCasePort {
self.init(sidedishNetworkManager: sidedishNetworkManager)
}

func getMain() -> AnyPublisher<Main, Error> {
return sidedishNetworkManager.getMain()
}

func getSoup() -> AnyPublisher<Soup, Error> {
return sidedishNetworkManager.getSoup()
}

func getSide() -> AnyPublisher<Side, Error> {
return sidedishNetworkManager.getSide()
func getCategory(path: String) -> AnyPublisher<Category, Error> {
return sidedishNetworkManager.getCategory(path: path)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ import Foundation
import Combine

protocol SidedishUseCasePort {
func getMain() -> AnyPublisher<Main, Error>
func getSoup() -> AnyPublisher<Soup, Error>
func getSide() -> AnyPublisher<Side, Error>
func getCategory(path: String) -> AnyPublisher<Category, Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import UIKit
import Combine

class DetailViewController: UIViewController {
enum Section: Int, CaseIterable {
case main
case soup
case side
}

private var category: String!
private var id: Int!
private var cancellables: Set<AnyCancellable> = []
Expand All @@ -26,7 +32,6 @@ class DetailViewController: UIViewController {

}
.store(in: &cancellables)
// detailViewModel.fetchData(path: self.category, path: self.id)
detailViewModel.fetchData(path: "main", path: 0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit
import Combine

class SidedishViewController: UIViewController {
typealias FetchData = () -> ()
typealias FetchDataHandler = (String) -> ()

enum Section: Int, CaseIterable {
case main
Expand Down Expand Up @@ -39,14 +39,17 @@ class SidedishViewController: UIViewController {
private var sidedishViewModel: SidedishViewModelType!
private var collectionView: UICollectionView!
private var dataSource: UICollectionViewDiffableDataSource<Section, DataItem>!
private let mainPath = "main"
private let soupPath = "soup"
private let sidePath = "side"

override func viewDidLoad() {
super.viewDidLoad()
sidedishViewModel = SidedishViewModel()
configureCollectionView()
fetchMainData()
fetchSoupData()
fetchSideData()
fetchMainData(path: mainPath)
fetchSoupData(path: soupPath)
fetchSideData(path: sidePath)
}

private func configureCollectionView() {
Expand Down Expand Up @@ -104,27 +107,27 @@ class SidedishViewController: UIViewController {
}
}

private func fetchMainData() {
self.fetchData(fetchData: self.sidedishViewModel.fetchMainData)
private func fetchMainData(path: String) {
self.fetchData(fetchData: self.sidedishViewModel.fetchMainData, path: path)
}

private func fetchSoupData() {
self.fetchData(fetchData: self.sidedishViewModel.fetchSoupData)
private func fetchSoupData(path: String) {
self.fetchData(fetchData: self.sidedishViewModel.fetchSoupData, path: path)
}

private func fetchSideData() {
self.fetchData(fetchData: self.sidedishViewModel.fetchSideData)
private func fetchSideData(path: String) {
self.fetchData(fetchData: self.sidedishViewModel.fetchSideData, path: path)
}

private func fetchData(fetchData handler: FetchData) {
private func fetchData(fetchData handler: FetchDataHandler, path: String) {
self.sidedishViewModel.dataChanged
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
self?.updateSnapshot()
}
.store(in: &cancellables)

handler()
handler(path)
}

private func updateSnapshot() {
Expand All @@ -137,4 +140,3 @@ class SidedishViewController: UIViewController {
self.dataSource.apply(snapshot)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SidedishCell: UICollectionViewCell {
self.descriptionLabel.text = item.getDescription()
self.normalPriceLabel.text = "\(item.getNormalPrice())"
self.salePriceLabel.text = "\(item.getSalePrice())"
self.salePriceLabel.isHidden = item.isNotSale()
guard let url = URL(string: item.getThumbnailImage()) else { return }
self.thumbnailImageView.setImage(with: url)
self.badgeLabel.backgroundColor = .systemGreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import Foundation
import Combine

class SidedishViewModel: SidedishViewModelType {
private var main = Main(items: [])
private var soup = Soup(items: [])
private var side = Side(items: [])
private var main = Category(items: [])
private var soup = Category(items: [])
private var side = Category(items: [])
private(set) var dataChanged = PassthroughSubject<Void, Never>()
private var cancellables = Set<AnyCancellable>()
private var sidedishUseCase: SidedishUseCasePort!
Expand All @@ -37,8 +37,8 @@ class SidedishViewModel: SidedishViewModelType {
return self.side.getItems()
}

func fetchMainData() {
sidedishUseCase.getMain()
func fetchMainData(path: String) {
sidedishUseCase.getCategory(path: path)
.receive(on: DispatchQueue.global())
.sink(receiveCompletion: { (result)
in switch result {
Expand All @@ -53,8 +53,8 @@ class SidedishViewModel: SidedishViewModelType {
.store(in: &cancellables)
}

func fetchSoupData() {
sidedishUseCase.getSoup()
func fetchSoupData(path: String) {
sidedishUseCase.getCategory(path: path)
.receive(on: DispatchQueue.global())
.sink(receiveCompletion: { (result)
in switch result {
Expand All @@ -69,8 +69,8 @@ class SidedishViewModel: SidedishViewModelType {
.store(in: &cancellables)
}

func fetchSideData() {
sidedishUseCase.getSide()
func fetchSideData(path: String) {
sidedishUseCase.getCategory(path: path)
.receive(on: DispatchQueue.global())
.sink(receiveCompletion: { (result)
in switch result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol SidedishViewModelType {
func getMainItems() -> [Item]
func getSoupItems() -> [Item]
func getSideItems() -> [Item]
func fetchMainData()
func fetchSoupData()
func fetchSideData()
func fetchMainData(path: String)
func fetchSoupData(path: String)
func fetchSideData(path: String)
}

0 comments on commit e09f4cb

Please sign in to comment.