Skip to content

Commit

Permalink
Merge pull request #7 from Polynomeer/feature/5/model
Browse files Browse the repository at this point in the history
feat: Create DataSource and Check MainView (#5)
  • Loading branch information
BMO5 authored Apr 21, 2021
2 parents 83e455b + debc96f commit c855831
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 24 deletions.
70 changes: 65 additions & 5 deletions frontend/SideDish/SideDish.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
BD090658262E9B450094421D /* MenuCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD090656262E9B450094421D /* MenuCell.swift */; };
BD090659262E9B450094421D /* MenuCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = BD090657262E9B450094421D /* MenuCell.xib */; };
BD09065E262EBD310094421D /* Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD09065D262EBD310094421D /* Menu.swift */; };
BD09066D262EC5120094421D /* Menus.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD09066C262EC5120094421D /* Menus.swift */; };
BD930B58262D6F5800906633 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD930B57262D6F5800906633 /* AppDelegate.swift */; };
BD930B5A262D6F5800906633 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD930B59262D6F5800906633 /* SceneDelegate.swift */; };
BD930B5C262D6F5800906633 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD930B5B262D6F5800906633 /* ViewController.swift */; };
Expand All @@ -17,6 +19,9 @@
BD930B64262D6F5900906633 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BD930B62262D6F5900906633 /* LaunchScreen.storyboard */; };
BD930B6F262D6F5900906633 /* SideDishTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD930B6E262D6F5900906633 /* SideDishTests.swift */; };
BD930B7A262D6F5900906633 /* SideDishUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD930B79262D6F5900906633 /* SideDishUITests.swift */; };
BDFABA96262FF9FC00803154 /* Parsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFABA95262FF9FC00803154 /* Parsing.swift */; };
BDFABA9B262FFA0600803154 /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFABA9A262FFA0600803154 /* Request.swift */; };
BDFABAA0262FFA1C00803154 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDFABA9F262FFA1C00803154 /* Network.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -39,6 +44,8 @@
/* Begin PBXFileReference section */
BD090656262E9B450094421D /* MenuCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuCell.swift; sourceTree = "<group>"; };
BD090657262E9B450094421D /* MenuCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MenuCell.xib; sourceTree = "<group>"; };
BD09065D262EBD310094421D /* Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Menu.swift; sourceTree = "<group>"; };
BD09066C262EC5120094421D /* Menus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Menus.swift; sourceTree = "<group>"; };
BD930B54262D6F5800906633 /* SideDish.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SideDish.app; sourceTree = BUILT_PRODUCTS_DIR; };
BD930B57262D6F5800906633 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
BD930B59262D6F5800906633 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -53,6 +60,9 @@
BD930B75262D6F5900906633 /* SideDishUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SideDishUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
BD930B79262D6F5900906633 /* SideDishUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideDishUITests.swift; sourceTree = "<group>"; };
BD930B7B262D6F5900906633 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
BDFABA95262FF9FC00803154 /* Parsing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Parsing.swift; sourceTree = "<group>"; };
BDFABA9A262FFA0600803154 /* Request.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Request.swift; sourceTree = "<group>"; };
BDFABA9F262FFA1C00803154 /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -80,6 +90,51 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
BD090662262EBD350094421D /* Model */ = {
isa = PBXGroup;
children = (
BD090674262ED1CA0094421D /* DTO */,
BD09065D262EBD310094421D /* Menu.swift */,
BD09066C262EC5120094421D /* Menus.swift */,
);
path = Model;
sourceTree = "<group>";
};
BD090666262EBD7A0094421D /* Controller */ = {
isa = PBXGroup;
children = (
);
path = Controller;
sourceTree = "<group>";
};
BD090667262EBD820094421D /* View */ = {
isa = PBXGroup;
children = (
BD090656262E9B450094421D /* MenuCell.swift */,
BD090657262E9B450094421D /* MenuCell.xib */,
);
path = View;
sourceTree = "<group>";
};
BD090668262EBDC80094421D /* AppCycle */ = {
isa = PBXGroup;
children = (
BD930B57262D6F5800906633 /* AppDelegate.swift */,
BD930B59262D6F5800906633 /* SceneDelegate.swift */,
);
path = AppCycle;
sourceTree = "<group>";
};
BD090674262ED1CA0094421D /* DTO */ = {
isa = PBXGroup;
children = (
BDFABA95262FF9FC00803154 /* Parsing.swift */,
BDFABA9A262FFA0600803154 /* Request.swift */,
BDFABA9F262FFA1C00803154 /* Network.swift */,
);
path = DTO;
sourceTree = "<group>";
};
BD930B4B262D6F5800906633 = {
isa = PBXGroup;
children = (
Expand All @@ -103,14 +158,14 @@
BD930B56262D6F5800906633 /* SideDish */ = {
isa = PBXGroup;
children = (
BD930B57262D6F5800906633 /* AppDelegate.swift */,
BD930B59262D6F5800906633 /* SceneDelegate.swift */,
BD090668262EBDC80094421D /* AppCycle */,
BD090667262EBD820094421D /* View */,
BD090666262EBD7A0094421D /* Controller */,
BD090662262EBD350094421D /* Model */,
BD930B5B262D6F5800906633 /* ViewController.swift */,
BD930B5D262D6F5800906633 /* Main.storyboard */,
BD090656262E9B450094421D /* MenuCell.swift */,
BD090657262E9B450094421D /* MenuCell.xib */,
BD930B60262D6F5900906633 /* Assets.xcassets */,
BD930B62262D6F5900906633 /* LaunchScreen.storyboard */,
BD930B60262D6F5900906633 /* Assets.xcassets */,
BD930B65262D6F5900906633 /* Info.plist */,
);
path = SideDish;
Expand Down Expand Up @@ -265,10 +320,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BDFABA96262FF9FC00803154 /* Parsing.swift in Sources */,
BDFABA9B262FFA0600803154 /* Request.swift in Sources */,
BD930B5C262D6F5800906633 /* ViewController.swift in Sources */,
BD930B58262D6F5800906633 /* AppDelegate.swift in Sources */,
BD090658262E9B450094421D /* MenuCell.swift in Sources */,
BDFABAA0262FFA1C00803154 /* Network.swift in Sources */,
BD930B5A262D6F5800906633 /* SceneDelegate.swift in Sources */,
BD09066D262EC5120094421D /* Menus.swift in Sources */,
BD09065E262EBD310094421D /* Menu.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions frontend/SideDish/SideDish/Model/DTO/JSONModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import Foundation

struct getMenu: Codable {
let statusCode: Int
let body: [Menu]
}
26 changes: 26 additions & 0 deletions frontend/SideDish/SideDish/Model/DTO/Network.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Network.swift
// SideDish
//
// Created by sonjuhyeong on 2021/04/21.
//

import Foundation

class DataTaskManager {

static let session = URLSession(configuration: .default)

static func get(completion: @escaping (Result<getMenu, Error>) -> Void) {
session.dataTask(with: RequestManager.getRequest()) { data, response, error in
if let data = data {
guard let menuList = ParsingManager.decodeData(type: getMenu.self, data: data) else { print("d"); return }
completion(.success(menuList))
} else {
guard let error = error?.localizedDescription as? Error else { return }
completion(.failure(error))
}
}.resume()
}

}
31 changes: 31 additions & 0 deletions frontend/SideDish/SideDish/Model/DTO/Parsing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Parsing.swift
// SideDish
//
// Created by sonjuhyeong on 2021/04/21.
//

import Foundation

class ParsingManager {

static func encodeData<T: Codable>(data: T) -> Data? {
let encoder = JSONEncoder()
do {
return try encoder.encode(data)
}catch{
print("Encode error")
return nil
}
}

static func decodeData<T: Codable>(type: T.Type, data: Data) -> T? {
let decoder = JSONDecoder()
do {
return try decoder.decode(type, from: data)
}catch{
print("Decode error")
return nil
}
}
}
23 changes: 23 additions & 0 deletions frontend/SideDish/SideDish/Model/DTO/Request.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Request.swift
// SideDish
//
// Created by sonjuhyeong on 2021/04/21.
//

import Foundation

class RequestManager {

static let urlString = "https://h3rb9c0ugl.execute-api.ap-northeast-2.amazonaws.com/develop/baminchan/main"
//GET
static func getRequest() -> URLRequest {
guard let url = URL(string: urlString) else {
print("The URL is inappropriate.")
return URLRequest(url: URL(string: "")!)
}
return URLRequest(url: url)
}


}
62 changes: 62 additions & 0 deletions frontend/SideDish/SideDish/Model/Menu.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Menu.swift
// SideDish
//
// Created by sonjuhyeong on 2021/04/20.
//

import Foundation

class Menu: Codable {

private let detail_hash: String
private let image: String
private let alt: String
private let delivery_type: [String]
private let title: String
private let description: String
private let n_price: String?
private let s_price: String
private let badge: [String]?

init(detail_hash: String, image: String, alt: String, delivery_type: [String], title: String, description: String, n_price: String?, s_price: String, badge: [String]?) {
self.detail_hash = detail_hash
self.image = image
self.alt = alt
self.delivery_type = delivery_type
self.title = title
self.description = description
self.n_price = n_price
self.s_price = s_price
self.badge = badge
}

func configure(cell: MenuCell) {
cell.titleLabel.text = self.title
cell.bodyLabel.text = self.description
cell.currentPriceLabel.text = self.s_price
}
}



extension Menu: Hashable, Equatable {
static func == (lhs: Menu, rhs: Menu) -> Bool {
return lhs.detail_hash == rhs.detail_hash || lhs.image == rhs.image ||
lhs.alt == rhs.alt || lhs.delivery_type == rhs.delivery_type ||
lhs.title == rhs.title || lhs.description == rhs.description ||
lhs.n_price == rhs.n_price || lhs.s_price == rhs.s_price || lhs.badge == rhs.badge
}

func hash(into hasher: inout Hasher) {
hasher.combine(detail_hash)
hasher.combine(image)
hasher.combine(alt)
hasher.combine(delivery_type)
hasher.combine(title)
hasher.combine(description)
hasher.combine(n_price)
hasher.combine(s_price)
hasher.combine(badge)
}
}
26 changes: 26 additions & 0 deletions frontend/SideDish/SideDish/Model/Menus.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// VariousMenu.swift
// SideDish
//
// Created by sonjuhyeong on 2021/04/20.
//

import Foundation

class Menus {

private var menus: [Menu]!

init() {
self.menus = nil
}

func add(menuList: [Menu]) {
self.menus = menuList
}

func giveMenu() -> [Menu] {
return self.menus
}
}

26 changes: 26 additions & 0 deletions frontend/SideDish/SideDish/View/MainDiffableDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import Foundation
import UIKit

class MainDiffableDataSource {

private var dataSource : UICollectionViewDiffableDataSource<Int, Menu>!

func setupDataSource(collectionView: UICollectionView) {
self.dataSource = UICollectionViewDiffableDataSource<Int, Menu>(collectionView: collectionView) {
(collectionView, indexPath, menu) -> UICollectionViewCell? in
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "menuCell", for: indexPath) as? MenuCell else { preconditionFailure() }

menu.configure(cell: cell)
return cell
}
}

func applySnapshot(data: [Menu]) {
let menus = data
var snapshot = NSDiffableDataSourceSnapshot<Int, Menu>()
snapshot.appendSections([1])
snapshot.appendItems(menus)
self.dataSource.apply(snapshot, animatingDifferences: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class MenuCell: UICollectionViewCell {
self.eventLabel.layer.cornerRadius = 5
self.launchingLabel.layer.masksToBounds = true
self.launchingLabel.layer.cornerRadius = 5
self.titleLabel.text = "[미노리키친] 일본식 우엉조림 (킨피라고보) 80g"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<rect key="frame" x="138" y="62" width="22" height="20"/>
<constraints>
<constraint firstAttribute="height" constant="20" id="M0r-fI-ITt"/>
<constraint firstAttribute="width" constant="22" id="WfW-c3-gye"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="22" id="WfW-c3-gye"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<color key="textColor" red="0.0039215686274509803" green="0.0039215686274509803" blue="0.0039215686274509803" alpha="1" colorSpace="calibratedRGB"/>
Expand Down
Loading

0 comments on commit c855831

Please sign in to comment.