-
Notifications
You must be signed in to change notification settings - Fork 50
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
[๐ฅTeam-6 / iOS / ์ญ & ์ญ์จ] ์์ธ ํ์ด์ง ๋ฐ Persistence ๊ตฌํ #74
base: banchan-code
Are you sure you want to change the base?
Changes from 125 commits
221872e
70429f0
4a80ab8
2ec2b27
9f69adf
8292668
51febc4
5b6418e
6471088
f8de5da
7bce9a3
0f9370c
d90a8a7
0028aee
96eb4fe
6ca3976
231310c
16db4bc
f3fdb26
9d9878b
7543910
ec93be7
0990fc4
9ef2707
92e4ce7
7b67445
1e7f2a1
dd1dafd
71c0eb5
e87710f
ce18911
82ad7f3
7c70eea
b07e127
a9f6261
6b7ed44
820e727
aaf57e0
f10ac4b
b22b22b
156b4c5
6b0e33b
d425037
54598e8
ebcebbf
9852175
631246b
c7de000
e9571cc
36ee292
bb05ed9
5513f47
b5c3d21
e92e0a7
cfa02b4
b4fc47a
c9db182
a63cc03
bf834af
91226cb
b236f79
f2e9884
22190e3
23ac570
a078518
2894fd8
fd930a6
a371aca
91ec3d3
30f16d4
7a30ced
0e9eb2b
a91e197
1665972
eb13ad3
b4f483e
3452825
d0e3168
49a06ae
132d8bf
52011f5
20dbece
9669352
ff962a1
542b445
d2c345f
5d5691c
6449ad4
be22b8d
5d00d1a
af785fb
e47fac9
1640865
0e5efbb
4145305
e7c697a
57421b6
251cb14
0c6588b
b875eb2
d3d5805
3588bf7
24833d6
214a920
73457cc
22d46e0
833b2ae
ceb6366
ce44c0e
19c6f28
596bf06
482b79a
3259116
63a55d9
e4fe0e3
e203d34
cd75dde
4a8cf5a
0990e2f
4fa0b3e
06abb91
586cedc
f6ecc57
313df74
f42f46f
85e76b4
c22330b
b02bd0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Banchan-Code | ||
|
||
- ์ฐ๋ฆฌ์ ํ๋ช ์ `๋ฐ์ฐฌ์ฝ๋`(Banchan-Code)์ ๋๋ค~ | ||
|
||
|
||
## ๋ฐฑ๊น์น๐ฅฌ(BE) : ์ ๐งโโ๏ธ, ์ฐ๐ฉ๐ป | ||
## ์ค์ด์๋ฐ์ด๐ฅ(iOS) : ์ญ๐ฅฒ, ์ญ์จ๐ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,6 @@ import UIKit | |
|
||
@main | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,5 @@ | |
import UIKit | ||
|
||
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
|
||
var window: UIWindow? | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// DishDetailResponseDTO.swift | ||
// BanchanCode | ||
// | ||
// Created by Song on 2021/04/28. | ||
// | ||
|
||
import Foundation | ||
|
||
struct DishDetailResponseDTO: Decodable { | ||
private enum CodingKeys: String, CodingKey { | ||
case id | ||
case name | ||
case description | ||
case prices | ||
case badges | ||
case stock | ||
case point | ||
case deliveryInfo = "delivery_info" | ||
case thumbImages = "thumb_images" | ||
case detailImages = "detail_images" | ||
} | ||
let id: Int | ||
let name: String | ||
let description: String | ||
let prices: [Int] | ||
let badges: [String] | ||
let stock: Int | ||
let point: Int | ||
let deliveryInfo: String | ||
let thumbImages: [String] | ||
let detailImages: [String] | ||
} | ||
|
||
extension DishDetailResponseDTO { | ||
func toDomain() -> DishDetail { | ||
return .init(basicInformation: BasicInformation( | ||
id: id, | ||
name: name, | ||
description: description, | ||
prices: prices, | ||
badges: badges, | ||
stock: stock, | ||
point: point, | ||
deliveryInfo: deliveryInfo | ||
), | ||
thumbImages: thumbImages, | ||
detailImages: detailImages) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// DishEntitiy.swift | ||
// BanchanCode | ||
// | ||
// Created by jinseo park on 4/28/21. | ||
// | ||
|
||
import Foundation | ||
import RealmSwift | ||
|
||
class DishDB: Object { | ||
|
||
@objc dynamic var id: Int = -1 | ||
@objc dynamic var name: String = "" | ||
@objc dynamic var contents: String = "" | ||
@objc dynamic var imageURL: String = "" | ||
@objc dynamic var categoryName: String = "" | ||
let prices = List<Int>() | ||
let badges = List<String>() | ||
|
||
convenience init(id: Int, name: String, contents: String, imageURL: String, categoryName: String) { | ||
self.init() | ||
self.id = id | ||
self.name = name | ||
self.contents = contents | ||
self.imageURL = imageURL | ||
self.categoryName = categoryName | ||
} | ||
Comment on lines
+22
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ๋ถ๋ถ์์ prices ์ badges๋ฅผ ์ถ๊ฐํ๋๊ฒ ๊น๋ํ๊ฒ ๋ค์. ๊ทธ๋ฆฌ๊ณ ์ฐพ์๋ณด๋ |
||
|
||
override class func primaryKey() -> String? { | ||
return "id" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// RealmManager.swift | ||
// BanchanCode | ||
// | ||
// Created by jinseo park on 4/28/21. | ||
// | ||
|
||
import RealmSwift | ||
import Foundation | ||
|
||
private protocol RealmOperations { | ||
func addDishes(items: [DishesItemViewModel], categoryName: String) | ||
func getDishes(categryName: String) -> Dishes | ||
} | ||
|
||
class RealmManager: RealmOperations { | ||
let realm = try! Realm() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. forcedunwrapping ์ ์ข์ง ์์์. ์์ ์ฌ์ฉ ์ํ์๋ ๊ฑธ ๊ถ์ฅํฉ๋๋ค. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๊ฐ์ฌํฉ๋๋ค. ํํ ๋ฆฌ์ผ๋๋ก ๋ฐ๋ผ๋ง ํ๋ค๋ณด๋ force๋ฅผ ์ด์ฉํ์ต๋๋ค. ์์ผ๋ก๋ try catch๋ก ๊ตฌํํด๋ณด๋ ์ต๊ด์ ํค์ฐ๋๋ก ํ๊ฒ ์ต๋๋ค! |
||
|
||
func addDishes(items: [DishesItemViewModel], categoryName: String) { | ||
items.forEach { item in | ||
if (realm.object(ofType: DishDB.self, forPrimaryKey: item.dish.id) == nil) { | ||
let dishDB = DishDB(id: item.dish.id, name: item.dish.name, contents: item.dish.description, imageURL: item.dish.imageURL, categoryName: categoryName) | ||
item.dish.prices.forEach { | ||
dishDB.prices.append($0) | ||
} | ||
item.dish.badges.forEach { | ||
dishDB.badges.append($0) | ||
} | ||
try! realm.write { | ||
realm.add(dishDB) | ||
} | ||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๊ฐ์ฌํฉ๋๋ค. ์ด๋ฒ ๊ธฐํ์ ์ ๋ Result<T,Error> ์ ๋ํ ๊ฐ๋ ์ ์ด์ง ๋ง๋ณด์๋๋ฐ( ๋คํธ์ํฌ ์ฐ๊ฒฐ์ด ์๋์ ๋ ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ์ด์ฉํด์ DB์ ์์ดํ ์ ๋ถ๋ฌ์ค๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๊ธฐ ์ํด์) ์ ์ด์จ์ด ์จ์ฃผ์ ๊ธ์ ํ๋ฒ ์ฝ์ด๋ณด๊ณ ์ดํดํด๋ณด๊ฒ ์ต๋๋ค! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ ๋ต, ๊ธ์ด ์ข ์ ์ ๋์ด ์์ง ์์์ ใ ใ ใ |
||
} | ||
} | ||
} | ||
|
||
func getDishes(categryName: String) -> Dishes { | ||
|
||
var dishItems = Dishes(dishes: []) | ||
let dishes = realm.objects(DishDB.self).filter("categoryName == %@", categryName) | ||
|
||
dishes.forEach{ dishDB in | ||
let dish = Dish(id: dishDB.id, name: dishDB.name, description: dishDB.contents, imageURL: dishDB.imageURL, prices: Array(dishDB.prices), badges: Array(dishDB.badges)) | ||
dishItems.dishes.append(dish) | ||
} | ||
return dishItems | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
covenience init
์ ์ฐ์ ์ด์ ๊ฐ ๋ฐ๋ก ์์๊น์? ํน๋ณํ ์ด์ ๊ฐ ์์ผ์๋ค๋ฉด ๊ทธ๋ฅ init์ ์จ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.