-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cartify_Ecommerce_Guide.html
2557 lines (2544 loc) · 330 KB
/
Cartify_Ecommerce_Guide.html
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="generator" content="pandoc">
<meta name="description" content="">
<title>Cartify_Ecommerce_Guide</title>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="https://maxcdn.bootstrapcdn.com/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="https://mushiyo.github.io/pandoc-toc-sidebar/css/dashboard.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">.sidebar ul{padding-left: 10px;} .sidebar{background-color: #dadada;}</style>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div id="sidebar" class="col-sm-3 col-md-2 sidebar">
<!--<ul class="nav nav-sidebar">
<li class="active"><a href="#">Overview <span class="sr-only">(current)</span></a></li>
</ul>-->
<ul>
<li><a href="#cartify-ecommerce-guide"
id="toc-cartify-ecommerce-guide">Cartify Ecommerce Guide</a>
<ul>
<li><a href="#introduction"
id="toc-introduction">Introduction</a>
<ul>
<li><a href="#release-plan" id="toc-release-plan">Release
Plan</a></li>
</ul></li>
</ul></li>
<li><a href="#backend-1.0"
id="toc-backend-1.0"><strong>Backend 1.0</strong></a>
<ul>
<li><a href="#database" id="toc-database">Database</a></li>
<li><a href="#productcategory"
id="toc-productcategory">ProductCategory</a></li>
<li><a href="#product" id="toc-product">Product</a></li>
<li><a href="#spring-rest-cors-config"
id="toc-spring-rest-cors-config">Spring REST, CORS
Config</a></li>
<li><a href="#endpoints" id="toc-endpoints">Endpoints</a></li>
</ul></li>
<li><a href="#frontend-1.0"
id="toc-frontend-1.0"><strong>Frontend 1.0</strong></a>
<ul>
<li><a href="#setup" id="toc-setup">Setup</a></li>
<li><a href="#productservice"
id="toc-productservice">ProductService</a></li>
<li><a href="#product-list-component"
id="toc-product-list-component">product-list
Component</a></li>
</ul></li>
<li><a href="#release-2.0"
id="toc-release-2.0"><strong>Release 2.0</strong></a>
<ul>
<li><a href="#online-shop-template-integration"
id="toc-online-shop-template-integration">Online Shop Template
Integration</a></li>
<li><a href="#findbycategory"
id="toc-findbycategory">FindByCategory</a></li>
<li><a href="#findbycategory-dynamically"
id="toc-findbycategory-dynamically">FindByCategory
Dynamically</a></li>
<li><a href="#searchproduct-by-keyword"
id="toc-searchproduct-by-keyword">SearchProduct by
Keyword</a></li>
<li><a href="#product-detail-page"
id="toc-product-detail-page"><strong>Product Detail
Page</strong></a></li>
<li><a href="#pagination"
id="toc-pagination"><strong>Pagination</strong></a></li>
<li><a href="#shopping-cart"
id="toc-shopping-cart"><strong>Shopping Cart</strong></a>
<ul>
<li><a href="#cart-status-component"
id="toc-cart-status-component">Cart Status Component</a></li>
<li><a href="#cart-detail-list"
id="toc-cart-detail-list"><strong>Cart-Detail
List</strong></a></li>
</ul></li>
<li><a href="#checkout-form"
id="toc-checkout-form"><strong>Checkout Form</strong></a>
<ul>
<li><a href="#form-layout" id="toc-form-layout">Form
Layout</a></li>
<li><a href="#populate-date-dropdowns"
id="toc-populate-date-dropdowns"><strong>Populate Date
Dropdowns</strong></a></li>
<li><a href="#address-dropdowns--backend"
id="toc-address-dropdowns--backend">Address Dropdowns-
Backend</a></li>
<li><a href="#address-dropdowns--frontend"
id="toc-address-dropdowns--frontend">Address Dropdowns-
FrontEnd</a></li>
<li><a href="#form-validation"
id="toc-form-validation"><strong>Form
Validation</strong></a></li>
<li><a href="#review-cart-totals"
id="toc-review-cart-totals">Review Cart Totals</a></li>
</ul></li>
<li><a href="#save-the-order"
id="toc-save-the-order"><strong>Save the Order</strong></a>
<ul>
<li><a href="#saveorder-to-db--backend"
id="toc-saveorder-to-db--backend">SaveOrder to DB-
Backend</a></li>
<li><a href="#saveorder-to-db--frontend"
id="toc-saveorder-to-db--frontend">SaveOrder to DB-
Frontend</a></li>
</ul></li>
</ul></li>
<li><a href="#release-3.0" id="toc-release-3.0">Release
3.0</a>
<ul>
<li><a href="#login-logout-functionality"
id="toc-login-logout-functionality">Login-Logout
Functionality</a></li>
</ul></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 id="cartify-ecommerce-guide">Cartify Ecommerce Guide</h1>
<p><strong><a href="https://cartify-sg.vercel.app">Live
Link</a></strong></p>
<p><img
src="https://img.shields.io/badge/java-%23ED8B00.svg?style=for-the-badge&logo=java&logoColor=white"
alt="Java" /> <img
src="https://img.shields.io/badge/spring-%236DB33F.svg?style=for-the-badge&logo=spring&logoColor=white"
alt="Spring" /> <img
src="https://img.shields.io/badge/angular-%23DD0031.svg?style=for-the-badge&logo=angular&logoColor=white"
alt="Angular" /><img
src="https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white"
alt="TypeScript" /> <img
src="https://img.shields.io/badge/Cockroach%20Labs-6933FF?style=for-the-badge&logo=Cockroach%20Labs&logoColor=white"
alt="CockroachLabs" /> <img
src="https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white"
alt="Postgres" /> <img
src="https://img.shields.io/badge/vercel-%23000000.svg?style=for-the-badge&logo=vercel&logoColor=white"
alt="Vercel" /> <img
src="https://img.shields.io/badge/heroku-%23430098.svg?style=for-the-badge&logo=heroku&logoColor=white"
alt="Heroku" /> <img
src="https://img.shields.io/badge/bootstrap-%23563D7C.svg?style=for-the-badge&logo=bootstrap&logoColor=white"
alt="Bootstrap" /></p>
<figure>
<img src="cartify-ui/src/assets/images/logo.png" alt="Cartify Logo" />
<figcaption aria-hidden="true">Cartify Logo</figcaption>
</figure>
<h2 id="introduction">Introduction</h2>
<p>Download the Source Code and PDF Files</p>
<p><strong>Download Source Code:</strong> <a
href="https://github.com/darbyluv2code/fullstack-angular-and-springboot">https://github.com/darbyluv2code/fullstack-angular-and-springboot</a></p>
<p><strong>Download PDF Files</strong> : All slides which are shown
during the course are available also as a reference and can be
downloaded here:</p>
<p><a
href="http://www.luv2code.com/download-full-stack-angular-and-springboot-pdf-slides">http://www.luv2code.com/download-full-stack-angular-and-springboot-pdf-slides</a></p>
<p><strong>Design Requirements - Backend</strong></p>
<ul>
<li>Show a list of products</li>
<li>Add products to shopping cart (CRUD)</li>
<li>Shopping cart check out</li>
<li>User login/logout security</li>
<li>Track previous orders for logged in users</li>
</ul>
<h3 id="release-plan">Release Plan</h3>
<ul>
<li><strong>Release 1.0</strong>
<ul>
<li><strong>Show a list of products</strong></li>
</ul></li>
<li><strong>Release 2.0</strong>
<ul>
<li><strong>Add products to shopping cart (CRUD)</strong></li>
<li><strong>Shopping cart check out</strong></li>
</ul></li>
<li><strong>Release 3.0</strong>
<ul>
<li><strong>User login/logout security</strong></li>
<li><strong>Track previous orders for logged in users</strong></li>
</ul></li>
</ul>
<p><strong>Release 2.0 - Plan</strong></p>
<ul>
<li><p>Online Shop Template Integration</p></li>
<li><p>Search for products by category</p></li>
<li><p>Search for products by text box</p></li>
<li><p>Master / detail view of products</p></li>
<li><p>Pagination support for products</p></li>
<li><p>Add products to shopping cart (CRUD)</p></li>
<li><p>Shopping cart check out</p></li>
</ul>
<hr />
<h1 id="backend-1.0"><strong>Backend 1.0</strong></h1>
<p><strong>Development Process Backend - Release 1.0</strong></p>
<ol type="1">
<li>Set up the database tables</li>
<li>Create a Spring Boot starter project (start.spring.io) with
Dependencies :
<code>web,data-rest,data-jpa,postgresql,lombok</code></li>
<li>Develop the Entities: Product and ProductCategory</li>
<li>Create REST APIs with Spring Data JPA Repositories and Spring Data
REST</li>
<li>Add CrossOrigin support to Spring Boot app</li>
</ol>
<h3 id="database">Database</h3>
<p>We can connect postgres database from windows command line /
powershell using below command</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">cockroach</span> sql <span class="at">--url</span> <span class="st">"postgresql://swarnadeep:<<Password_here>>@free-tier12.aws-ap-south-1.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full&options=--cluster%3Dswarna-db-200"</span></span></code></pre></div>
<p><strong>SELECT queries to check data</strong></p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode sql"><code class="sourceCode sql"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">select</span> <span class="op">*</span> <span class="kw">from</span> <span class="ot">"cartify_ecommerce"</span>.product_category pc ;</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="kw">select</span> <span class="op">*</span> <span class="kw">from</span> <span class="ot">"cartify_ecommerce"</span>.product p ;</span></code></pre></div>
<p><strong>Insert Data in DB</strong></p>
<div class="sourceCode" id="cb3"><pre
class="sourceCode sql"><code class="sourceCode sql"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">INSERT</span> <span class="kw">INTO</span> <span class="ot">"cartify_ecommerce"</span>.product_category(<span class="kw">id</span>, category_name) <span class="kw">VALUES</span> (nextval(<span class="st">'cartify_ecommerce.pc_seq'</span>), <span class="st">'BOOKS'</span>);</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="kw">INSERT</span> <span class="kw">INTO</span> <span class="ot">"cartify_ecommerce"</span>.product (<span class="kw">id</span>, sku, name, description, image_url, active, units_in_stock, unit_price, category_id, date_created)</span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="kw">VALUES</span> (nextval(<span class="st">'cartify_ecommerce.product_seq'</span>), <span class="st">'BOOK-TECH-1000'</span>, <span class="st">'JavaScript - The Fun Parts'</span>, <span class="st">'Learn JavaScript'</span>,</span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="st">'assets/images/products/placeholder.png'</span> ,<span class="st">'1'</span>,<span class="dv">100</span>,<span class="fl">19.99</span>,<span class="dv">1</span>, NOW());</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="kw">INSERT</span> <span class="kw">INTO</span> <span class="ot">"cartify_ecommerce"</span>.product (<span class="kw">id</span>, sku, name, description, image_url, active, units_in_stock, unit_price, category_id, date_created)</span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="kw">VALUES</span> (nextval(<span class="st">'cartify_ecommerce.product_seq'</span>), <span class="st">'BOOK-TECH-1001'</span>, <span class="st">'Spring Framework Tutorial'</span>, <span class="st">'Learn Spring'</span>,</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="st">'assets/images/products/placeholder.png'</span> ,<span class="st">'1'</span>,<span class="dv">100</span>,<span class="fl">29.99</span>,<span class="dv">1</span>, NOW());</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="kw">INSERT</span> <span class="kw">INTO</span> <span class="ot">"cartify_ecommerce"</span>.product (<span class="kw">id</span>, sku, name, description, image_url, active, units_in_stock, unit_price, category_id, date_created)</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="kw">VALUES</span> (nextval(<span class="st">'cartify_ecommerce.product_seq'</span>), <span class="st">'BOOK-TECH-1002'</span>, <span class="st">'Kubernetes - Deploying Containers'</span>, <span class="st">'Learn Kubernetes'</span>,</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="st">'assets/images/products/placeholder.png'</span> ,<span class="st">'1'</span>,<span class="dv">100</span>,<span class="fl">24.99</span>,<span class="dv">1</span>, NOW());</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a><span class="kw">INSERT</span> <span class="kw">INTO</span> <span class="ot">"cartify_ecommerce"</span>.product (<span class="kw">id</span>, sku, name, description, image_url, active, units_in_stock, unit_price, category_id, date_created)</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a><span class="kw">VALUES</span> (nextval(<span class="st">'cartify_ecommerce.product_seq'</span>), <span class="st">'BOOK-TECH-1003'</span>, <span class="st">'Internet of Things (IoT) - Getting Started'</span>, <span class="st">'Learn IoT'</span>,</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a><span class="st">'assets/images/products/placeholder.png'</span> ,<span class="st">'1'</span>,<span class="dv">100</span>,<span class="fl">29.99</span>,<span class="dv">1</span>, NOW());</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a><span class="kw">INSERT</span> <span class="kw">INTO</span> <span class="ot">"cartify_ecommerce"</span>.product (<span class="kw">id</span>, sku, name, description, image_url, active, units_in_stock, unit_price, category_id, date_created)</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a><span class="kw">VALUES</span> (nextval(<span class="st">'cartify_ecommerce.product_seq'</span>), <span class="st">'BOOK-TECH-1004'</span>, <span class="st">'The Go Programming Language: A to Z'</span>, <span class="st">'Learn Go'</span>,</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="st">'assets/images/products/placeholder.png'</span> ,<span class="st">'1'</span>,<span class="dv">100</span>,<span class="fl">24.99</span>,<span class="dv">1</span>, NOW());</span></code></pre></div>
<p><strong><em>application.properties</em></strong></p>
<pre class="properties"><code>############### Spring REST ###############
spring.data.rest.base-path=/api
############### JPA config ###############
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
# spring.jpa.defer-datasource-initialization=true
spring.sql.init.mode=always
#spring.datasource.initialization-mode=always #--> Or for Spring Boot before 2.5:
############### Connecting to Postgres Database ###############
spring.datasource.url=jdbc:postgresql://free-tier12.aws-ap-south-1.cockroachlabs.cloud:26257/swarna-db-200.defaultdb
spring.datasource.username=swarnadeep
spring.datasource.password=<<Password_here>>
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect</code></pre>
<h3 id="productcategory">ProductCategory</h3>
<p>Designed ProductCategory entity and Repository</p>
<p><strong><em>ProductCategory.java</em></strong></p>
<div class="sourceCode" id="cb5"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="kw">package</span><span class="im"> com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">entity</span><span class="op">;</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="kw">...</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Entity</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="at">@Data</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="at">@Table</span><span class="op">(</span>name<span class="op">=</span><span class="st">"product_category"</span> <span class="op">,</span> schema <span class="op">=</span> <span class="st">"cartify_ecommerce"</span><span class="op">)</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> ProductCategory <span class="op">{</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="at">@Id</span></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="at">@SequenceGenerator</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"pc_seq"</span><span class="op">,</span>sequenceName <span class="op">=</span> <span class="st">"pc_seq"</span><span class="op">,</span>allocationSize <span class="op">=</span> <span class="dv">1</span><span class="op">,</span> schema <span class="op">=</span> <span class="st">"cartify_ecommerce"</span><span class="op">)</span></span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="at">@GeneratedValue</span><span class="op">(</span>strategy <span class="op">=</span> GenerationType<span class="op">.</span><span class="fu">SEQUENCE</span><span class="op">,</span> generator <span class="op">=</span> <span class="st">"pc_seq"</span><span class="op">)</span></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="dt">long</span> id<span class="op">;</span></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"category_name"</span><span class="op">)</span></span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">String</span> categoryName<span class="op">;</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a> <span class="at">@OneToMany</span><span class="op">(</span>cascade <span class="op">=</span> CascadeType<span class="op">.</span><span class="fu">ALL</span><span class="op">,</span> mappedBy <span class="op">=</span> <span class="st">"category"</span><span class="op">)</span></span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">Set</span><span class="op"><</span>Product<span class="op">></span> products<span class="op">;</span></span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p><strong><em>ProductCategoryRepo.java</em></strong></p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="kw">package</span><span class="im"> com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">repo</span><span class="op">;</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">data</span><span class="op">.</span><span class="im">rest</span><span class="op">.</span><span class="im">core</span><span class="op">.</span><span class="im">annotation</span><span class="op">.</span><span class="im">RepositoryRestResource</span><span class="op">;</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="co">//RepositoryRestResource will change default endpoint, so that we can access data using '/api/product-category'</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="at">@RepositoryRestResource</span><span class="op">(</span>collectionResourceRel <span class="op">=</span> <span class="st">"productCategory"</span><span class="op">,</span> path <span class="op">=</span> <span class="st">"product-category"</span><span class="op">)</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">interface</span> ProductCategoryRepo <span class="kw">extends</span> JpaRepository<span class="op"><</span>ProductCategory<span class="op">,</span> <span class="bu">Long</span><span class="op">></span> <span class="op">{</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h3 id="product">Product</h3>
<p><strong><em>Product.java</em></strong></p>
<div class="sourceCode" id="cb7"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="at">@Entity</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="at">@Data</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Table</span><span class="op">(</span>name<span class="op">=</span><span class="st">"product"</span> <span class="op">,</span> schema <span class="op">=</span> <span class="st">"cartify_ecommerce"</span><span class="op">)</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> Product <span class="op">{</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a> <span class="at">@Id</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="at">@SequenceGenerator</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"product_seq"</span><span class="op">,</span>sequenceName <span class="op">=</span> <span class="st">"product_seq"</span><span class="op">,</span>allocationSize <span class="op">=</span> <span class="dv">1</span><span class="op">,</span> schema <span class="op">=</span> <span class="st">"cartify_ecommerce"</span><span class="op">)</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="at">@GeneratedValue</span><span class="op">(</span>strategy <span class="op">=</span> GenerationType<span class="op">.</span><span class="fu">SEQUENCE</span><span class="op">,</span> generator <span class="op">=</span> <span class="st">"product_seq"</span><span class="op">)</span></span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">Long</span> id<span class="op">;</span></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a> <span class="at">@ManyToOne</span></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a> <span class="at">@JoinColumn</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"category_id"</span><span class="op">,</span> nullable <span class="op">=</span> <span class="kw">false</span><span class="op">)</span></span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> ProductCategory category<span class="op">;</span></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"sku"</span><span class="op">)</span></span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">String</span> sku<span class="op">;</span></span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"name"</span><span class="op">)</span></span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">String</span> name<span class="op">;</span></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"description"</span><span class="op">)</span></span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">String</span> description<span class="op">;</span></span>
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"unit_price"</span><span class="op">)</span></span>
<span id="cb7-26"><a href="#cb7-26" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">BigDecimal</span> unitPrice<span class="op">;</span></span>
<span id="cb7-27"><a href="#cb7-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-28"><a href="#cb7-28" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"image_url"</span><span class="op">)</span></span>
<span id="cb7-29"><a href="#cb7-29" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">String</span> imageUrl<span class="op">;</span></span>
<span id="cb7-30"><a href="#cb7-30" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-31"><a href="#cb7-31" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"active"</span><span class="op">)</span></span>
<span id="cb7-32"><a href="#cb7-32" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="dt">boolean</span> active<span class="op">;</span></span>
<span id="cb7-33"><a href="#cb7-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-34"><a href="#cb7-34" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"units_in_stock"</span><span class="op">)</span></span>
<span id="cb7-35"><a href="#cb7-35" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="dt">int</span> unitsInStock<span class="op">;</span></span>
<span id="cb7-36"><a href="#cb7-36" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-37"><a href="#cb7-37" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"date_created"</span><span class="op">)</span></span>
<span id="cb7-38"><a href="#cb7-38" aria-hidden="true" tabindex="-1"></a> <span class="at">@CreationTimestamp</span> <span class="co">// Created timestamp will be updated automatically</span></span>
<span id="cb7-39"><a href="#cb7-39" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">Date</span> dateCreated<span class="op">;</span></span>
<span id="cb7-40"><a href="#cb7-40" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-41"><a href="#cb7-41" aria-hidden="true" tabindex="-1"></a> <span class="at">@Column</span><span class="op">(</span>name <span class="op">=</span> <span class="st">"last_updated"</span><span class="op">)</span></span>
<span id="cb7-42"><a href="#cb7-42" aria-hidden="true" tabindex="-1"></a> <span class="at">@UpdateTimestamp</span> <span class="co">// Last updated timestamp will be updated automatically</span></span>
<span id="cb7-43"><a href="#cb7-43" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="bu">Date</span> lastUpdated<span class="op">;</span></span>
<span id="cb7-44"><a href="#cb7-44" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p><strong><em>ProductRepo.java</em></strong></p>
<div class="sourceCode" id="cb8"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="kw">package</span><span class="im"> com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">repo</span><span class="op">;</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="kw">...</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">interface</span> ProductRepo <span class="kw">extends</span> JpaRepository<span class="op"><</span>Product<span class="op">,</span> <span class="bu">Long</span><span class="op">>{</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h3 id="spring-rest-cors-config">Spring REST, CORS Config</h3>
<p>Here we used <code>spring-boot-starter-data-rest</code> to avoid
making Controller and let spring do that in background. By this, We can
use all REST methods without creating Controller.</p>
<p>In <strong><em>application.properties</em></strong>, we mentioned an
endpoint, where all backend api calls will be added after that</p>
<pre class="properties"><code>spring.data.rest.base-path=/api</code></pre>
<p><strong>Default Endpoints</strong></p>
<ul>
<li>By default, Spring Data REST will create endpoints based on entity
type
<ul>
<li>Simple pluralized form</li>
<li>First character of Entity type is lowercase</li>
<li>Then just adds an “s” to the entity</li>
</ul></li>
</ul>
<p><strong>For example,</strong></p>
<ul>
<li>if Repository will be :
<code>public interface ProductRepo extends JpaRepository<Product, Long></code></li>
<li>Then Endpoint will be : <code>/products</code></li>
<li><em>Spring Data REST will expose these endpoints for free!</em></li>
</ul>
<table>
<thead>
<tr class="header">
<th>HTTP Method</th>
<th>Endpoints</th>
<th>CRUD Action</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>POST</td>
<td>/products</td>
<td>Create a new product</td>
</tr>
<tr class="even">
<td>GET</td>
<td>/products</td>
<td>Read a list of products</td>
</tr>
<tr class="odd">
<td>GET</td>
<td>/products/{id}</td>
<td>Read a single product</td>
</tr>
<tr class="even">
<td>PUT</td>
<td>/products/{id}</td>
<td>Update an existing product</td>
</tr>
<tr class="odd">
<td>DELETE</td>
<td>/products/{id}</td>
<td>Delete an existing product</td>
</tr>
</tbody>
</table>
<p><strong>Disable access for specific endpoints</strong></p>
<p>Now, I want the REST API as READ-ONLY , so I will
<strong>disable</strong> access for POST , PUT and DELETE. So there is 2
options to do that.</p>
<ul>
<li><strong>Option 1</strong>: Don’t use Spring Data REST : Manually
create our own <span class="citation"
data-cites="RestController">@RestController</span> and <span
class="citation" data-cites="GetMapping">@GetMapping</span>
<ul>
<li>But we lose the Spring Data REST support for paging, sorting etc
:-(</li>
</ul></li>
<li><strong>Option 2</strong>: Use Spring Data REST. I will prefer this.
below is the config class for that.</li>
</ul>
<p>MyDataRestConfig.java</p>
<div class="sourceCode" id="cb10"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="kw">package</span><span class="im"> com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">config</span><span class="op">;</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">entity</span><span class="op">.</span><span class="im">Product</span><span class="op">;</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">entity</span><span class="op">.</span><span class="im">ProductCategory</span><span class="op">;</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">context</span><span class="op">.</span><span class="im">annotation</span><span class="op">.</span><span class="im">Configuration</span><span class="op">;</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">data</span><span class="op">.</span><span class="im">rest</span><span class="op">.</span><span class="im">core</span><span class="op">.</span><span class="im">config</span><span class="op">.</span><span class="im">RepositoryRestConfiguration</span><span class="op">;</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">data</span><span class="op">.</span><span class="im">rest</span><span class="op">.</span><span class="im">webmvc</span><span class="op">.</span><span class="im">config</span><span class="op">.</span><span class="im">RepositoryRestConfigurer</span><span class="op">;</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">http</span><span class="op">.</span><span class="im">HttpMethod</span><span class="op">;</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">web</span><span class="op">.</span><span class="im">servlet</span><span class="op">.</span><span class="im">config</span><span class="op">.</span><span class="im">annotation</span><span class="op">.</span><span class="im">CorsRegistry</span><span class="op">;</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a><span class="at">@Configuration</span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> MyDataRestConfig <span class="kw">implements</span> RepositoryRestConfigurer <span class="op">{</span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a> <span class="at">@Override</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> <span class="dt">void</span> <span class="fu">configureRepositoryRestConfiguration</span><span class="op">(</span>RepositoryRestConfiguration config<span class="op">,</span> CorsRegistry cors<span class="op">)</span> <span class="op">{</span></span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a> HttpMethod<span class="op">[]</span> theUnsupportedActions <span class="op">=</span> <span class="op">{</span>HttpMethod<span class="op">.</span><span class="fu">PUT</span><span class="op">,</span> HttpMethod<span class="op">.</span><span class="fu">POST</span><span class="op">,</span> HttpMethod<span class="op">.</span><span class="fu">DELETE</span><span class="op">,</span> HttpMethod<span class="op">.</span><span class="fu">PATCH</span><span class="op">};</span></span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a> <span class="co">// disable HTTP methods for Product: PUT, POST, DELETE and PATCH</span></span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a> config<span class="op">.</span><span class="fu">getExposureConfiguration</span><span class="op">()</span></span>
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">forDomainType</span><span class="op">(</span>Product<span class="op">.</span><span class="fu">class</span><span class="op">)</span></span>
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">withItemExposure</span><span class="op">((</span>metdata<span class="op">,</span> httpMethods<span class="op">)</span> <span class="op">-></span> httpMethods<span class="op">.</span><span class="fu">disable</span><span class="op">(</span>theUnsupportedActions<span class="op">))</span></span>
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">withCollectionExposure</span><span class="op">((</span>metdata<span class="op">,</span> httpMethods<span class="op">)</span> <span class="op">-></span> httpMethods<span class="op">.</span><span class="fu">disable</span><span class="op">(</span>theUnsupportedActions<span class="op">));</span></span>
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-24"><a href="#cb10-24" aria-hidden="true" tabindex="-1"></a> <span class="co">// disable HTTP methods for ProductCategory: PUT, POST, DELETE and PATCH</span></span>
<span id="cb10-25"><a href="#cb10-25" aria-hidden="true" tabindex="-1"></a> config<span class="op">.</span><span class="fu">getExposureConfiguration</span><span class="op">()</span></span>
<span id="cb10-26"><a href="#cb10-26" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">forDomainType</span><span class="op">(</span>ProductCategory<span class="op">.</span><span class="fu">class</span><span class="op">)</span></span>
<span id="cb10-27"><a href="#cb10-27" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">withItemExposure</span><span class="op">((</span>metdata<span class="op">,</span> httpMethods<span class="op">)</span> <span class="op">-></span> httpMethods<span class="op">.</span><span class="fu">disable</span><span class="op">(</span>theUnsupportedActions<span class="op">))</span></span>
<span id="cb10-28"><a href="#cb10-28" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">withCollectionExposure</span><span class="op">((</span>metdata<span class="op">,</span> httpMethods<span class="op">)</span> <span class="op">-></span> httpMethods<span class="op">.</span><span class="fu">disable</span><span class="op">(</span>theUnsupportedActions<span class="op">));</span></span>
<span id="cb10-29"><a href="#cb10-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-30"><a href="#cb10-30" aria-hidden="true" tabindex="-1"></a> <span class="co">// Added for CORS allow origin</span></span>
<span id="cb10-31"><a href="#cb10-31" aria-hidden="true" tabindex="-1"></a> cors<span class="op">.</span><span class="fu">addMapping</span><span class="op">(</span><span class="st">"/**"</span><span class="op">).</span><span class="fu">allowedOrigins</span><span class="op">(</span><span class="st">"*"</span><span class="op">)</span></span>
<span id="cb10-32"><a href="#cb10-32" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">allowedMethods</span><span class="op">(</span><span class="st">"GET"</span><span class="op">,</span> <span class="st">"POST"</span><span class="op">,</span> <span class="st">"PUT"</span><span class="op">,</span> <span class="st">"DELETE"</span><span class="op">,</span> <span class="st">"OPTIONS"</span><span class="op">)</span></span>
<span id="cb10-33"><a href="#cb10-33" aria-hidden="true" tabindex="-1"></a> <span class="co">// .allowCredentials(false).maxAge(3600)</span></span>
<span id="cb10-34"><a href="#cb10-34" aria-hidden="true" tabindex="-1"></a> <span class="op">;</span></span>
<span id="cb10-35"><a href="#cb10-35" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb10-36"><a href="#cb10-36" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p><strong>CorsConfig (Will not work for Spring Rest)</strong></p>
<p><strong><em>CorsConfig.java</em></strong> - To allow frontend domain
fetch values from backend.</p>
<div class="sourceCode" id="cb11"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co">// package com.swarna.cartify.config;</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="co">// ...</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="co">// @Configuration</span></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="co">// public class CorsConfig implements WebMvcConfigurer{</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="co">// @Override</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a><span class="co">// public void addCorsMappings(CorsRegistry registry) {</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="co">// // WebMvcConfigurer.super.addCorsMappings(registry);</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a><span class="co">// // registry.addMapping("/**").allowedOrigins(frontendURL)</span></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a><span class="co">// registry.addMapping("/**").allowedOrigins("*")</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a><span class="co">// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS");</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a><span class="co">// }</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a><span class="co">// }</span></span></code></pre></div>
<h3 id="endpoints">Endpoints</h3>
<pre class="http"><code>http://localhost:8080/api/products -- To see all products
http://localhost:8080/api/products/1 -- To check single product
http://localhost:8080/api/product-category -- To check all categories </code></pre>
<hr />
<h1 id="frontend-1.0"><strong>Frontend 1.0</strong></h1>
<p><strong>Development Process Frontend - Release 1.0</strong></p>
<ol type="1">
<li>Create Angular project <code>ng new cartify-ui</code></li>
<li>Create Angular component for product-list</li>
<li>Develop TypeScript model class for Product
<code>ng g class common/product</code></li>
<li>Create Angular service to call REST APIs
<code>ng g s services/productService</code></li>
<li>Update Angular component to subscribe to data from Angular
service</li>
<li>Display the data in an HTML page</li>
</ol>
<h3 id="setup">Setup</h3>
<p><strong>Create Angular project Setup</strong></p>
<div class="sourceCode" id="cb13"><pre
class="sourceCode sh"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ng new TodoList</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cd Todolist</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> npm install bootstrap</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> npm install jquery</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> npm install @fortawesome/fontawesome-free</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a><span class="ex">--</span> Downloaded versions: <span class="st">"bootstrap"</span>: <span class="st">"^4.4.1"</span>, <span class="st">"jquery"</span>: <span class="st">"^3.6.0"</span>,</span></code></pre></div>
<p>Configure <code>angular.json</code> to activate bootstrap,
Font-awesome and jquery</p>
<div class="sourceCode" id="cb14"><pre
class="sourceCode json"><code class="sourceCode json"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="er">"architect":</span> <span class="fu">{</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">"build"</span><span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">"builder"</span><span class="fu">:</span> <span class="st">"@angular-devkit/build-angular:browser"</span><span class="fu">,</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">"options"</span><span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">"outputPath"</span><span class="fu">:</span> <span class="st">"dist/course-api-ui"</span><span class="fu">,</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a> <span class="dt">"index"</span><span class="fu">:</span> <span class="st">"src/index.html"</span><span class="fu">,</span></span>
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a> <span class="dt">"main"</span><span class="fu">:</span> <span class="st">"src/main.ts"</span><span class="fu">,</span></span>
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">"polyfills"</span><span class="fu">:</span> <span class="st">"src/polyfills.ts"</span><span class="fu">,</span></span>
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a> <span class="dt">"tsConfig"</span><span class="fu">:</span> <span class="st">"tsconfig.app.json"</span><span class="fu">,</span></span>
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a> <span class="dt">"assets"</span><span class="fu">:</span> <span class="ot">[</span></span>
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a> <span class="st">"src/favicon.ico"</span><span class="ot">,</span></span>
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a> <span class="st">"src/assets"</span></span>
<span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a> <span class="ot">]</span><span class="fu">,</span></span>
<span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a> <span class="dt">"styles"</span><span class="fu">:</span> <span class="ot">[</span></span>
<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a> <span class="st">"src/styles.css"</span><span class="ot">,</span></span>
<span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a> <span class="st">"./node_modules/bootstrap/dist/css/bootstrap.min.css"</span><span class="ot">,</span></span>
<span id="cb14-17"><a href="#cb14-17" aria-hidden="true" tabindex="-1"></a> <span class="st">"./node_modules/@fortawesome/fontawesome-free/css/all.min.css"</span></span>
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true" tabindex="-1"></a> <span class="ot">]</span><span class="fu">,</span></span>
<span id="cb14-19"><a href="#cb14-19" aria-hidden="true" tabindex="-1"></a> <span class="dt">"scripts"</span><span class="fu">:</span> <span class="ot">[</span></span>
<span id="cb14-20"><a href="#cb14-20" aria-hidden="true" tabindex="-1"></a> <span class="st">"./node_modules/jquery/dist/jquery.min.js"</span><span class="ot">,</span></span>
<span id="cb14-21"><a href="#cb14-21" aria-hidden="true" tabindex="-1"></a> <span class="st">"./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"</span></span>
<span id="cb14-22"><a href="#cb14-22" aria-hidden="true" tabindex="-1"></a> <span class="ot">]</span></span>
<span id="cb14-23"><a href="#cb14-23" aria-hidden="true" tabindex="-1"></a> <span class="fu">},</span></span></code></pre></div>
<p>Included font-awesome icons in
<strong><em>styles.css</em></strong></p>
<div class="sourceCode" id="cb15"><pre
class="sourceCode css"><code class="sourceCode css"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="im">@import</span> <span class="fu">url(</span><span class="st">'https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'</span><span class="fu">)</span><span class="op">;</span></span></code></pre></div>
<p><strong><em>Product.ts</em> - Product model class</strong></p>
<div class="sourceCode" id="cb16"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> Product {</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> sku<span class="op">:</span> <span class="dt">string</span><span class="op">;</span></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> name<span class="op">:</span> <span class="dt">string</span><span class="op">;</span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> description<span class="op">:</span> <span class="dt">string</span><span class="op">;</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> unitPrice<span class="op">:</span> <span class="dt">number</span><span class="op">;</span></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> imageUrl<span class="op">:</span> <span class="dt">string</span><span class="op">;</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a> active<span class="op">:</span> <span class="dt">boolean</span><span class="op">;</span></span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a> unitsInStock<span class="op">:</span> <span class="dt">number</span><span class="op">;</span></span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a> dateCreated<span class="op">:</span> <span class="bu">Date</span><span class="op">;</span></span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a> lastUpdate<span class="op">:</span> <span class="bu">Date</span><span class="op">;</span></span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<h3 id="productservice">ProductService</h3>
<p><strong><em>product.service.ts</em> - ProductService </strong></p>
<div class="sourceCode" id="cb17"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="op">...</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> ProductService {</span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span>(<span class="kw">private</span> http<span class="op">:</span> HttpClient) {}</span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> <span class="fu">getAllProducts</span>()<span class="op">:</span> Observable<span class="op"><</span>Product[]<span class="op">></span> {</span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="kw">this</span><span class="op">.</span><span class="at">http</span><span class="op">.</span><span class="fu">get</span><span class="op"><</span>GetResponse<span class="op">></span>(<span class="vs">`</span><span class="sc">${</span>environment<span class="op">.</span><span class="at">apiServerUrl</span><span class="sc">}</span><span class="vs">/products`</span>)<span class="op">.</span><span class="fu">pipe</span>(</span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">map</span>(response <span class="kw">=></span> response<span class="op">.</span><span class="at">_embedded</span><span class="op">.</span><span class="at">products</span>)) <span class="op">;</span></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a><span class="kw">interface</span> GetResponse {</span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a> _embedded <span class="op">:</span> {</span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a> products <span class="op">:</span> Product[]<span class="op">;</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<h3 id="product-list-component">product-list Component</h3>
<p><strong><em>app.component.html</em></strong></p>
<div class="sourceCode" id="cb18"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"container"</span><span class="kw">></span></span>
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> <span class="kw"><h1</span> <span class="er">class</span><span class="ot">=</span><span class="st">"mt-3 mb-3"</span><span class="kw">></span>Products<span class="kw"></h1></span></span>
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="kw"><app-product-list></app-product-list></span></span>
<span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a><span class="kw"></div></span></span></code></pre></div>
<p><strong><em>product-list.component.html</em></strong></p>
<div class="sourceCode" id="cb19"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="kw"><table</span> <span class="er">class</span><span class="ot">=</span><span class="st">"table table-striped"</span><span class="kw">></span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="kw"><thead></span></span>
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="kw"><tr</span> <span class="er">class</span><span class="ot">=</span><span class="st">"table-dark"</span><span class="kw">></span></span>
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a> <span class="co"><!-- <th scope="col">#</th> --></span></span>
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a> <span class="kw"><th></th></span></span>
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a> <span class="kw"><th</span> <span class="er">scope</span><span class="ot">=</span><span class="st">"col"</span><span class="kw">></span>Name<span class="kw"></th></span></span>
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a> <span class="kw"><th</span> <span class="er">scope</span><span class="ot">=</span><span class="st">"col"</span><span class="kw">></span>Price<span class="kw"></th></span></span>
<span id="cb19-8"><a href="#cb19-8" aria-hidden="true" tabindex="-1"></a> <span class="kw"><th</span> <span class="er">scope</span><span class="ot">=</span><span class="st">"col"</span><span class="kw">></span>Units in Stock<span class="kw"></th></span></span>
<span id="cb19-9"><a href="#cb19-9" aria-hidden="true" tabindex="-1"></a> <span class="kw"></tr></span></span>
<span id="cb19-10"><a href="#cb19-10" aria-hidden="true" tabindex="-1"></a> <span class="kw"></thead></span></span>
<span id="cb19-11"><a href="#cb19-11" aria-hidden="true" tabindex="-1"></a> <span class="kw"><tbody></span></span>
<span id="cb19-12"><a href="#cb19-12" aria-hidden="true" tabindex="-1"></a> <span class="kw"><tr</span> <span class="er">*ngFor</span><span class="ot">=</span><span class="st">"let product of products"</span><span class="kw">></span></span>
<span id="cb19-13"><a href="#cb19-13" aria-hidden="true" tabindex="-1"></a> <span class="co"><!-- <th scope="row">{{product.}}</th> --></span></span>
<span id="cb19-14"><a href="#cb19-14" aria-hidden="true" tabindex="-1"></a> <span class="kw"><td</span> <span class="er">class</span><span class="ot">=</span><span class="st">"align-middle"</span><span class="kw">><img</span> <span class="er">src</span><span class="ot">=</span><span class="st">"{{product.imageUrl}}"</span> <span class="er">height</span><span class="ot">=</span><span class="st">"50"</span> <span class="er">alt</span><span class="ot">=</span><span class="st">"image"</span><span class="kw">></td></span></span>
<span id="cb19-15"><a href="#cb19-15" aria-hidden="true" tabindex="-1"></a> <span class="kw"><td</span> <span class="er">class</span><span class="ot">=</span><span class="st">"align-middle"</span><span class="kw">></span>{{product.name}}<span class="kw"></td></span></span>
<span id="cb19-16"><a href="#cb19-16" aria-hidden="true" tabindex="-1"></a> <span class="kw"><td</span> <span class="er">class</span><span class="ot">=</span><span class="st">"align-middle"</span><span class="kw">></span>{{product.unitPrice | currency: 'USD'}}<span class="kw"></td></span></span>
<span id="cb19-17"><a href="#cb19-17" aria-hidden="true" tabindex="-1"></a> <span class="kw"><td</span> <span class="er">class</span><span class="ot">=</span><span class="st">"align-middle"</span><span class="kw">></span>{{product.unitsInStock}}<span class="kw"></td></span></span>
<span id="cb19-18"><a href="#cb19-18" aria-hidden="true" tabindex="-1"></a> <span class="kw"></tr></span></span>
<span id="cb19-19"><a href="#cb19-19" aria-hidden="true" tabindex="-1"></a> <span class="kw"></tbody></span></span>
<span id="cb19-20"><a href="#cb19-20" aria-hidden="true" tabindex="-1"></a><span class="kw"></table></span></span></code></pre></div>
<p><strong><em>product-list.component.ts</em></strong></p>
<div class="sourceCode" id="cb20"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> ProductListComponent <span class="kw">implements</span> OnInit {</span>
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a> products<span class="op">:</span> Product[]<span class="op">;</span></span>
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span>(<span class="kw">private</span> productService <span class="op">:</span>ProductService) { }</span>
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">ngOnInit</span>()<span class="op">:</span> <span class="dt">void</span> {</span>
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="fu">getAllProducts</span>()<span class="op">;</span></span>
<span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">getAllProducts</span>(){</span>
<span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">productService</span><span class="op">.</span><span class="fu">getAllProducts</span>()<span class="op">.</span><span class="fu">subscribe</span>(</span>
<span id="cb20-11"><a href="#cb20-11" aria-hidden="true" tabindex="-1"></a> data <span class="kw">=></span> { <span class="kw">this</span><span class="op">.</span><span class="at">products</span> <span class="op">=</span> data })</span>
<span id="cb20-12"><a href="#cb20-12" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb20-13"><a href="#cb20-13" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p><strong>Snapshot of Release 1.0</strong></p>
<p><img src="images/release1.0.png" alt="release1.0" style="zoom:67%;" /></p>
<hr />
<h1 id="release-2.0"><strong>Release 2.0</strong></h1>
<ul>
<li><p>Online Shop Template Integration</p></li>
<li><p>Search for products by category</p></li>
<li><p>Search for products by text box</p></li>
<li><p>Master / detail view of products</p></li>
<li><p>Pagination support for products</p></li>
<li><p>Add products to shopping cart (CRUD)</p></li>
<li><p>Shopping cart check out</p></li>
</ul>
<h3 id="online-shop-template-integration">Online Shop Template
Integration</h3>
<p><strong>Development Process</strong></p>
<ol type="1">
<li><p>Install Bootstrap and Fontawesome CSS styles locally using npm:
<code>npm i bootstrap@4.4.1</code> and
<code>npm i @fortawesome/fontawesome-free</code> .</p>
<p>Then add css and JS paths (Demonstrated Above Frontend 1.0 >
Setup)</p></li>
<li><p>Add local custom CSS styles to Angular src/styles.css
file</p></li>
<li><p>Integrate template files into Angular app</p></li>
<li><p>Add support for icons and logos</p></li>
<li><p>Enhance our application with product images</p></li>
</ol>
<p><strong><em>app.component.html</em></strong> - writing only headlines
here. For detail code, visit GitHub</p>
<div class="sourceCode" id="cb21"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="co"><!-- MENU SIDEBAR--></span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a><span class="co"><!-- HEADER DESKTOP--></span></span>
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a><span class="co"><!-- MAIN CONTENT of product list--></span></span>
<span id="cb21-6"><a href="#cb21-6" aria-hidden="true" tabindex="-1"></a><span class="kw"><app-product-list></app-product-list></span></span>
<span id="cb21-7"><a href="#cb21-7" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb21-8"><a href="#cb21-8" aria-hidden="true" tabindex="-1"></a><span class="co"><!-- FOOTER STARTS --></span></span></code></pre></div>
<p><strong><em>product-list.component.html</em></strong></p>
<div class="sourceCode" id="cb22"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"main-content"</span><span class="kw">></span></span>
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a> <span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"section-content section-content-p30"</span><span class="kw">></span></span>
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"container-fluid"</span><span class="kw">></span></span>
<span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a> <span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"row"</span><span class="kw">></span></span>
<span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb22-6"><a href="#cb22-6" aria-hidden="true" tabindex="-1"></a> <span class="co"><!-- Loop over the products --></span></span>
<span id="cb22-7"><a href="#cb22-7" aria-hidden="true" tabindex="-1"></a> <span class="kw"><div</span> <span class="er">*ngFor</span><span class="ot">=</span><span class="st">"let product of products"</span> <span class="er">class</span><span class="ot">=</span><span class="st">"col-md-3"</span><span class="kw">></span></span>
<span id="cb22-8"><a href="#cb22-8" aria-hidden="true" tabindex="-1"></a> <span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"product-box"</span><span class="kw">></span></span>
<span id="cb22-9"><a href="#cb22-9" aria-hidden="true" tabindex="-1"></a> <span class="kw"><a</span> <span class="er">href</span><span class="ot">=</span><span class="st">"product-detail.html"</span><span class="kw">></span></span>
<span id="cb22-10"><a href="#cb22-10" aria-hidden="true" tabindex="-1"></a> <span class="kw"><img</span> <span class="er">src</span><span class="ot">=</span><span class="st">"{{ product.imageUrl }}"</span> <span class="er">class</span><span class="ot">=</span><span class="st">"img-responsive"</span><span class="kw">></span></span>
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a> <span class="kw"></a></span></span>
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a> <span class="kw"><a</span> <span class="er">href</span><span class="ot">=</span><span class="st">"product-detail.html"</span><span class="kw">></span></span>
<span id="cb22-13"><a href="#cb22-13" aria-hidden="true" tabindex="-1"></a> <span class="kw"><h1></span>{{ product.name }}<span class="kw"></h1></span></span>
<span id="cb22-14"><a href="#cb22-14" aria-hidden="true" tabindex="-1"></a> <span class="kw"></a></span></span>
<span id="cb22-15"><a href="#cb22-15" aria-hidden="true" tabindex="-1"></a> <span class="kw"><h2></span>{{ product.description }} <span class="kw"></h2></span></span>
<span id="cb22-16"><a href="#cb22-16" aria-hidden="true" tabindex="-1"></a> <span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"price"</span><span class="kw">></span>{{ product.unitPrice | currency: 'USD' }}<span class="kw"></div></span></span>
<span id="cb22-17"><a href="#cb22-17" aria-hidden="true" tabindex="-1"></a> <span class="kw"><a</span> <span class="er">href</span><span class="ot">=</span><span class="st">"#"</span> <span class="er">class</span><span class="ot">=</span><span class="st">"primary-btn"</span><span class="kw">></span>Add to cart<span class="kw"></a></span></span>
<span id="cb22-18"><a href="#cb22-18" aria-hidden="true" tabindex="-1"></a> <span class="kw"></div></span></span>
<span id="cb22-19"><a href="#cb22-19" aria-hidden="true" tabindex="-1"></a> <span class="kw"></div></span></span>
<span id="cb22-20"><a href="#cb22-20" aria-hidden="true" tabindex="-1"></a> <span class="kw"></div></span></span>
<span id="cb22-21"><a href="#cb22-21" aria-hidden="true" tabindex="-1"></a> <span class="kw"></div></span></span>
<span id="cb22-22"><a href="#cb22-22" aria-hidden="true" tabindex="-1"></a> <span class="kw"></div></span></span>
<span id="cb22-23"><a href="#cb22-23" aria-hidden="true" tabindex="-1"></a><span class="kw"></div></span></span></code></pre></div>
<blockquote>
<p>Spring REST gives 20 records by default , wheather there is any
number of records or not</p>
<p>We need to use
<strong><code>${environment.apiServerUrl}/products?size=100</code> to
get all 100 products in frontend service ts file.</strong></p>
</blockquote>
<p>Snapshot</p>
<p><img src="images/feature2.0_1.png" alt="feature2.0_1" style="zoom:67%;" /></p>
<h3 id="findbycategory">FindByCategory</h3>
<p><strong>Development Process</strong></p>
<ol type="1">
<li><p>Define routes and Configure Router based on our routes , Define
the Router Outlet</p></li>
<li><p>Set up Router Links to pass category id param</p></li>
<li><p>Enhance ProductListComponent to read category id param</p></li>
<li><p>Modify Spring Boot app - REST Repository needs new
method</p></li>
<li><p>Update Angular Service to call new URL on Spring Boot
app</p></li>
</ol>
<h4 id="backend--findbycategory">Backend- FindByCategory</h4>
<p><strong><em>ProductRepo.java</em></strong></p>
<div class="sourceCode" id="cb23"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="kw">package</span><span class="im"> com</span><span class="op">.</span><span class="im">swarna</span><span class="op">.</span><span class="im">cartify</span><span class="op">.</span><span class="im">repo</span><span class="op">;</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">data</span><span class="op">.</span><span class="im">domain</span><span class="op">.</span><span class="im">Page</span><span class="op">;</span></span>
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">org</span><span class="op">.</span><span class="im">springframework</span><span class="op">.</span><span class="im">data</span><span class="op">.</span><span class="im">domain</span><span class="op">.</span><span class="im">Pageable</span><span class="op">;</span></span>
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="kw">...</span></span>
<span id="cb23-5"><a href="#cb23-5" aria-hidden="true" tabindex="-1"></a><span class="at">@RepositoryRestResource</span></span>
<span id="cb23-6"><a href="#cb23-6" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">interface</span> ProductRepo <span class="kw">extends</span> JpaRepository<span class="op"><</span>Product<span class="op">,</span> <span class="bu">Long</span><span class="op">>{</span></span>
<span id="cb23-7"><a href="#cb23-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb23-8"><a href="#cb23-8" aria-hidden="true" tabindex="-1"></a> <span class="co">//API will be => http://localhost:8080/api/products/search/findByCategoryId/?id=2</span></span>
<span id="cb23-9"><a href="#cb23-9" aria-hidden="true" tabindex="-1"></a> Page<span class="op"><</span>Product<span class="op">></span> <span class="fu">findByCategoryId</span><span class="op">(</span><span class="at">@RequestParam</span><span class="op">(</span><span class="st">"id"</span><span class="op">)</span> <span class="bu">Long</span> id<span class="op">,</span> <span class="bu">Pageable</span> pageable<span class="op">);</span></span>
<span id="cb23-10"><a href="#cb23-10" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h4 id="frontend--findbycategory">Frontend- FindByCategory</h4>
<p><strong>Adding Angular Routing first</strong></p>
<p><strong><em>app-routing.module.ts</em></strong></p>
<div class="sourceCode" id="cb24"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> { NgModule } <span class="im">from</span> <span class="st">'@angular/core'</span><span class="op">;</span></span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> { RouterModule<span class="op">,</span> Routes } <span class="im">from</span> <span class="st">'@angular/router'</span><span class="op">;</span></span>
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> { ProductListComponent } <span class="im">from</span> <span class="st">'./components/product-list/product-list.component'</span><span class="op">;</span></span>
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a><span class="kw">const</span> routes<span class="op">:</span> Routes <span class="op">=</span> [</span>
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a> { path<span class="op">:</span> <span class="st">'category/:id'</span><span class="op">,</span> component<span class="op">:</span> ProductListComponent }<span class="op">,</span></span>
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a> { path<span class="op">:</span> <span class="st">'category'</span><span class="op">,</span> component<span class="op">:</span> ProductListComponent }<span class="op">,</span></span>
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a> { path<span class="op">:</span> <span class="st">'products'</span><span class="op">,</span> component<span class="op">:</span> ProductListComponent }<span class="op">,</span></span>
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a> { path<span class="op">:</span> <span class="st">''</span><span class="op">,</span> redirectTo<span class="op">:</span> <span class="st">'/products'</span><span class="op">,</span> pathMatch<span class="op">:</span> <span class="st">'full'</span> }<span class="op">,</span></span>
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a> { path<span class="op">:</span> <span class="st">'**'</span><span class="op">,</span> redirectTo<span class="op">:</span> <span class="st">'/products'</span><span class="op">,</span> pathMatch<span class="op">:</span> <span class="st">'full'</span> }<span class="op">,</span></span>
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a>]<span class="op">;</span></span>
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true" tabindex="-1"></a>@<span class="fu">NgModule</span>({</span>
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true" tabindex="-1"></a> imports<span class="op">:</span> [RouterModule<span class="op">.</span><span class="fu">forRoot</span>(routes)]<span class="op">,</span></span>
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true" tabindex="-1"></a> exports<span class="op">:</span> [RouterModule]<span class="op">,</span></span>
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true" tabindex="-1"></a>})</span>
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> AppRoutingModule {}</span></code></pre></div>
<p><strong><em>app.module.ts</em></strong></p>
<div class="sourceCode" id="cb25"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> { AppRoutingModule } <span class="im">from</span> <span class="st">'./app-routing.module'</span><span class="op">;</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a><span class="op">...</span></span>
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a> imports<span class="op">:</span> [<span class="op">...</span></span>
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a> AppRoutingModule<span class="op">,</span></span>
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a> ]<span class="op">,</span></span></code></pre></div>
<p><strong><em>app.component.html</em></strong></p>
<div class="sourceCode" id="cb26"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>...</span>
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a> <span class="kw"><nav</span> <span class="er">class</span><span class="ot">=</span><span class="st">"navbar-sidebar"</span><span class="kw">></span></span>
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a> <span class="kw"><ul</span> <span class="er">class</span><span class="ot">=</span><span class="st">"list-unstyled navbar-list"</span><span class="kw">></span></span>
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a> <span class="kw"><li><a</span> <span class="er">routerLink</span><span class="ot">=</span><span class="st">"/category/1"</span> <span class="er">routerLinkActive</span><span class="ot">=</span><span class="st">"active-link"</span><span class="kw">></span>Books<span class="kw"></a></li></span></span>
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a> <span class="kw"><li><a</span> <span class="er">routerLink</span><span class="ot">=</span><span class="st">"/category/2"</span> <span class="er">routerLinkActive</span><span class="ot">=</span><span class="st">"active-link"</span><span class="kw">></span>Coffee Mugs<span class="kw"></a></li></span></span>
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a> <span class="kw"><li><a</span> <span class="er">routerLink</span><span class="ot">=</span><span class="st">"/category/3"</span> <span class="er">routerLinkActive</span><span class="ot">=</span><span class="st">"active-link"</span><span class="kw">></span>Mouse Pads<span class="kw"></a></li></span></span>
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a> <span class="kw"><li><a</span> <span class="er">routerLink</span><span class="ot">=</span><span class="st">"/category/4"</span> <span class="er">routerLinkActive</span><span class="ot">=</span><span class="st">"active-link"</span><span class="kw">></span>Luggage Tags<span class="kw"></a></li></span></span>
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a> ...</span>
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a> <span class="co"><!-- MAIN CONTENT--></span></span>
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a> <span class="kw"><router-outlet></router-outlet></span></span>
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a> <span class="co"><!-- </span><span class="re">END</span><span class="co"> MAIN CONTENT--></span></span></code></pre></div>
<p><strong><em>product.service.ts</em></strong></p>
<div class="sourceCode" id="cb27"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a><span class="op">...</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="fu">getProductsByCategory</span>(currentCategoryId<span class="op">:</span> <span class="dt">number</span>)<span class="op">:</span> Observable<span class="op"><</span>Product[]<span class="op">></span> {</span>
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="kw">this</span><span class="op">.</span><span class="at">http</span><span class="op">.</span><span class="fu">get</span><span class="op"><</span>GetResponse<span class="op">></span>(<span class="vs">`</span><span class="sc">${</span>environment<span class="op">.</span><span class="at">apiServerUrl</span><span class="sc">}</span><span class="vs">/products/search/findByCategoryId/?id=</span><span class="sc">${</span>currentCategoryId<span class="sc">}</span><span class="vs">`</span>)<span class="op">.</span><span class="fu">pipe</span>(</span>
<span id="cb27-4"><a href="#cb27-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">map</span>(response <span class="kw">=></span> response<span class="op">.</span><span class="at">_embedded</span><span class="op">.</span><span class="at">products</span>)</span>
<span id="cb27-5"><a href="#cb27-5" aria-hidden="true" tabindex="-1"></a> ) <span class="op">;</span></span>
<span id="cb27-6"><a href="#cb27-6" aria-hidden="true" tabindex="-1"></a><span class="op">...</span></span></code></pre></div>
<p><strong><em>product-list.component.ts</em></strong> - Fetching
Parameter from URL using Activated route and calling service method</p>
<div class="sourceCode" id="cb28"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> ProductListComponent <span class="kw">implements</span> OnInit {</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a> products<span class="op">:</span> Product[]<span class="op">;</span></span>
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a> currentCategoryId<span class="op">:</span> <span class="dt">number</span><span class="op">;</span></span>
<span id="cb28-4"><a href="#cb28-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-5"><a href="#cb28-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span>(<span class="kw">private</span> productService<span class="op">:</span> ProductService<span class="op">,</span> <span class="kw">private</span> route<span class="op">:</span> ActivatedRoute ) {}</span>
<span id="cb28-6"><a href="#cb28-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-7"><a href="#cb28-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">ngOnInit</span>()<span class="op">:</span> <span class="dt">void</span> {</span>
<span id="cb28-8"><a href="#cb28-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">route</span><span class="op">.</span><span class="at">paramMap</span><span class="op">.</span><span class="fu">subscribe</span>(() <span class="kw">=></span> {</span>
<span id="cb28-9"><a href="#cb28-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="fu">getAllProducts</span>()<span class="op">;</span></span>
<span id="cb28-10"><a href="#cb28-10" aria-hidden="true" tabindex="-1"></a> })<span class="op">;</span></span>
<span id="cb28-11"><a href="#cb28-11" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb28-12"><a href="#cb28-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-13"><a href="#cb28-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">getAllProducts</span>() {</span>
<span id="cb28-14"><a href="#cb28-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-15"><a href="#cb28-15" aria-hidden="true" tabindex="-1"></a> <span class="co">//check if "id" parameter is available</span></span>
<span id="cb28-16"><a href="#cb28-16" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> hascategoryId<span class="op">:</span> <span class="dt">boolean</span> <span class="op">=</span> <span class="kw">this</span><span class="op">.</span><span class="at">route</span><span class="op">.</span><span class="at">snapshot</span><span class="op">.</span><span class="at">paramMap</span><span class="op">.</span><span class="fu">has</span>(<span class="st">'id'</span>)<span class="op">;</span></span>
<span id="cb28-17"><a href="#cb28-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-18"><a href="#cb28-18" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span>(hascategoryId){</span>
<span id="cb28-19"><a href="#cb28-19" aria-hidden="true" tabindex="-1"></a> <span class="co">// get the "id" parameter and converting to number using "+" symbol</span></span>
<span id="cb28-20"><a href="#cb28-20" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">currentCategoryId</span> <span class="op">=</span> <span class="op">+</span><span class="kw">this</span><span class="op">.</span><span class="at">route</span><span class="op">.</span><span class="at">snapshot</span><span class="op">.</span><span class="at">paramMap</span><span class="op">.</span><span class="fu">get</span>(<span class="st">'id'</span>)<span class="op">;</span></span>
<span id="cb28-21"><a href="#cb28-21" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span>{</span>
<span id="cb28-22"><a href="#cb28-22" aria-hidden="true" tabindex="-1"></a> <span class="co">// if no category id available, default set to 1</span></span>
<span id="cb28-23"><a href="#cb28-23" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">currentCategoryId</span> <span class="op">=</span> <span class="dv">1</span><span class="op">;</span></span>
<span id="cb28-24"><a href="#cb28-24" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb28-25"><a href="#cb28-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb28-26"><a href="#cb28-26" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">productService</span><span class="op">.</span><span class="fu">getProductsByCategory</span>(<span class="kw">this</span><span class="op">.</span><span class="at">currentCategoryId</span>)<span class="op">.</span><span class="fu">subscribe</span>((data) <span class="kw">=></span> {</span>
<span id="cb28-27"><a href="#cb28-27" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">products</span> <span class="op">=</span> data<span class="op">;</span></span>
<span id="cb28-28"><a href="#cb28-28" aria-hidden="true" tabindex="-1"></a> })<span class="op">;</span></span>
<span id="cb28-29"><a href="#cb28-29" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb28-30"><a href="#cb28-30" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p>Snapshot</p>
<p><img src="images/feature2.0_findbyCategory.png" alt="feature2.0_findbyCategory" style="zoom:67%;" /></p>
<h3 id="findbycategory-dynamically">FindByCategory Dynamically</h3>
<p><strong>Development Process</strong></p>
<ol type="1">
<li><p>Modify Spring Boot app - Expose entity ids - Backend</p></li>
<li><p>Create a class: ProductCategory :
<code>ng g class common/product-category</code></p></li>
<li><p>Create new component for menu :
<code>ng g c components/product-category-menu</code></p></li>
<li><p>Enhance menu component to read data from product service</p></li>
<li><p>Update product service to call URL on Spring Boot app</p></li>
<li><p>In HTML, replace hard-coded links with menu component</p></li>
</ol>
<h4 id="backend---findbycategory-dynamic">Backend - FindByCategory
Dynamic</h4>
<p><strong>Goal :</strong></p>
<div class="sourceCode" id="cb29"><pre
class="sourceCode json"><code class="sourceCode json"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="er">API</span> <span class="er">:</span> <span class="er">https://cartify-ecommerce-fullstack.herokuapp.com/api/product-category</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="er">From</span> <span class="er">:</span> <span class="er">There</span> <span class="er">is</span> <span class="er">no</span> <span class="er">entity</span> <span class="er">id</span> <span class="er">at</span> <span class="er">the</span> <span class="er">productCategory</span> <span class="er">level,</span> <span class="er">so</span> <span class="er">no</span> <span class="er">easy</span> <span class="er">access</span></span>
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a><span class="fu">{</span></span>
<span id="cb29-5"><a href="#cb29-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">"_embedded"</span> <span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb29-6"><a href="#cb29-6" aria-hidden="true" tabindex="-1"></a> <span class="dt">"productCategory"</span> <span class="fu">:</span> <span class="ot">[</span> <span class="fu">{</span></span>
<span id="cb29-7"><a href="#cb29-7" aria-hidden="true" tabindex="-1"></a> <span class="dt">"categoryName"</span> <span class="fu">:</span> <span class="st">"Books"</span><span class="fu">,</span></span>
<span id="cb29-8"><a href="#cb29-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">"_links"</span> <span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb29-9"><a href="#cb29-9" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb29-10"><a href="#cb29-10" aria-hidden="true" tabindex="-1"></a><span class="er">To</span> <span class="er">this</span> <span class="fu">:</span> </span>
<span id="cb29-11"><a href="#cb29-11" aria-hidden="true" tabindex="-1"></a><span class="fu">{</span></span>
<span id="cb29-12"><a href="#cb29-12" aria-hidden="true" tabindex="-1"></a> <span class="dt">"_embedded"</span> <span class="fu">:</span> <span class="fu">{</span></span>
<span id="cb29-13"><a href="#cb29-13" aria-hidden="true" tabindex="-1"></a> <span class="dt">"productCategory"</span> <span class="fu">:</span> <span class="ot">[</span> <span class="fu">{</span></span>
<span id="cb29-14"><a href="#cb29-14" aria-hidden="true" tabindex="-1"></a> <span class="dt">"id"</span> <span class="fu">:</span> <span class="dv">1</span><span class="fu">,</span></span>
<span id="cb29-15"><a href="#cb29-15" aria-hidden="true" tabindex="-1"></a> <span class="dt">"categoryName"</span> <span class="fu">:</span> <span class="st">"Books"</span><span class="fu">,</span></span>
<span id="cb29-16"><a href="#cb29-16" aria-hidden="true" tabindex="-1"></a> </span></code></pre></div>
<p><strong><em>MyDataRestConfig.java</em></strong></p>
<div class="sourceCode" id="cb30"><pre
class="sourceCode java"><code class="sourceCode java"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> MyDataRestConfig <span class="kw">implements</span> RepositoryRestConfigurer <span class="op">{</span></span>
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a> <span class="at">@Autowired</span></span>
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> EntityManager entityManager<span class="op">;</span></span>
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a><span class="kw">...</span></span>
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// call an internal helper method</span></span>
<span id="cb30-6"><a href="#cb30-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">exposeIds</span><span class="op">(</span>config<span class="op">);</span></span>
<span id="cb30-7"><a href="#cb30-7" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb30-8"><a href="#cb30-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-9"><a href="#cb30-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">private</span> <span class="dt">void</span> <span class="fu">exposeIds</span><span class="op">(</span>RepositoryRestConfiguration config<span class="op">)</span> <span class="op">{</span></span>
<span id="cb30-10"><a href="#cb30-10" aria-hidden="true" tabindex="-1"></a> <span class="co">//expose entity ids</span></span>
<span id="cb30-11"><a href="#cb30-11" aria-hidden="true" tabindex="-1"></a> <span class="co">// - get a list of all entity classes from the entity manager</span></span>
<span id="cb30-12"><a href="#cb30-12" aria-hidden="true" tabindex="-1"></a> <span class="bu">Set</span><span class="op"><</span>EntityType<span class="op"><?>></span> entities <span class="op">=</span> entityManager<span class="op">.</span><span class="fu">getMetamodel</span><span class="op">().</span><span class="fu">getEntities</span><span class="op">();</span></span>
<span id="cb30-13"><a href="#cb30-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-14"><a href="#cb30-14" aria-hidden="true" tabindex="-1"></a> <span class="co">// - create an array of the entity types</span></span>
<span id="cb30-15"><a href="#cb30-15" aria-hidden="true" tabindex="-1"></a> <span class="bu">List</span><span class="op"><</span><span class="bu">Class</span><span class="op">></span> entityClasses <span class="op">=</span> <span class="kw">new</span> <span class="bu">ArrayList</span><span class="op"><>();</span></span>
<span id="cb30-16"><a href="#cb30-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-17"><a href="#cb30-17" aria-hidden="true" tabindex="-1"></a> <span class="co">// - get the entity types for the entities</span></span>
<span id="cb30-18"><a href="#cb30-18" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> <span class="op">(</span>EntityType tempEntityType <span class="op">:</span> entities<span class="op">)</span> <span class="op">{</span></span>
<span id="cb30-19"><a href="#cb30-19" aria-hidden="true" tabindex="-1"></a> entityClasses<span class="op">.</span><span class="fu">add</span><span class="op">(</span>tempEntityType<span class="op">.</span><span class="fu">getJavaType</span><span class="op">());</span></span>
<span id="cb30-20"><a href="#cb30-20" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb30-21"><a href="#cb30-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb30-22"><a href="#cb30-22" aria-hidden="true" tabindex="-1"></a> <span class="co">// - expose the entity ids for the array of entity/domain types</span></span>
<span id="cb30-23"><a href="#cb30-23" aria-hidden="true" tabindex="-1"></a> <span class="bu">Class</span><span class="op">[]</span> domainTypes <span class="op">=</span> entityClasses<span class="op">.</span><span class="fu">toArray</span><span class="op">(</span><span class="kw">new</span> <span class="bu">Class</span><span class="op">[</span><span class="dv">0</span><span class="op">]);</span></span>
<span id="cb30-24"><a href="#cb30-24" aria-hidden="true" tabindex="-1"></a> config<span class="op">.</span><span class="fu">exposeIdsFor</span><span class="op">(</span>domainTypes<span class="op">);</span></span>
<span id="cb30-25"><a href="#cb30-25" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
<span id="cb30-26"><a href="#cb30-26" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h4 id="frontend--findbycategory-dynamic">Frontend- FindByCategory
Dynamic</h4>
<p><strong><em>product-category.ts</em></strong></p>
<div class="sourceCode" id="cb31"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> ProductCategory {</span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a> id<span class="op">:</span> <span class="dt">number</span><span class="op">;</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a> categoryName<span class="op">:</span> <span class="dt">string</span><span class="op">;</span></span>
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p><strong><em>product.service.ts</em></strong></p>
<div class="sourceCode" id="cb32"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="op">...</span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">getProductCategories</span>()<span class="op">:</span> Observable<span class="op"><</span>ProductCategory[]<span class="op">></span> {</span>
<span id="cb32-3"><a href="#cb32-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="kw">this</span><span class="op">.</span><span class="at">http</span></span>
<span id="cb32-4"><a href="#cb32-4" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">get</span><span class="op"><</span>GetResponseProductCategory<span class="op">></span>(<span class="vs">`</span><span class="sc">${</span>environment<span class="op">.</span><span class="at">apiServerUrl</span><span class="sc">}</span><span class="vs">/product-category`</span>)</span>
<span id="cb32-5"><a href="#cb32-5" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">pipe</span>(<span class="fu">map</span>((response) <span class="kw">=></span> response<span class="op">.</span><span class="at">_embedded</span><span class="op">.</span><span class="at">productCategory</span>))<span class="op">;</span></span>
<span id="cb32-6"><a href="#cb32-6" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb32-7"><a href="#cb32-7" aria-hidden="true" tabindex="-1"></a>}</span>
<span id="cb32-8"><a href="#cb32-8" aria-hidden="true" tabindex="-1"></a><span class="kw">interface</span> GetResponseProductCategory {</span>
<span id="cb32-9"><a href="#cb32-9" aria-hidden="true" tabindex="-1"></a> _embedded<span class="op">:</span> {</span>
<span id="cb32-10"><a href="#cb32-10" aria-hidden="true" tabindex="-1"></a> productCategory<span class="op">:</span> ProductCategory[]<span class="op">;</span></span>
<span id="cb32-11"><a href="#cb32-11" aria-hidden="true" tabindex="-1"></a> }<span class="op">;</span></span>
<span id="cb32-12"><a href="#cb32-12" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<p><strong><em>app.component.html</em></strong></p>
<div class="sourceCode" id="cb33"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="co"><!--<div class="menu-sidebar-content js-scrollbar1"> ... </div> --></span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a>Above DIV of sidebar will be replaced by below.</span>
<span id="cb33-4"><a href="#cb33-4" aria-hidden="true" tabindex="-1"></a><span class="kw"><app-product-category-menu></app-product-category-menu></span></span></code></pre></div>
<p><strong><em>product-category-menu.component.html</em></strong></p>
<div class="sourceCode" id="cb34"><pre
class="sourceCode html"><code class="sourceCode html"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a><span class="co"><!-- Dynamic Category name coming from database --></span></span>
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a><span class="kw"><div</span> <span class="er">class</span><span class="ot">=</span><span class="st">"menu-sidebar-content js-scrollbar1"</span><span class="kw">></span></span>
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a> <span class="kw"><nav</span> <span class="er">class</span><span class="ot">=</span><span class="st">"navbar-sidebar"</span><span class="kw">></span></span>
<span id="cb34-4"><a href="#cb34-4" aria-hidden="true" tabindex="-1"></a> <span class="kw"><ul</span> <span class="er">class</span><span class="ot">=</span><span class="st">"list-unstyled navbar-list"</span><span class="kw">></span></span>
<span id="cb34-5"><a href="#cb34-5" aria-hidden="true" tabindex="-1"></a> <span class="co"><!-- <li></span></span>
<span id="cb34-6"><a href="#cb34-6" aria-hidden="true" tabindex="-1"></a><span class="co"> <a routerLink="/category/1" routerLinkActive="active-link">Books</a></span></span>
<span id="cb34-7"><a href="#cb34-7" aria-hidden="true" tabindex="-1"></a><span class="co"> </li> --></span></span>
<span id="cb34-8"><a href="#cb34-8" aria-hidden="true" tabindex="-1"></a> <span class="kw"><li</span> <span class="er">*ngFor</span><span class="ot">=</span><span class="st">"let tempProductCategory of productCategories"</span><span class="kw">></span></span>
<span id="cb34-9"><a href="#cb34-9" aria-hidden="true" tabindex="-1"></a> <span class="kw"><a</span> <span class="er">routerLink</span><span class="ot">=</span><span class="st">"/category/{{ tempProductCategory.id }}"</span> <span class="er">routerLinkActive</span><span class="ot">=</span><span class="st">"active-link"</span><span class="kw">></span></span>
<span id="cb34-10"><a href="#cb34-10" aria-hidden="true" tabindex="-1"></a> {{ tempProductCategory.categoryName }}</span>
<span id="cb34-11"><a href="#cb34-11" aria-hidden="true" tabindex="-1"></a> <span class="kw"></a></span></span>
<span id="cb34-12"><a href="#cb34-12" aria-hidden="true" tabindex="-1"></a> <span class="kw"></li></span></span>
<span id="cb34-13"><a href="#cb34-13" aria-hidden="true" tabindex="-1"></a> <span class="kw"></ul></span></span>
<span id="cb34-14"><a href="#cb34-14" aria-hidden="true" tabindex="-1"></a> <span class="kw"></nav></span></span>
<span id="cb34-15"><a href="#cb34-15" aria-hidden="true" tabindex="-1"></a><span class="kw"></div></span></span></code></pre></div>
<p><strong><em>product-category-menu.component.html</em></strong></p>
<div class="sourceCode" id="cb35"><pre
class="sourceCode typescript"><code class="sourceCode typescript"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="im">export</span> <span class="kw">class</span> ProductCategoryMenuComponent <span class="kw">implements</span> OnInit {</span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a> productCategories<span class="op">:</span> ProductCategory[]<span class="op">;</span></span>
<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span>(<span class="kw">private</span> productService<span class="op">:</span> ProductService) {}</span>
<span id="cb35-4"><a href="#cb35-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">ngOnInit</span>() {</span>
<span id="cb35-5"><a href="#cb35-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="fu">listProductCategories</span>()<span class="op">;</span></span>
<span id="cb35-6"><a href="#cb35-6" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb35-7"><a href="#cb35-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb35-8"><a href="#cb35-8" aria-hidden="true" tabindex="-1"></a> <span class="fu">listProductCategories</span>() {</span>
<span id="cb35-9"><a href="#cb35-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">productService</span><span class="op">.</span><span class="fu">getProductCategories</span>()<span class="op">.</span><span class="fu">subscribe</span>((data) <span class="kw">=></span> {</span>
<span id="cb35-10"><a href="#cb35-10" aria-hidden="true" tabindex="-1"></a> <span class="bu">console</span><span class="op">.</span><span class="fu">log</span>(<span class="st">'Product Categories='</span> <span class="op">+</span> <span class="bu">JSON</span><span class="op">.</span><span class="fu">stringify</span>(data))<span class="op">;</span></span>
<span id="cb35-11"><a href="#cb35-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">this</span><span class="op">.</span><span class="at">productCategories</span> <span class="op">=</span> data<span class="op">;</span> })<span class="op">;</span></span>
<span id="cb35-12"><a href="#cb35-12" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb35-13"><a href="#cb35-13" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<h3 id="searchproduct-by-keyword">SearchProduct by Keyword</h3>
<p><strong>Development Process</strong></p>
<ol type="1">
<li><p>Modify Spring Boot app - Add a new search method</p></li>
<li><p>Create new component for search</p></li>
<li><p>Add new Angular route for searching</p></li>
<li><p>Update SearchComponent to send data to search route</p></li>
<li><p>Enhance ProductListComponent to search for products with
ProductService</p></li>
<li><p>Update ProductService to call URL on Spring Boot app</p></li>
</ol>
<p><strong><em>ProductRepo.java</em></strong> - Backend - Find products
based on name</p>