Skip to content

Commit

Permalink
Merge pull request #50 from pbj-apps/Add-Product-External-Id
Browse files Browse the repository at this point in the history
Add product externalId
  • Loading branch information
s4cha authored Jul 1, 2022
2 parents 8b11d57 + 6e3ed09 commit 75ae75c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Sources/Live/Data/Product/JSONProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct JSONProductHighlightedTiming: Decodable {
}

struct JSONProduct: Decodable {
let external_id: String?
let title: String
let description: String
let price: String
Expand Down Expand Up @@ -57,7 +58,8 @@ public extension String {
extension JSONProductResult {
func toProduct() -> Product {
return Product(
id: id,
id: id,
externalId: product.external_id ?? "",
title: product.title,
price: product.price,
detail: product.description,
Expand Down
17 changes: 10 additions & 7 deletions Sources/Live/Domain/Product/Product.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation

public struct Product: Equatable, Identifiable {
public let id: String
public let externalId: String
public let title: String
public let price: String
public let detail: String
Expand All @@ -18,14 +19,16 @@ public struct Product: Equatable, Identifiable {
public let highlightTimings: [ProductHighlightedTiming]?

public init(id: String,
title: String,
price: String,
detail: String,
image: URL?,
link: URL?,
isHighlighted: Bool,
highlightTimings: [ProductHighlightedTiming]?){
externalId: String,
title: String,
price: String,
detail: String,
image: URL?,
link: URL?,
isHighlighted: Bool,
highlightTimings: [ProductHighlightedTiming]?){
self.id = id
self.externalId = externalId
self.title = title
self.price = price
self.detail = detail
Expand Down
3 changes: 2 additions & 1 deletion Sources/LiveUI/Products/ProductComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ struct ProductComponent: View {
struct ProductComponent_Previews: PreviewProvider {
static var previews: some View {
let product = Product(
id: "123",
id: "123",
externalId: "456",
title: "Apple Airpods",
price: "$29.99",
detail: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.`",
Expand Down
5 changes: 4 additions & 1 deletion Sources/LiveUI/Products/ProductsCarrousel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public struct ProductsCarrousel<PVF: ProductCardViewFactory>: View {
struct ProductsCarrousel_Previews: PreviewProvider {
static var previews: some View {
let product1 = Product(
id: "123",
id: "123",
externalId: "456",
title: "Apple Airpods",
price: "$29.99",
detail: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.`",
Expand All @@ -55,6 +56,7 @@ struct ProductsCarrousel_Previews: PreviewProvider {
highlightTimings: nil)
let product2 = Product(
id: "123",
externalId: "456",
title: "Apple Airpods",
price: "$29.99",
detail: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.`",
Expand All @@ -64,6 +66,7 @@ struct ProductsCarrousel_Previews: PreviewProvider {
highlightTimings: nil)
let product3 = Product(
id: "123",
externalId: "456",
title: "Apple Airpods",
price: "$29.99",
detail: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.`",
Expand Down

0 comments on commit 75ae75c

Please sign in to comment.