File tree Expand file tree Collapse file tree 6 files changed +55
-1
lines changed Expand file tree Collapse file tree 6 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -13,5 +13,6 @@ module.exports = {
13
13
'no-console' : 0 ,
14
14
'no-underscore-dangle' : 0 ,
15
15
'no-nested-ternary' : 0 ,
16
+ 'import/prefer-default-export' : 0 ,
16
17
} ,
17
18
} ;
Original file line number Diff line number Diff line change @@ -111,3 +111,16 @@ JS AMAZONA
111
111
8 . style div.rating, span and last span
112
112
9 . Edit HomeScreen
113
113
10 . Add div.product-rating and use Rating component
114
+ 13 . Product Screen
115
+ 1 . get product id from request
116
+ 2 . implement /api/product/: id api
117
+ 3 . send Ajax request to product api
118
+ 4 . create back to result link
119
+ 5 . create div.details with 3 columns
120
+ 6 . column 1 for product image
121
+ 7 . column 2 for product information
122
+ 8 . column 3 form product action
123
+ 9 . style .details and all columns
124
+ 10 . create add to cart button with add-button id
125
+ 11 . after_render() to add event to the button
126
+ 12 . redirect user to cart/: product_id
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ app.use(cors());
7
7
app . get ( '/api/products' , ( req , res ) => {
8
8
res . send ( data . products ) ;
9
9
} ) ;
10
+ app . get ( '/api/products/:id' , ( req , res ) => {
11
+ const product = data . products . find ( ( x ) => x . _id === req . params . id ) ;
12
+ if ( product ) {
13
+ res . send ( product ) ;
14
+ } else {
15
+ res . status ( 404 ) . send ( { message : 'Product Not Found!' } ) ;
16
+ }
17
+ } ) ;
10
18
11
19
app . listen ( 5000 , ( ) => {
12
20
console . log ( 'serve at http://localhost:5000' ) ;
Original file line number Diff line number Diff line change
1
+ import axios from 'axios' ;
2
+ import { apiUrl } from './config' ;
3
+
4
+ export const getProduct = async ( id ) => {
5
+ try {
6
+ const response = await axios ( {
7
+ url : `${ apiUrl } /api/products/${ id } ` ,
8
+ method : 'GET' ,
9
+ headers : {
10
+ 'Content-Type' : 'application/json' ,
11
+ } ,
12
+ } ) ;
13
+ if ( response . statusText !== 'OK' ) {
14
+ throw new Error ( response . data . message ) ;
15
+ }
16
+ return response . data ;
17
+ } catch ( err ) {
18
+ console . log ( err ) ;
19
+ return { error : err . response . data . message || err . message } ;
20
+ }
21
+ } ;
Original file line number Diff line number Diff line change
1
+ export const apiUrl = 'http://localhost:5000' ;
Original file line number Diff line number Diff line change
1
+ import { parseRequestUrl } from '../utils' ;
2
+ import { getProduct } from '../api' ;
3
+
1
4
const ProductScreen = {
2
- render : ( ) => '<div>ProductScreen</div>' ,
5
+ render : async ( ) => {
6
+ const request = parseRequestUrl ( ) ;
7
+ const product = await getProduct ( request . id ) ;
8
+ if ( product . error ) {
9
+ return `<div>${ product . error } </div>` ;
10
+ }
11
+ return `<h1>${ product . name } </h1>` ;
12
+ } ,
3
13
} ;
4
14
export default ProductScreen ;
You can’t perform that action at this time.
0 commit comments