-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
143 lines (135 loc) · 5.69 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const express = require('express')
const cors = require('cors')
const app = express()
app.use(cors())
const pets = [
{
petId: 1,
imageUrl: 'https://images.unsplash.com/photo-1589883661923-6476cb0ae9f2?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2574&q=80',
description: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.',
rating: 5
},
{
petId: 2,
imageUrl: 'https://images.unsplash.com/photo-1596854407944-bf87f6fdd49e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1160&q=80',
description: 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.',
rating: 4
},
{
petId: 3,
imageUrl: 'https://images.unsplash.com/photo-1529257414772-1960b7bea4eb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80',
description: 'It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum',
rating: 3
},
{
petId: 4,
imageUrl: 'https://images.unsplash.com/photo-1533743983669-94fa5c4338ec?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1392&q=80',
description: 'All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. ',
rating: 5
}
]
// pet-detail/:petId
// pet-detail:2
// pet-detail:4
app.get('/pet-detail/:petId', (req, res) => {
const petId = parseInt(req.params.petId)
const pet = pets.find(pet => pet.petId == petId)
const model = {
pageTitle: 'Pet Detail',
components: [
{
type: 'featuredImage',
data: {
imageUrl: pet.imageUrl
}
},
{
type: 'textRow',
data: {
text: pet.description
}
},
{
type: "ratingRow",
data: {
rating: pet.rating
}
}
]
}
res.json(model)
})
// pet-listing
app.get('/pet-listing', (req, res) => {
const model = {
"pageTitle": "Pets",
"components": [
{
"type": "featuredImage",
"data": {
"imageUrl": "https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1468&q=80"
}
},
{
"type": "carousel",
"data": {
"items": pets.map(pet => {
return {
petId: pet.petId,
imageUrl: pet.imageUrl
}
}),
"action": {
"type": "sheet",
"destination": "petDetail"
}
}
},
{
type: 'list',
data: {
rows: [
{
id: 1,
title: "Fluffy",
subTitle: "This is a great pet!",
imageUrl: "https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1468&q=80",
description: "All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet."
},
{
id: 2,
title: "Barnie",
subTitle: "This is a great pet!"
},
{
id: 3,
title: "Cato",
subTitle: "This is a great pet!",
description: "All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet."
},
{
id: 4,
title: "Laila",
subTitle: "This is a great pet!",
imageUrl: "https://images.unsplash.com/photo-1517331156700-3c241d2b4d83?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1468&q=80",
description: "All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet."
}
],
action: {
type: "push",
destination: "petDetail"
}
}
},
{
type: "grid",
data: {
}
}
]
}
res.json(model)
})
app.listen(3000, () => {
console.log('Server is running...')
})