<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: KunalShekhar</title>
    <description>The latest articles on Forem by KunalShekhar (@kunalshekhar).</description>
    <link>https://forem.com/kunalshekhar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F556950%2F521e4834-e1bf-4cd8-b7b8-8ae0344d2373.png</url>
      <title>Forem: KunalShekhar</title>
      <link>https://forem.com/kunalshekhar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kunalshekhar"/>
    <language>en</language>
    <item>
      <title>Let’s Build Signup, SignIn, and Role-Based Access in Our E-Commerce App</title>
      <dc:creator>KunalShekhar</dc:creator>
      <pubDate>Sat, 16 Jan 2021 21:35:27 +0000</pubDate>
      <link>https://forem.com/kunalshekhar/let-s-build-signup-signin-and-role-based-access-in-our-e-commerce-app-3n8k</link>
      <guid>https://forem.com/kunalshekhar/let-s-build-signup-signin-and-role-based-access-in-our-e-commerce-app-3n8k</guid>
      <description>&lt;p&gt;In this article, we are going to implement basic SignUp and SignIn functionality in Spring backend and Android UI.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/cfgwH4XQkvI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  An Overview Of The Tutorial!
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Introduction&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Database Design&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;API Design&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Demo overview&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signup&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dealing with the Android Application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Our Intention&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Requirements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dependencies&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Permissions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating Models&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Updating the API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating Activities&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The Main Page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signing Up Users&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signing In Users&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Constructing the Dashboard&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running the Application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resources&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This is a series of tutorials we are building to demonstrate how to build an &lt;strong&gt;E-Commerce App&lt;/strong&gt;, one component at a time.&lt;/p&gt;

&lt;p&gt;We are going to implement a &lt;strong&gt;basic authentication&lt;/strong&gt; which will be extended to role-based access i.e. Admin can change anything, add new Users, a manager can only add/update Category and Products, users can only see the products and Category.&lt;/p&gt;

&lt;p&gt;When users/admin sign in, we will generate an authentication token, which will be used to verify the users, when they are going to access an API later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Design
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y62PNtnL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/31xaqr8dboui293vw2k4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y62PNtnL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/31xaqr8dboui293vw2k4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Entity Relationship Diagram



&lt;p&gt;We will have a user table and tokens table. For every user, when they signUp and sign in, we will generate a token, which will have an expiry date. After the expiry day has passed, we should generate a new token, although we will not cover it in the tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Design
&lt;/h2&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;UserController will have two methods, Signup and SignIn, which will be POST requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo Overview
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UGAjCy5Jc4A"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  SignUp
&lt;/h2&gt;

&lt;p&gt;Let's look at signUp API. It takes SignupDto as Input and returns True or False as output depending upon if SignUp succeeds.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We follow these steps for signup&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Encrypt the password&lt;/li&gt;
&lt;li&gt;Save the User&lt;/li&gt;
&lt;li&gt;Generate auth token and save it in database&lt;/li&gt;
&lt;li&gt;Return Success
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

We will now look at models that are mapped as a table in the &lt;a href="https://medium.com/hackernoon/top-5-sql-and-database-courses-to-learn-online-48424533ac61"&gt;database.&lt;/a&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;User and Tokens are linked by user_id field in tokens table, which has one to one relationship, i.e one user can have one token and vice versa.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/master/"&gt;You can find the complete backend code here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Start building the Android Application
&lt;/h2&gt;

&lt;p&gt;Next, we are going to use the same REST API to perform the user authentication process in the same android application that we have created and deployed in the last tutorial. If you have not followed up, please check out the tutorial using the link given below.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/technology-hits/lets-add-products-in-android-for-e-commerce-app-b8468e055001" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/technology-hits/lets-add-products-in-android-for-e-commerce-app-b8468e055001" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Add Products in Android for E-Commerce App | by Nil Madhab | Javarevisited | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 3, 2021&lt;/time&gt; ・ 7 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Our Intention
&lt;/h2&gt;

&lt;p&gt;In our last tutorial above, we have created ways in our application to view, add, and update our products by communicating with our REST API service.&lt;/p&gt;

&lt;p&gt;Now we are going to limit the access of &lt;strong&gt;adding and updating products only to the authenticated users.&lt;/strong&gt; Non-authenticated users can simply checkout all products we have, but they are not permitted to edit.&lt;/p&gt;

&lt;p&gt;Our intention is to achieve such functionality mentioned above in our application. Get ready to explore!&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Though we have no new requirements for the application to achieve basic authentication, let’s revise them for the new readers’ convenience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Android Studio (Completely Setup with SDK)&lt;/li&gt;
&lt;li&gt;Android Virtual Device&lt;/li&gt;
&lt;li&gt;Cloud Hosted E-Commerce Backend API&lt;/li&gt;
&lt;li&gt;Retrofit- to interact with the API&lt;/li&gt;
&lt;li&gt;Glide- to load images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Steps to set up your work environment in Android Studio can be found here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependencies
&lt;/h2&gt;

&lt;p&gt;No new dependencies are needed for extending the user authentication functionality in our application. Anyway, I’ll showcase all dependencies we have used in our application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recycler View&lt;/li&gt;
&lt;li&gt;Card View&lt;/li&gt;
&lt;li&gt;Retrofit&lt;/li&gt;
&lt;li&gt;Gson converter&lt;/li&gt;
&lt;li&gt;Glide&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Permissions
&lt;/h2&gt;

&lt;p&gt;Same as dependencies, we don’t need any extra permissions to extend the required functionality to our application.&lt;/p&gt;

&lt;p&gt;We only need &lt;strong&gt;internet permissions&lt;/strong&gt; to communicate with the RESTful service. It was added during the last-mentioned tutorial.&lt;/p&gt;

&lt;p&gt;You can check out the app/src/main/AndroidManifest.xml file of our application below-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Please check the contents of the given app/src/main/AndroidManifest.xml file with yours.
&lt;h2&gt;
  
  
  Creating Models
&lt;/h2&gt;

&lt;p&gt;We already have a model for the Product to send and receive through the API. Likewise, we need to create a model for the user to pass their credentials through our API.&lt;/p&gt;

&lt;p&gt;Our user model accepts the credentials first name, last name, email id, and a password to save a user to the backend and the respective user’s email id and password to sign in them into the application.&lt;/p&gt;

&lt;p&gt;Therefore, create a class User, that has four fields firstName, lastName, email, and password, as shown below-&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
And now we have all the required models to interact with our API. Let’s go ahead with making the user objects interact with our RESTful service.
&lt;h2&gt;
  
  
  Updating the API
&lt;/h2&gt;

&lt;p&gt;We need to update the interface API that we have created so that it also interacts with the Users API in our backend.&lt;/p&gt;

&lt;p&gt;We already have the interaction with the products API. Without disturbing that, we need to establish interaction with the Users API in our RESTful service. For the same, we are gonna update the API.java in our project.&lt;/p&gt;

&lt;p&gt;You can update the same as below-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now we can interact with the Users API of our backend. Let’s move further!&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Activities
&lt;/h2&gt;

&lt;p&gt;We all know that activities are the basic building blocks of the application. An activity consists of a layout file and a java class to control the same.&lt;/p&gt;

&lt;p&gt;We are provided with the pre-built activity called Main Activity. And also, we have added the following working activities to our application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ListProducts Activity&lt;/li&gt;
&lt;li&gt;AddProduct Activity&lt;/li&gt;
&lt;li&gt;UpdateProduct Activity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this tutorial, we need three more activities to sign up a user, sign in a user, and show the dashboard to the users respectively. Go ahead and create the following activities by following the steps: Right-click on the MainActivity residing package -&amp;gt; New -&amp;gt; Activity -&amp;gt; Empty Activity&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;SignupActivity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SigninActivity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DashboardActivity&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Main Page
&lt;/h2&gt;

&lt;p&gt;The previous main page consisted mainly of buttons that navigate to add or update products and list products. But the functionalities of adding and updating products should be available only after the user is signing in. So, we are removing it from the main activity’s layout file.&lt;/p&gt;

&lt;p&gt;Instead of that, we are adding two buttons that navigate to the user signup and user sign-in activity. The respective layout file is as below-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, we need to make those newly created buttons to navigate to respective activities. For that, add on click listeners to the buttons in the MainActivity.java as below-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TLUUUNKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iykmjciuka92aipgec4h.jpg" alt="Alt Text"&gt;&lt;br&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TLUUUNKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iykmjciuka92aipgec4h.jpg" alt="Alt Text"&gt;
&lt;h2&gt;
  
  
  Signing Up Users
&lt;/h2&gt;

&lt;p&gt;We need mainly four edit texts — one for getting the first name, one for getting the last name, one for getting the email id and the last one for getting the password.&lt;/p&gt;

&lt;p&gt;And finally, we need a button to submit these data. The layout for the signup activity is modified as follows-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The input data has to be trimmed, validated and verified before we pass it to the backend. All these are done in the SignupActivity.java.&lt;/p&gt;

&lt;p&gt;An On Click Listener is added to the button that submit the data. Once the data is submitted, it is validated. After validation, a user object is created with the data and the object is passed through the API to Signup.&lt;/p&gt;

&lt;p&gt;Once the signup is completed successfully, the application navigates to the signin activity. The controlling file of the signup activity as below-&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qYijr6mH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y2d2jaournphlfs0d2zg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qYijr6mH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y2d2jaournphlfs0d2zg.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We have the sign up part all ready. Let’s move to the sign in part of our application!&lt;br&gt;
Signing In Users&lt;/p&gt;

&lt;p&gt;For signing in users, we need just the user’s email to identify them and their password to verify them. To get them, we need two edit text views.&lt;/p&gt;

&lt;p&gt;And also, a button is needed to submit the data. Below given is the layout file for sign-in activity.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The data from this layout is &lt;strong&gt;fetched, processed and verified with the backend&lt;/strong&gt; API by the SigninActivity.java. It also should contain the on click listener for the button to submit the data.&lt;/p&gt;

&lt;p&gt;Through the &lt;strong&gt;on click listener&lt;/strong&gt; added, we receive the data from the fields and process it to create a user object. The object is then passed to the &lt;strong&gt;REST API&lt;/strong&gt;, which verifies it and sends us a response to authenticate the user.&lt;/p&gt;

&lt;p&gt;After &lt;strong&gt;successful authentication&lt;/strong&gt; of the user, they are directed to the &lt;strong&gt;dashboard activity&lt;/strong&gt; of the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y02rAb-6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xl0dw03y7yugadxibpcs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y02rAb-6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xl0dw03y7yugadxibpcs.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The only remaining task before us is to make the dashboard activity. Without any delay, let’s do that!&lt;br&gt;
Constructing the Dashboard&lt;/p&gt;

&lt;p&gt;The dashboard activity seems similar to that of our main activity. It can also be called the main activity for authenticated users.&lt;/p&gt;

&lt;p&gt;Authenticated users must be able to edit the products or add new products. For that sake, add the buttons for adding and updating the products. Also, add a button for viewing the products.&lt;/p&gt;

&lt;p&gt;The layout file of the dashboard activity should be constructed as follows-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Let’s make these buttons in the dashboard activity functional! Go to the file DashboardActivity.java that controls the functioning of the activity. Add on click listeners to the buttons that we have added previously.&lt;/p&gt;

&lt;p&gt;Set up the navigation correctly so that the user is navigated to the respective activities from the buttons.&lt;/p&gt;

&lt;p&gt;The corresponding DashboardActivity.java file is as follows-&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WFvTUZqh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ujpkhxk27blbh15tpvum.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WFvTUZqh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ujpkhxk27blbh15tpvum.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Hurray! we have completed the coding section! Let’s run the application now!&lt;/p&gt;

&lt;h2&gt;
  
  
  Running the Application
&lt;/h2&gt;

&lt;p&gt;Now, it’s time for running the application, after adding the required functionalities. Select the required Android Virtual Device from the toolbar and click on the run button on the same(Green triangle icon)&lt;/p&gt;

&lt;p&gt;After a certain amount of time, your android virtual device will get the application installed and opened. You can completely use it now!&lt;/p&gt;

&lt;p&gt;Some of its screenshots are as below —&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--meGMVFeo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8tusgq6zipgbzgj708ka.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--meGMVFeo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8tusgq6zipgbzgj708ka.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wLQ0ELFR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1rfuu4sva5kdsu8vz99n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wLQ0ELFR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1rfuu4sva5kdsu8vz99n.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NtDGeyTA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wu5os3094alu0bz2czsl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NtDGeyTA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wu5os3094alu0bz2czsl.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fzmfZLyF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vpv2la0xli96str4e84w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fzmfZLyF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vpv2la0xli96str4e84w.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/master/"&gt;Bitbucket link&lt;/a&gt; for Spring Backend Project Repository&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/android-ui/src/c3b5df055d886b2aba3a6af9928b532f4808dd8a/"&gt;Bitbucket link&lt;/a&gt; for Android Application Project Repository&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://104.236.26.66:8080/api/swagger-ui.html"&gt;Spring Backend&lt;/a&gt; Swagger UI hosted on cloud&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://104.236.26.66:8080/api/"&gt;REST API&lt;/a&gt; of our Spring Backend&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f"&gt;Tutorial&lt;/a&gt; for the creating Spring Backend API&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://medium.com/technology-hits/lets-add-products-in-android-for-e-commerce-app-b8468e055001"&gt;Tutorial&lt;/a&gt; for creating the products application&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.android.com/studio/install"&gt;Steps&lt;/a&gt; to install and set up Android Studio&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Yahoo! That’s it! Hope you have learned many things from this tutorial. Stay tuned for such an awesome series of tutorials!&lt;/p&gt;

&lt;p&gt;Happy Learning!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Let’s Link Products With Category for our E-Commerce App</title>
      <dc:creator>KunalShekhar</dc:creator>
      <pubDate>Fri, 15 Jan 2021 21:44:26 +0000</pubDate>
      <link>https://forem.com/kunalshekhar/let-s-link-products-with-category-for-our-e-commerce-app-4if0</link>
      <guid>https://forem.com/kunalshekhar/let-s-link-products-with-category-for-our-e-commerce-app-4if0</guid>
      <description>&lt;p&gt;We will be creating a Vue.js application for displaying our Products and Categories.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rt1k8ZJE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vq6beuloquohhbsw605f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rt1k8ZJE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vq6beuloquohhbsw605f.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Photo by Ryan Hutton


&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Requirements&lt;/li&gt;
&lt;li&gt;Setting up the Project&lt;/li&gt;
&lt;li&gt;Vue Components&lt;/li&gt;
&lt;li&gt;Vue Router&lt;/li&gt;
&lt;li&gt;Our Application&lt;/li&gt;
&lt;li&gt;Why use Vue Router&lt;/li&gt;
&lt;li&gt;Resources&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We are building a complete E-Commerce application.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Develop an E-Commerce Application From Scratch Using Java and Spring | by Nil Madhab | Javarevisited | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 10, 2021&lt;/time&gt; ・ 5 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
So in this series of tutorials, we will now link our products with a category and design the user interface for it using Vue.js 3. In the past tutorial, we had designed the user interface for displaying products. Now, our products will have added information about their category.&lt;br&gt;
&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/technology-hits/lets-create-vue-js-frontend-for-products-in-our-e-commerce-app-14cc8c3459c8" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/technology-hits/lets-create-vue-js-frontend-for-products-in-our-e-commerce-app-14cc8c3459c8" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Add Products for our eCommerce App with Vue.js | by Nil Madhab | JavaScript In Plain English | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 12, 2021&lt;/time&gt; ・ 10 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;If you are new to Vue.js, it is recommended to glance at the above article before moving on. So, our application will list all the products and categories and provide us with the following capabilities :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a product&lt;/li&gt;
&lt;li&gt;Edit a product&lt;/li&gt;
&lt;li&gt;Add a category&lt;/li&gt;
&lt;li&gt;Edit a category&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;In the last tutorial, we used the Vue CDN to create a single widget for displaying the products and injected that into our main HTML file. But now we will move a step ahead and build a complete Vue application, which is more powerful and robust. We will use the Vue CLI tool to set up our project. You also need to have Node.js installed before proceeding with the tutorial. We will not write any Node.js specific code but still, our Vue.js project requires Node. Apart from this, I will also be using Bootstrap, some Google Fonts and VS code as my editor. These things are up to your preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the Project
&lt;/h2&gt;

&lt;p&gt;The detailed instructions for setting up a Vue project can be found here, but let's quickly go through the process once. First, we will have to install the Vue CLI tool. It can be installed in the system with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @vue/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After installing the Vue CLI, the following command is used for creating a new project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vue create project_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next, it will ask for some project configurations. Here is my project configuration:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S7IW5wbd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8jqs9bsx1gghjm7b2n4b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S7IW5wbd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8jqs9bsx1gghjm7b2n4b.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Project Configs



&lt;p&gt;After confirming all the details, we will have a project folder created for us by Vue CLI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZwgOBka3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yal1ry6xb6dtgw1864tv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZwgOBka3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/yal1ry6xb6dtgw1864tv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
The folder structure of our App


&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;

&lt;p&gt;Let’s go through the folder structure of our newly created Vue project&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;public -&lt;/strong&gt; contains the main HTML file of our project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;src/assets -&lt;/strong&gt; stores the media files like images, logos, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;src/components -&lt;/strong&gt; stores all the reusable components of our project. These components are not unique to some specific route.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;src/router -&lt;/strong&gt; contains the index.js file which keeps a record of all the routes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;src/views -&lt;/strong&gt; stores all the router components. These are the components that are rendered as per the current route.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apart from this, we have some important files too&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;App.vue -&lt;/strong&gt; it is the root component of our project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;main.js -&lt;/strong&gt; it is the starting point of our project. Here we import our root component &lt;strong&gt;App.vue&lt;/strong&gt;, our router file &lt;strong&gt;index.js&lt;/strong&gt; and &lt;strong&gt;createApp&lt;/strong&gt; method. After this, we mount our root component to the DOM using the following statement:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createApp(App).use(router).mount('#app');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The folder structure is not enforced by Vue, we can customize this as per our requirements.&lt;/p&gt;
&lt;h2&gt;
  
  
  Vue Components
&lt;/h2&gt;

&lt;p&gt;Almost all frontend frameworks allow us to create components that we can reuse at multiple places on the same or different websites. Some examples include a search bar, login form, product display component etc. In Vue, files with “.vue” extension are known as single file components. These single file components are composed of HTML, JavaScript, and CSS.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;

&amp;lt;/template&amp;gt;&amp;lt;script&amp;gt;
export default {}
&amp;lt;/script&amp;gt;&amp;lt;style&amp;gt;&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The template part contains the HTML of the component. The script tag contains the code defining the custom behavior of the component. And style tag houses the CSS of the component. As mentioned earlier, src/components and src/views contain all our components.&lt;/p&gt;
&lt;h2&gt;
  
  
  Vue Router
&lt;/h2&gt;

&lt;p&gt;The Vue router enables us to link our browser URL and our components. This helps us define paths that get coupled with our components. This way Vue renders components based on the URL. The official page of Vue router lists all its features. The most important of all these is the ease of creating &lt;strong&gt;Single page applications (SPAs)&lt;/strong&gt; using Vue router.&lt;/p&gt;

&lt;p&gt;In Single page applications designed using Vue, the very first request sent to the server responds with a single HTML file and the JavaScript bundle. Then in the browser, Vue takes complete control over the application. After this, no further requests are sent to the server for new pages even if we change routes. This means once everything is loaded, navigating through different routes of our web application becomes very smooth. As an example, head over to Vue router guide and disconnect your internet once the page has loaded, even without the internet you will be able to use most of the features available there (even changing the guide language).&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;src/router/index.js&lt;/strong&gt; file contains information about all the router paths. Folder &lt;strong&gt;src/views&lt;/strong&gt; contain the components which we couple with router paths. Because of their usage, these components are also known as router views.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;index.js&lt;/strong&gt; file, we import all the router components and create an array of objects called &lt;strong&gt;routes&lt;/strong&gt;. Objects of this array represent different routes of our application. Every route has a &lt;strong&gt;path&lt;/strong&gt;, a &lt;strong&gt;name&lt;/strong&gt; associated with it, and the component to be rendered for this path. For our project, I will be keeping the name property same as component name.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After creating this routes array, we use the &lt;strong&gt;createRouter&lt;/strong&gt; method to create and export our &lt;strong&gt;router&lt;/strong&gt;. Vue CLI is kind enough to do this task for us while creating our project.&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Application
&lt;/h2&gt;

&lt;p&gt;Now after understanding the Vue project structure and the requirement of different Vue features, we can dive into our E-Commerce project. For creating our application, we will be using many Vue components. So, there needs to be a structural hierarchy of components in our project. We can use the component tree to define this structure.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WqT1EVtM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gfgf8cfcy6yno545s1yv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WqT1EVtM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gfgf8cfcy6yno545s1yv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Component Tree



&lt;p&gt;&lt;strong&gt;App.vue&lt;/strong&gt; is the root component of our application. It is the first one to be rendered onto the DOM. Then we have our reusable components (in blue boxes) and router view components (in yellow boxes).&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;App.vue&lt;/strong&gt;, we have the data properties &lt;strong&gt;baseURL, products&lt;/strong&gt; and &lt;strong&gt;categories.&lt;/strong&gt; The baseURL refers to our backend API from where we fetch data and send requests for data addition and modification. The products and categories arrays, as their name suggests, stores our products and categories. We also have the components property which lists all the components which we use in the current component.&lt;/p&gt;
&lt;h2&gt;
  
  
  API call
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;mounted&lt;/strong&gt; Lifecycle hook of our root component &lt;strong&gt;App.vue,&lt;/strong&gt; we make the API call to fetch our products and categories. For this, we use JavaScript’s &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API"&gt;Fetch API.&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const res  = await fetch(this.baseURL + "product/");
this.products = await res.json();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Fetching data from backend API is an asynchronous task. Hence the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch"&gt;fetch&lt;/a&gt; method returns a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"&gt;promise.&lt;/a&gt; If our internet connection is stable and the server is up and running, the res variable will store the server &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Response"&gt;response.&lt;/a&gt; Now to extract our data from this response, we use the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Body/json"&gt;json&lt;/a&gt; method. The json method reads the response stream, and since this stream could be very large, it takes time and returns a promise on completion. This promise once resolved returns a JavaScript object. In JavaScript, an array is also an object which can be represented in JSON.&lt;/p&gt;

&lt;p&gt;The root component is the best place to fetch data from backend API because from here we can pass on this data as &lt;strong&gt;props&lt;/strong&gt; to our child component. Let’s get this terminology clear. When we use a component inside of some other component, they are referred to as child and parent component respectively. A parent component can pass its data to a child component, this data is known as &lt;strong&gt;props.&lt;/strong&gt; You can think of it as passing arguments to a function.&lt;/p&gt;
&lt;h2&gt;
  
  
  Router paths
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;App.vue&lt;/strong&gt;, we have used the components &lt;strong&gt;Navbar&lt;/strong&gt; and &lt;strong&gt;Footer.&lt;/strong&gt; Apart from this we also have a Vue tag &lt;strong&gt;.&lt;/strong&gt; This router-view tag renders component based on the URL path. Along with this, we also have the &lt;strong&gt;&lt;/strong&gt; tag. It acts as an anchor tag for a router-enabled app. The target location for this link is specified using the to prop. Let’s have a look at &lt;strong&gt;index.js&lt;/strong&gt; file where we have defined all our routes.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;So to summarize the above file, we have set up the routing of our application in the following manner:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M2fX2Yxh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e1vkypzk2dvgia76vy7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M2fX2Yxh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e1vkypzk2dvgia76vy7k.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing props
&lt;/h2&gt;

&lt;p&gt;In App.vue, we have passed props to the router view components. As mentioned earlier, it is the parent component which can pass props to its child component. To send these props, we can either give them some value or bind them with the data properties of the parent component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;router-view :baseURL="baseURL" &amp;gt;&amp;lt;/router-view&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here baseURL written after the colon (short for &lt;strong&gt;v-bind&lt;/strong&gt; directive) is the name with which this prop will be available in the child component. baseURL inside the double quotes is the parent component’s data field. We can name these props differently also, but I have used the same name to maintain consistency. Now in the child component, it is necessary to register these props in the component object’s &lt;strong&gt;props&lt;/strong&gt; property. A child component may skip some props if it doesn't require them.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;App.vue&lt;/strong&gt;, we have also used the &lt;strong&gt;“v-show”&lt;/strong&gt; directive to show the Footer component only when we are at some path other than the Home. We can get the current path name from &lt;code&gt;this.$route.name&lt;/code&gt; property. So now, let's take a look at our App.vue file:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Navbar
&lt;/h2&gt;

&lt;p&gt;The Navbar component is used for navigating through our web application. We have used the Navbar component inside our &lt;strong&gt;App.vue&lt;/strong&gt; above the &lt;strong&gt;router-view tag.&lt;/strong&gt; Hence, every route of our website will have the Navbar at the top. We have designed our Navbar with three router links to &lt;strong&gt;Home, Product and Category route.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Home
&lt;/h2&gt;

&lt;p&gt;The Home component is the landing page of our web application. It is the first impression of our app which plays a crucial role in our advertising campaign.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p0VSCyiP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qecz4mp4w9xxuf37zczk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p0VSCyiP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/qecz4mp4w9xxuf37zczk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Footer
&lt;/h2&gt;

&lt;p&gt;The Footer component is present at the bottom of our websites. Here we can place the About Us, Contact and some other important pages link. Along with these, we can also place links to our social media handles. I have used this icons library to use logos of some popular social media platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Products
&lt;/h2&gt;

&lt;p&gt;As the basic structure of our website is in place, we can start working on the core functionality. Let us start with components related to products.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Product.vue:&lt;/strong&gt; This component lists all the products of our application. In the component template, we first design a button for adding new products inside a &lt;strong&gt;router-link&lt;/strong&gt; to AddProduct router view component. Then we use the &lt;strong&gt;v-for&lt;/strong&gt; directive to loop through all the products inside the products array. For every product, we render the ProductBox component passing the product as a prop. In the component object, we list the required props that we get from our parent component. Along with this, we also mention ProductBox as a child component.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;AddProduct.vue:&lt;/strong&gt; This component presents a form for adding a new product into our backend API database. We define five data fields to track user input. Here, the v-model directive helps us to make a two-way binding between the user input and our component data fields. We also attach a click event to the submit button of our form. Once the user submits the form, we call the addProduct method of our component. This method creates our newProduct and makes a POST request to our backend API to add this product. Once this process completes we redirect to our Product route.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ch_jUDMj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oujlntja1qdfc36tl93d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ch_jUDMj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oujlntja1qdfc36tl93d.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Add Product Form



&lt;p&gt;&lt;strong&gt;ProductBox.vue:&lt;/strong&gt; This component displays the details of a product. First, we design a button for editing the product inside a router-link to EditProduct router view component. This router link takes the product id inside the params object. Remember, we defined the path for EditProduct with a dynamic segment denoted by a colon. When the route is matched, the value of the dynamic segments will be exposed as &lt;code&gt;this.$route.params&lt;/code&gt; in every component. This is defined in the Vue documentation as &lt;a href="https://router.vuejs.org/guide/essentials/dynamic-matching.html"&gt;Dynamic Route Matching.&lt;/a&gt; Then we display the product’s image, name, description and price.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--URto0bSM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rr6uxguuc5f1sjuzkqcu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--URto0bSM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rr6uxguuc5f1sjuzkqcu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Product box



&lt;p&gt;&lt;strong&gt;EditProduct.vue:&lt;/strong&gt; This component displays the form for editing details of an existing product. Remember this.$route.params.id stores the id of product for which this form was invoked. We use this id to find our product and fill the default input values with its current details. Similar to the AddProduct form, once the user submits the form, we create the newProduct and make a POST request to our backend API to update the current product. Then we redirect to the Product route.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rMDNQ0Te--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/26tgtiya4icgjm4g5118.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rMDNQ0Te--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/26tgtiya4icgjm4g5118.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Edit Product Form



&lt;h2&gt;
  
  
  Categories
&lt;/h2&gt;

&lt;p&gt;Once we are done with the product’s components, working with categories is not a creative task. The code which goes inside is very similar. The categories also provide us with the same functionality as products.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Vue Router
&lt;/h2&gt;

&lt;p&gt;The Vue router is a very powerful tool, yet easy to learn. Vue router as its landing page says makes building SPAs a breeze. It provides us with a modular, component-based router configuration. Using Vue router improves the responsiveness of our application to a good extent.&lt;/p&gt;

&lt;p&gt;You have made it to the end!! 🎉✨&lt;/p&gt;

&lt;p&gt;Now we have a fully working Vue.js frontend to display our products and categories. The complete code for the app can be found here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://v3.vuejs.org/guide/introduction.html"&gt;Vue.js 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce-ui/src/f77c335cd9b1b777cff065f4396af6b1cefcef0e/?at=chitresh%2Fvue.js-product-category"&gt;Frontend code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/master/"&gt;Backend API Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://104.236.26.66:8080/api/swagger-ui.html#/"&gt;Swagger-UI for the API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en/"&gt;Node.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fonts.google.com/"&gt;Google Fonts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://getbootstrap.com/docs/4.5/getting-started/introduction/"&gt;Bootstrap&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ionicons.com/"&gt;Ionicons&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank You for Reading 📕😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>springboot</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Let’s Add Products for our eCommerce App with Vue.js</title>
      <dc:creator>KunalShekhar</dc:creator>
      <pubDate>Thu, 14 Jan 2021 19:53:09 +0000</pubDate>
      <link>https://forem.com/webtutsplus/let-s-add-products-for-our-ecommerce-app-with-vue-js-m2k</link>
      <guid>https://forem.com/webtutsplus/let-s-add-products-for-our-ecommerce-app-with-vue-js-m2k</guid>
      <description>&lt;p&gt;We are building a complete E-commerce application from scratch. Today we are going to add the Products feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7tY4CBv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4sfog7jzvwveb0v0rau5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7tY4CBv2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4sfog7jzvwveb0v0rau5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As part of building an E-Commerce application, previously we built the backend for UserProfiles and created android UI for the same.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Develop an E-Commerce Application From Scratch Using Java and Spring | by Nil Madhab | Javarevisited | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 10, 2021&lt;/time&gt; ・ 5 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/technology-hits/android-ui-for-e-commerce-user-profile-backend-4053ab122a13" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/technology-hits/android-ui-for-e-commerce-user-profile-backend-4053ab122a13" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Build User Profile UI With Android for our E-Commerce App | by Nil Madhab | Javarevisited | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 8, 2021&lt;/time&gt; ・ 10 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;The most important part of an online shop is products. We are going to create product backend APIs and consume those APIs in our web front-end built using the shiny Vue.js framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://remotedevs.org:8000/"&gt;Webtutsplus E-commerce App&lt;/a&gt;&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/oh8mse1eD3U"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Design
&lt;/h2&gt;

&lt;p&gt;This is a sample JSON of a product, we will link it to a category and add other fields in later tutorials.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
products.sql




&lt;p&gt;Each product has a unique ID, name, image URL, price, description. We can model it in Springboot as&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  API Design
&lt;/h2&gt;

&lt;p&gt;In the real-world, we need to see the products, create new products, and update the products. So we will create 3 APIs. Later we will create many other real-world features like deleting, stocks, linking to categories, and adding tags. After this, we will create the UI.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
Product controller to create, add and update products




&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mvbgzd_G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/j0msr8zwd1z2dot51w5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mvbgzd_G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/j0msr8zwd1z2dot51w5o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Swagger listing of APIs



&lt;p&gt;You can find the backend code in this &lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/596dd222404adcdd5541ddd04e48f9b75dfa3205/?at=nmadhab%2Fproducts-v1-first-tutorial"&gt;branch&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vue.js introduction
&lt;/h2&gt;

&lt;p&gt;We will use Vue.js 3 to design the front end for displaying products of our E-commerce app.&lt;/p&gt;

&lt;p&gt;Vue is a JavaScript framework that is used to build user interfaces. The official page of Vue describes it as a “progressive framework” which is “incrementally adoptable”. Both of these terms roughly relate to the same meaning. Vue can be used in two ways. We can either create a full Vue website, commonly known as a Single-page application or we can create stand-alone widgets (also known as components) which we can then use in our HTML as an addition. This way, the adoption of Vue in our application is totally in our hands. In this tutorial, we will be creating a Vue component to display products of our E-Commerce App.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vue.js Requirements
&lt;/h2&gt;

&lt;p&gt;As we are just creating a single widget for displaying the product and its details, we can make use of the Vue CDN from its installation page and carry on. Using Vue CDN is a beginner-friendly way to start our journey. For bigger projects, a different setup using Vue CLI is recommended. As a code editor, I will be using VS Code, but you can use any editor of your choice. First, we will create the following three files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PoCQvmOE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vwa59mux0ut5urlxxpy0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PoCQvmOE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vwa59mux0ut5urlxxpy0.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s get started
&lt;/h2&gt;

&lt;p&gt;First, let us set up the boilerplate for index.html. Our very first requirement is Vue CDN. Apart from this, I am also including Bootstrap 4 CDN and some Google fonts which I will be using. And for my custom styles, I am also including the link to my external CSS file. Also, include the script tag to link our JavaScript file app.js in the body tag. After all these things are done, our index.html will look like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We will revisit this file once we are done with our app.js file.&lt;/p&gt;

&lt;p&gt;You can find the complete code &lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce-ui/src/68a63aa70194f9064e8be0115f86e95293fe1a05/?at=chitresh%2Fvue.js-product-edit"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a Vue Component
&lt;/h2&gt;

&lt;p&gt;Now it's time for our app.js file, where we will be writing the logic for creating our Vue Component. To create a component, Vue provides us with a method createApp(). This method takes as a parameter a component instance. This instance is made up of various component options and Lifecycle hooks that add user-defined behaviour to the component.&lt;br&gt;
&lt;strong&gt;Component Options&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will be using two of the component options — data and methods.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The data option lists all the data fields which are exposed by our component instance.&lt;/li&gt;
&lt;li&gt;The methods option lists all the functions which we might need to use. For example, here we can define a function to execute whenever some button in our component template is clicked.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Lifecycle Hooks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apart from these component options, our component instance also consists of Lifecycle hooks. Lifecycle hooks are the functions that our component automatically runs at different stages of its initialization. These stages include when a component is created, added to the DOM, updated, or destroyed. We will be using the lifecycle hook, mounted. This function is called when our component is added to the DOM. In this function, we can make HTTP requests to fetch data for our component.&lt;/p&gt;
&lt;h2&gt;
  
  
  Our Component
&lt;/h2&gt;

&lt;p&gt;So in our case, the data option consists of six fields. A product array to store our products, showAddForm(a boolean value) to decide whether to display form for adding a new product and four-string data fields which we will use to get input from the user for product edit functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data() {
    return {
        products : null,
        showAddForm : false,
        tempName : "",
        tempDescription : "",
        tempPrice : "",
        tempImageURL : "" 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In methods option, we have five methods,&lt;strong&gt;resetInputFields, addProductButtonPressed, addProduct, editButtonPressed and editProduct.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;resetInputFields -&lt;/strong&gt; it sets the values of all data fields bound to the input form to an empty string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;addProductButtonPressed -&lt;/strong&gt; it toggles the display of form used for adding a new product. It gets executed whenever the user clicks the “Add a New Product” button.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;addProduct -&lt;/strong&gt; it creates a new product as per the user input and makes a POST request to backend API to add this product. It gets executed when the user submits the form for adding a new product.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;editButtonPressed -&lt;/strong&gt; it toggles the form for editing a product based on the product’s showEditForm property and sets the values of input fields as per the invoking product details. It gets executed when the user clicks the “Edit” button. For distinguishing the product, this method takes the index of the product as a method argument.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;editProduct-&lt;/strong&gt; it creates a new product as per the user input and makes a POST request to backend API to update the product details. This method also takes the index of the product as a method argument. It gets executed when the user submits the form for editing a product. The backend API makes use of the product’s unique id to update its details.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In mounted life cycle hook, we fetch all the products from the E-Commerce API and store them in the products array. In addition to this, we also add a property showEditForm to all products and set it to false.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mounted : async function mounted(){
    const response  = await fetch(urlGetProduct);
    this.products = await response.json();
    for(product of this.products) {
        product.showEditForm = false;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now that our component is created we have to add this component to our DOM. For this, we make use of the mount method.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.mount("#app");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This statement mounts our component to the HTML element with id “app”. Now our Vue component controls everything inside this element. We can make this HTML element to render dynamic data, add interactivity and handle events occurring inside it. This completes the creation of our Vue component in app.js.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Designing the Component’s Template
&lt;/h2&gt;

&lt;p&gt;We are now back to our index.html file.&lt;/p&gt;

&lt;p&gt;We have created an h1 tag for displaying the heading at the top of the web page. Then we have to create a div element with id as “app”. This will be the playground of our Vue component. All the data fields declared in our component’s data option are accessible here. First, we will design a form for adding a new product. Then a section to display product details. Finally, a form for editing products. This will be very similar to the first form.&lt;/p&gt;

&lt;p&gt;For achieving all this, Vue gives us the power of directives.&lt;br&gt;
&lt;strong&gt;Vue Directives&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Directives are like instructions to Vue to do something. Vue provides us with many directives in our armoury. These directives can be used for listening to events and conditional rendering of HTML elements to the DOM.&lt;/p&gt;
&lt;h2&gt;
  
  
  Add Form
&lt;/h2&gt;

&lt;p&gt;Let’s start with the add form. Here we will use the directives &lt;strong&gt;“v-on”&lt;/strong&gt; and “v-show”. The &lt;strong&gt;“v-on”&lt;/strong&gt; directive is used for listening to DOM events. This includes events like clicking, hovering, scrolling and many more. We will use this directive to listen to click events on the “Add a new product” button. On this click event, we can either perform some JavaScript logic or we can call some method of our component declared earlier. While calling the method, we can also pass arguments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button v-on:click=”addProductButtonPressed”&amp;gt; Add Product &amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Vue also provides shortcuts for some directives. For example, &lt;strong&gt;“v-on”&lt;/strong&gt; can be replaced with @ symbol.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button @click=”addProductButtonPressed”&amp;gt; Add Product &amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We will use the “v-show” directive to show the form for adding products. The “v-show” directive can be used to toggle the display of some HTML element based on some boolean condition. In the form, we will make use of the boolean variable showAddForm to decide whether to display the form or not.&lt;/p&gt;

&lt;p&gt;Now in designing the form, we make use of the “v-model” directive. We can use this directive in the input fields of the form. This creates a two-way binding between the input fields and the data fields of our component. This way we can easily read the input values and even reset them when required.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input type="text" placeholder="Enter name" v-model="tempName"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;At the bottom of the form will be a submit button. Here also we will make use of the “v-on” directive to listen to the click event.&lt;br&gt;
Product Details&lt;/p&gt;

&lt;p&gt;In a div element with class “products-box”, we will use the directive “v-for” for looping through the products array. In the loop, along with the individual product, we will also keep a count of the index.&lt;/p&gt;

&lt;p&gt;Now the interesting part is, inside this div, all the HTML elements will be rendered one after the other for all the individual products. And for different products, we will be displaying dynamic content based on the product details.&lt;/p&gt;

&lt;p&gt;We can use “v-bind” for binding the attributes of HTML element with dynamic content.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img v-bind:src=”product.imageURL” alt=”product-image”&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Along with “v-for” directive we also have access to “v-if” and “v-else” directive which we can use in an if-else situation. But, it is beneficial to use &lt;strong&gt;“v-show”&lt;/strong&gt;, instead of “v-if” anywhere possible because &lt;strong&gt;“v-show”&lt;/strong&gt; only displays or hides the content. In case the condition is false, it does not remove any part from the DOM, it just hides it. For displaying dynamic text content, we have to wrap data fields inside double braces.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h2 class="product_name"&amp;gt;{{product.name}}&amp;lt;/h2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;** Edit Product&lt;/p&gt;

&lt;p&gt;Finally, we will design the form for edit product functionality. The layout of this form will be similar to the earlier form. We will be using the same directives &lt;strong&gt;“v-show”&lt;/strong&gt;, &lt;strong&gt;“v-on”&lt;/strong&gt; and &lt;strong&gt;“v-model”&lt;/strong&gt;. The only difference will be the logic for handling the submission of the form.&lt;/p&gt;

&lt;p&gt;So after designing the component template, our index.html will look something like this:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;In this HTML file, the div element with class “product-item” encapsulates displaying the product details and its edit form. It is this div element, which is rendered for all the products.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0_jsAM95--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nvr0okxvlj5en22pp7bh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0_jsAM95--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/nvr0okxvlj5en22pp7bh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS&lt;/p&gt;

&lt;p&gt;Let’s also add some custom CSS :&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;So now we have a front-end to display all the products and their details. We have also got the functionality to add new products and edit the existing ones.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iXtzscxy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v832dnkpywb8jcbgum6h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iXtzscxy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v832dnkpywb8jcbgum6h.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use a framework?
&lt;/h2&gt;

&lt;p&gt;Front-end frameworks have made the lives of developers a lot easier. The biggest advantage of using a framework over traditional JavaScript is the link between our data and its presentation. Using frameworks, developers do not need to worry about writing the code for updating DOM when some variables change. Frameworks achieve this very easily using two-way binding. Along with easing our work, some frameworks also provide additional features like routing, which can be used to create Single Page Applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  But why Vue.js?
&lt;/h2&gt;

&lt;p&gt;Vue.js is getting backed by a lot of developers. The Vue.js community is rapidly growing. The recent updates to Vue have made it a lot more robust. Many prefer Vue.js over other frameworks because of its ease-of-use, its performance, and its compact size. The official documentation of Vue is a great resource to get a deep dive into the framework. Many also consider Vue as a combination of all good parts of React and Angular. Hence, Vue.js is worth giving a try.&lt;br&gt;
Follow the next tutorial in the series, where we will create categories and link products with categories.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/javascript-in-plain-english/lets-link-product-with-category-for-our-ecommerce-app-28100657a848" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/javascript-in-plain-english/lets-link-product-with-category-for-our-ecommerce-app-28100657a848" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Link Products With Category for our E-Commerce App | by Nil Madhab | JavaScript In Plain English | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 2, 2021&lt;/time&gt; ・ 10 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/webtutsplus/creating-a-simple-vue-js-website-for-our-backend-1d1ef8839c27" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/webtutsplus/creating-a-simple-vue-js-website-for-our-backend-1d1ef8839c27" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Vue.js UI for our Java Springboot backend | JavaScript In Plain English&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 3, 2021&lt;/time&gt; ・ 13 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href="https://getbootstrap.com/docs/4.0/getting-started/introduction/"&gt;Bootstrap 4 CDN&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce-ui/src/68a63aa70194f9064e8be0115f86e95293fe1a05/?at=chitresh%2Fvue.js-product-edit"&gt;Frontend Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/596dd222404adcdd5541ddd04e48f9b75dfa3205/?at=nmadhab%2Fproducts-v1-first-tutorial"&gt;Backend code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://v3.vuejs.org/guide/introduction.html"&gt;Vue.js 3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://remotedevs.org:8080/api/swagger-ui.html"&gt;Swagger-UI for the API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fonts.google.com/"&gt;Google Fonts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/master/"&gt;Backend API Repository&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Thank You for Reading!&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Let’s Build User Profile UI With Android for our E-Commerce App</title>
      <dc:creator>KunalShekhar</dc:creator>
      <pubDate>Tue, 12 Jan 2021 16:20:08 +0000</pubDate>
      <link>https://forem.com/webtutsplus/let-s-build-user-profile-ui-with-android-for-our-e-commerce-app-nmg</link>
      <guid>https://forem.com/webtutsplus/let-s-build-user-profile-ui-with-android-for-our-e-commerce-app-nmg</guid>
      <description>&lt;p&gt;We are going to create an android UI for our UserProfile backend API we are creating for our demo E-commerce tutorial&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m_WluMeh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/om7nw0ur5fqqz0bjoao5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m_WluMeh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/om7nw0ur5fqqz0bjoao5.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We are building an e-commerce platform from scratch. In the last tutorial, we build the backend for the UserProfile.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/technology-hits/lets-develop-an-ecommerce-application-from-scratch-using-java-and-spring-6dfac6ce5a9f" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Develop an E-Commerce Application From Scratch Using Java and Spring | by Nil Madhab | Javarevisited | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 10, 2021&lt;/time&gt; ・ 5 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;In this article, we will build the android UI for the UserProfile backend, which can be a base for many other applications.&lt;/p&gt;

&lt;p&gt;Not long before was the time when the user profile consisted of a hard copy form. From the advent of digital technology and sophisticated software, profiles have been becoming more intuitive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend API description
&lt;/h2&gt;

&lt;p&gt;Here we describe the most important component of our user profile application: the REST API. A REST API is an application that uses the existing protocol stack for data communication between different applications on the web. Here, we are using a web API to communicate between our android application and a remote database for user data storage. Our API handles the GET and POST request which basically allows the android application to create and fetch data from the database.&lt;/p&gt;

&lt;p&gt;The API used here is created using Java and Spring Boot framework. Spring is a popular application development framework, developed for the enterprise edition of the Java programming language. You can find detailed project files for the REST API over here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X8VzxT1u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ves5ozdti5pm8k9n1ikk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X8VzxT1u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ves5ozdti5pm8k9n1ikk.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iB8musS4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ns8cl374mog2s1kdubcy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iB8musS4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ns8cl374mog2s1kdubcy.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Android Studio is the official Integrated Development Environment (IDE) for &lt;a href="https://medium.com/hackernoon/top-5-courses-to-learn-android-for-java-programmers-667e03d995b4"&gt;Android app development&lt;/a&gt;, based on IntelliJ IDEA. On top of IntelliJ’s powerful code editor and developer tools, Android Studio offers even more features that enhance your productivity when building Android apps, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A flexible Gradle-based build system.&lt;/li&gt;
&lt;li&gt;A fast and feature-rich emulator.&lt;/li&gt;
&lt;li&gt;A unified environment where you can develop for all Android devices.&lt;/li&gt;
&lt;li&gt;Apply Changes to push code and resource changes to your running app without restarting your app.&lt;/li&gt;
&lt;li&gt;Code templates and GitHub integration to help you build common app features and import sample code.&lt;/li&gt;
&lt;li&gt;Extensive testing tools and frameworks.&lt;/li&gt;
&lt;li&gt;Lint tools to catch performance, usability, version compatibility, and other problems.&lt;/li&gt;
&lt;li&gt;C++ and NDK support.&lt;/li&gt;
&lt;li&gt;Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benefit of using Android Studio over any other IDE is we get a rich set of features built-in which enable us to focus more on the development aspect while the back-end of this IDE handles the requirements and dependencies. For this project, an existing API endpoint has been used for database connectivity.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisite:
&lt;/h2&gt;

&lt;p&gt;Before we start developing, we need to check off a few requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You will need to have a Java JDK installed on your system. You can find the instructions for installing the JDK here.&lt;/li&gt;
&lt;li&gt;You will need to install Android Studio on your system.&lt;/li&gt;
&lt;li&gt;Lastly, we can use our Android smartphone with USB debugging enabled for testing the android app or we can use the built-in Android emulator from Android Studio (I have used my smartphone for testing and debugging).&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Project Setup and Structure:
&lt;/h2&gt;

&lt;p&gt;Once you install Android Studio on your system, you can start with creating a new project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SCv96Jrv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kwha5j5mk052n6yuatua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SCv96Jrv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kwha5j5mk052n6yuatua.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Android Studio Welcome Screen



&lt;p&gt;To create your new Android project, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the &lt;strong&gt;Welcome to Android Studio&lt;/strong&gt; window, click &lt;strong&gt;Start a new Android Studio project.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;In the Select a &lt;strong&gt;Project Template&lt;/strong&gt; window, select &lt;strong&gt;Empty Activity&lt;/strong&gt; and click &lt;strong&gt;Next.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;In the &lt;strong&gt;Configure your project&lt;/strong&gt; window, complete the following:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Enter “User Authentication” in the &lt;strong&gt;Name&lt;/strong&gt; field.&lt;/li&gt;
&lt;li&gt;Enter “com.example.userprofile” in the &lt;strong&gt;Package name&lt;/strong&gt; field.&lt;/li&gt;
&lt;li&gt;If you’d like to place the project in a different folder, change its &lt;strong&gt;Save&lt;/strong&gt; location.&lt;/li&gt;
&lt;li&gt;Select Java from the Language drop-down menu.&lt;/li&gt;
&lt;li&gt;Select the lowest version of Android your app will support in the &lt;strong&gt;Minimum SDK&lt;/strong&gt; field. I have selected API level 22 (Android Lollipop).&lt;/li&gt;
&lt;li&gt;Leave the other options as they are.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Finish.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After some processing time, the Android Studio main window appears.&lt;/p&gt;

&lt;p&gt;Now take a moment to review the most important files. First, be sure the Project window is open (select &lt;strong&gt;View &amp;gt; Tool Windows &amp;gt; Project)&lt;/strong&gt; and the Android view is selected from the drop-down list at the top of that window. You can then see the following files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;app &amp;gt; java &amp;gt; com.example.userprofile &amp;gt; MainActivity&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the main activity. It’s the entry point for your app. When you build and run your app, the system launches an instance of this Activity and loads its layout.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;app &amp;gt; res &amp;gt; layout &amp;gt; activity_main.xml&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This XML file defines the layout for the activity’s user interface (UI). It contains a TextView element with the text “Hello, World!”&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;app &amp;gt; manifests &amp;gt; AndroidManifest.xml&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The manifest file describes the fundamental characteristics of the app and defines each of its components.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Gradle Scripts &amp;gt; build.gradle&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are two files with this name: one for the project, “Project: User Authentication” and one for the app module, “Module: app.” Each module has its own build.gradle file, but this project currently has just one module. Use each module’s build.gradle file to control how the Gradle plugin builds your app. For more information about this file, see Configure your build.&lt;/p&gt;

&lt;p&gt;Before you run your first app, get your smartphone, and enable USB debugging by following the instructions over here. After, enabling USB debugging, connect your smartphone to your PC and you are ready to go.&lt;/p&gt;

&lt;p&gt;In Android Studio, &lt;strong&gt;select Run &amp;gt; Run ‘app’&lt;/strong&gt; or click the Run icon in the toolbar.&lt;/p&gt;

&lt;p&gt;Congratulations on creating your very first app. But you are far from what we have to achieve. Next, we need to create the rest of the application.&lt;br&gt;
Setting up the files:&lt;/p&gt;

&lt;p&gt;Let’s start with &lt;strong&gt;app &amp;gt; res &amp;gt; drawables.&lt;/strong&gt; This is the directory where we will be storing all the graphical elements for our application. We are going to store three different categories of graphic elements.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Image. (filename: background.jpg)&lt;/li&gt;
&lt;li&gt;Icon elements. (filenames: account.xml, email.xml, pencil.xml)&lt;/li&gt;
&lt;li&gt;Custom graphic file. (round_button.xml)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The image used here is for the background of the UI. You can use any image you like but be sure to use the same file name for the next part where we will be coding the back-end and creating activity layouts.&lt;/p&gt;

&lt;p&gt;Icon elements are XML files for vector graphic icons used in our application. You can find and download these files from here.&lt;/p&gt;

&lt;p&gt;The custom graphic file here is used for creating a rich look for our buttons in the application. It’s an XML file containing various tags and attributes specifying the properties that the button will have for its appearance.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Moving on, we have two layout files for our two pages: create user and fetch user data page. These files are contained in &lt;strong&gt;app &amp;gt; res &amp;gt; layout&lt;/strong&gt; having names activity_main.xml, user.xml. To create these files, right-click on the layout directory and select new &amp;gt; layout resource file. A New Resource File pop-up with several fields should appear. In the File name field, we’ll insert the required file names.&lt;/p&gt;

&lt;p&gt;In the Root element field of this same pop-up, make sure to type in RelativeLayout. The remaining two fields can remain the same. Click OK. This will create a new layout for us.&lt;/p&gt;

&lt;p&gt;However, Android Studio will likely default to the visual editor we saw our Constraint Layout in earlier. To edit our layout’s XML directly, we’ll need to navigate out of the visual editor and into the XML editor. Near the top-right of the editor screen, you should see three tabs: code, split, design. Select the code tab to toggle into the XML editor.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
activity_main.xml


 


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
user.xml




&lt;p&gt;If you can notice then all these files contain some common tags having some attributes. These tags are View elements that are going to be displayed in the application. Let’s review them one by one for a general idea.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RelativeLayout:&lt;/strong&gt; RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left, or center).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TextView:&lt;/strong&gt; A TextView displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however, the basic class is configured to not allow editing.
EditText: EditText is a standard entry widget in android apps. It is an overlay over TextView that configures itself to be editable. EditText is a subclass of TextView with text editing operations. We often use EditText in our applications to provide an input or text field, especially in forms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Button:&lt;/strong&gt; In Android, Button represents a push button. Push buttons can be clicked, or pressed by the user to perform an action. On a button, we can perform different actions or events like click event, pressed event, touch event, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TableLayout:&lt;/strong&gt; A layout that arranges its children into rows and columns. A TableLayout consists of several TableRow objects, each defining a row. TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TableRow:&lt;/strong&gt; For building a row in a table we use the TableRow element. Table row objects are the child's views of a table layout. Each row of the table has zero or more cells and each cell can hold only one view object like ImageView, TextView, or any other view.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wOEMPZwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kxlpqfoay2qdtoa82i0r.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wOEMPZwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kxlpqfoay2qdtoa82i0r.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Rows and Columns in TableLayout Android



&lt;p&gt;There are many more tags and have many different attributes for creating various intuitive design elements and UI for an android application.&lt;/p&gt;

&lt;p&gt;Next up, we will create the files necessary for the back-end of our applications: Java files.&lt;/p&gt;

&lt;p&gt;We will be creating two more java class files which are Config.java and User.java.&lt;/p&gt;

&lt;p&gt;To create them, right-click on &lt;strong&gt;app &amp;gt; java &amp;gt; com.example.userprofile directory and click New &amp;gt; Java Class.&lt;/strong&gt; Enter the file name and press enter.&lt;/p&gt;

&lt;p&gt;Before moving ahead, we must configure our AndroidManifest.xml file for the file additions and requirements that we want.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
AndroidManifest.xml




&lt;h2&gt;
  
  
  Adding in the code
&lt;/h2&gt;

&lt;p&gt;To save the hassle, each class for a given activity contains a default piece of code that is essential for the behavior of the application.&lt;/p&gt;

&lt;p&gt;As a user navigates through, out of, and back to your app, the Activity instances in your app transition through different stages in their life-cycle. The Activity class provides several callbacks that allow the activity to know that a state has changed: that the system is creating, stopping, or resuming an activity, or destroying the process in which the activity resides.&lt;/p&gt;

&lt;p&gt;Within the lifecycle callback methods, you can declare how your activity behaves when the user leaves and re-enters the activity. For example, if you’re building a streaming video player, you might pause the video and terminate the network connection when the user switches to another app.&lt;/p&gt;

&lt;p&gt;When the user returns, you can reconnect to the network and allow the user to resume the video from the same spot. In other words, each callback allows you to perform specific work that’s appropriate to a given change of state. Doing the right work at the right time and handling transitions properly make your app more robust and performant. For example, good implementation of the lifecycle callbacks can help ensure that your app avoids:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Crashing if the user receives a phone call or switches to another app while using your app.&lt;/li&gt;
&lt;li&gt;Consuming valuable system resources when the user is not actively using it.&lt;/li&gt;
&lt;li&gt;Losing the user’s progress if they leave your app and return to it at a later time.&lt;/li&gt;
&lt;li&gt;Crashing or losing the user’s progress when the screen rotates between landscape and portrait orientation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4EoOCCbI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ceax7k8hwgor529xox2w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4EoOCCbI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ceax7k8hwgor529xox2w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
Activity Life Cycle



&lt;p&gt;We have extensively use the &lt;strong&gt;onCreate()&lt;/strong&gt; activity method which defines the behavior of the application on start-up.&lt;/p&gt;

&lt;p&gt;For the first file, MainActivity.java:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
MainActivity.java




&lt;p&gt;Let’s go through the methods defined in this code snippet-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;create():&lt;/strong&gt; This method is at the heart of profile creation where the magic happens. Right from getting the input to processing it; is managed by this method. The most important job of this method is to create an HTTP client tunnel connection to the server hosting the database and send the HTTP POST request. Here, we have provided the existing API endpoint. Also, this method will be handling failed requests and other errors while successfully creating a user profile.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;user():&lt;/strong&gt; This method starts a new activity called user. There we can view the existing user profiles in the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we have the User.java file:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
User.java




&lt;p&gt;Let’s go through the methods defined in this code snippet-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;fetch():&lt;/strong&gt; This method performs the operation of fetching user data from a remote database. It performs this operation by sending an HTTP GET request. After fetching the data, the method dynamically creates the required number of rows for the number of users that will be displayed on the UI. The received data is in the form of a JSON string, which is parsed into a JSON object. From here, we extract the necessary data for display purposes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;createTextView():&lt;/strong&gt; This method creates a TextView object while setting the required parameters to this object and finally attaching it as a child to the TableRow object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, we have the Config.java file:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
config.java




&lt;p&gt;This file is a java interface file that stores the API endpoint.&lt;/p&gt;

&lt;p&gt;Now we will run our program as previously stated by connecting our android device via USB.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/BFWYc6tQuoc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/webtutsplus/android-app-for-spring-backend-68f39dca8b72" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/webtutsplus/android-app-for-spring-backend-68f39dca8b72" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;User Authentication Android Application for Java and Spring Backend | Javarevisited&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 8, 2021&lt;/time&gt; ・ 6 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/tools/android-studio/docs/"&gt;Google Cloud Platform&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwio5YXQ2MLtAhX7yjgGHabuC8oQFjAAegQIARAD&amp;amp;url=https%3A%2F%2Fdeveloper.android.com%2Fstudio&amp;amp;usg=AOvVaw3fIlahucURgOEYHHhVdQuW"&gt;Android Studio&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/studio/build#module-level"&gt;Configuring your build&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/studio/debug/dev-options"&gt;Enable USB debugging on your phone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=2ahUKEwi23sKz48LtAhW_xDgGHdBfB7kQFjABegQIARAC&amp;amp;url=https%3A%2F%2Fmaterialdesignicons.com%2F&amp;amp;usg=AOvVaw0nKP6M_S9hl0vHqp8CiPth"&gt;Material Design&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/guide"&gt;Android App Developer’s guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://restfulapi.net/http-methods/"&gt;HTTP and the REST API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/android-ui/src/master/"&gt;GitHub Repository for the above code and resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bitbucket.org/ecommerce-webtutsplus/ecommerce/src/master/"&gt;GitHub Repository for the REST API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://138.68.64.95:8080/api/swagger-ui.html#/"&gt;Swagger-UI for the API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Let’s Build Signup, SignIn, and Role-Based Access in Our E-Commerce App</title>
      <dc:creator>KunalShekhar</dc:creator>
      <pubDate>Tue, 12 Jan 2021 13:04:43 +0000</pubDate>
      <link>https://forem.com/webtutsplus/let-s-build-signup-signin-and-role-based-access-in-our-e-commerce-app-18bl</link>
      <guid>https://forem.com/webtutsplus/let-s-build-signup-signin-and-role-based-access-in-our-e-commerce-app-18bl</guid>
      <description>&lt;p&gt;An Overview Of The Tutorial!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Introduction

Database Design

API Design

Demo overview

Signup

Dealing with the Android Application

Our Intention

Requirements

Dependencies

Permissions

Creating Models

Updating the API

Creating Activities

The Main Page

Signing Up Users

Signing In Users

Constructing the Dashboard

Running the Application

Resources
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;This is a series of tutorials we are building to demonstrate how to build an E-Commerce App, one component at a time.&lt;/p&gt;

&lt;p&gt;We are going to implement a basic authentication which will be extended to role-based access i.e. Admin can change anything, add new Users, a manager can only add/update Category and Products, users can only see the products and Category.&lt;/p&gt;

&lt;p&gt;When users/admin sign in, we will generate an authentication token, which will be used to verify the users, when they are going to access an API later.&lt;/p&gt;

&lt;p&gt;Database Design&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YqAeEQKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ijakbo2gz4d78ybecaxv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YqAeEQKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ijakbo2gz4d78ybecaxv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will have a user table and tokens table. For every user, when they signUp and sign in, we will generate a token, which will have an expiry date. After the expiry day has passed, we should generate a new token, although we will not cover it in the tutorial.&lt;/p&gt;

&lt;p&gt;API Design&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
UserController will have two methods, Signup and SignIn, which will be POST requests.&lt;/p&gt;

&lt;p&gt;Demo Overview&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UGAjCy5Jc4A"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;SignUp&lt;/p&gt;

&lt;p&gt;Let's look at signUp API. It takes SignupDto as Input and returns True or False as output depending upon if SignUp succeeds.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
We follow these steps for signup
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.Encrypt the password
2.Save the User
3.Generate auth token and save it in database
4.Return Success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We will now look at models that are mapped as a table in the database&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;User and Tokens are linked by user_id field in tokens table, which has one to one relationship, i.e one user can have one token and vice versa.&lt;/p&gt;

&lt;p&gt;User and Tokens are linked by user_id field in tokens table, which has one to one relationship, i.e one user can have one token and vice versa.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Let’s Build Signup, SignIn, and Role-Based Access in Our E-Commerce App</title>
      <dc:creator>KunalShekhar</dc:creator>
      <pubDate>Sun, 10 Jan 2021 07:21:28 +0000</pubDate>
      <link>https://forem.com/kunalshekhar/let-s-build-signup-signin-and-role-based-access-in-our-e-commerce-app-1l91</link>
      <guid>https://forem.com/kunalshekhar/let-s-build-signup-signin-and-role-based-access-in-our-e-commerce-app-1l91</guid>
      <description>&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/cfgwH4XQkvI"&gt;
&lt;/iframe&gt;
&lt;br&gt;
An Overview Of The Tutorial!&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Introduction

Database Design

API Design

Demo overview

Signup

Dealing with the Android Application

Our Intention

Requirements

Dependencies

Permissions

Creating Models

Updating the API

Creating Activities

The Main Page

Signing Up Users

Signing In Users

Constructing the Dashboard

Running the Application

Resources
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is a series of tutorials we are building to demonstrate how to build an E-Commerce App, one component at a time.&lt;/p&gt;

&lt;p&gt;We are going to implement a basic authentication which will be extended to role-based access i.e. Admin can change anything, add new Users, a manager can only add/update Category and Products, users can only see the products and Category.&lt;/p&gt;

&lt;p&gt;When users/admin sign in, we will generate an authentication token, which will be used to verify the users, when they are going to access an API later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database Design&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YqAeEQKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ijakbo2gz4d78ybecaxv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YqAeEQKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ijakbo2gz4d78ybecaxv.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will have a user table and tokens table. For every user, when they signUp and sign in, we will generate a token, which will have an expiry date. After the expiry day has passed, we should generate a new token, although we will not cover it in the tutorial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Design&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
UserController will have two methods, Signup and SignIn, which will be POST requests.

&lt;p&gt;&lt;strong&gt;Demo Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/UGAjCy5Jc4A"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SignUp&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's look at signUp API. It takes SignupDto as Input and returns True or False as output depending upon if SignUp succeeds.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
We follow these steps for signup
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1.Encrypt the password
2.Save the User
3.Generate auth token and save it in database
4.Return Success
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We will now look at models that are mapped as a table in the database&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;User and Tokens are linked by user_id field in tokens table, which has one to one relationship, i.e one user can have one token and vice versa.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Start building the Android Application&lt;/p&gt;

&lt;p&gt;Next, we are going to use the same REST API to perform the user authentication process in the same android application that we have created and deployed in the last tutorial. If you have not followed up, please check out the tutorial using the link given below.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://medium.com/javarevisited/lets-add-products-in-android-for-e-commerce-app-b8468e055001" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vm73w5AQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2AhNjwft_dNBxvTr6g6TOVGg.jpeg" alt="Nil Madhab"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://medium.com/javarevisited/lets-add-products-in-android-for-e-commerce-app-b8468e055001" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Let’s Add Products in Android for E-Commerce App | by Nil Madhab | Javarevisited | Dec, 2020 | Medium&lt;/h2&gt;
      &lt;h3&gt;Nil Madhab ・ &lt;time&gt;Jan 3, 2021&lt;/time&gt; ・ 7 min read
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KBvj_QRD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/medium_icon-90d5232a5da2369849f285fa499c8005e750a788fdbf34f5844d5f2201aae736.svg" alt="Medium Logo"&gt;
        Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Our Intention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our last tutorial above, we have created ways in our application to view, add, and update our products by communicating with our REST API service.&lt;/p&gt;

&lt;p&gt;Now we are going to limit the access of adding and updating products only to the authenticated users. Non-authenticated users can simply checkout all products we have, but they are not permitted to edit.&lt;/p&gt;

&lt;p&gt;Our intention is to achieve such functionality mentioned above in our application. Get ready to explore!&lt;br&gt;
&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Though we have no new requirements for the application to achieve basic authentication, let’s revise them for the new readers’ convenience.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Android Studio (Completely Setup with SDK)
Android Virtual Device
Cloud Hosted E-Commerce Backend API
Retrofit- to interact with the API
Glide- to load images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Steps to set up your work environment in Android Studio can be found here.&lt;br&gt;
Dependencies&lt;/p&gt;

&lt;p&gt;No new dependencies are needed for extending the user authentication functionality in our application. Anyway, I’ll showcase all dependencies we have used in our application.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recycler View
Card View
Retrofit
Gson converter
Glide
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Permissions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Same as dependencies, we don’t need any extra permissions to extend the required functionality to our application.&lt;/p&gt;

&lt;p&gt;We only need internet permissions to communicate with the RESTful service. It was added during the last-mentioned tutorial.&lt;/p&gt;

&lt;p&gt;You can check out the app/src/main/AndroidManifest.xml file of our application below-&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Creating Models&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We already have a model for the Product to send and receive through the API. Likewise, we need to create a model for the user to pass their credentials through our API.&lt;/p&gt;

&lt;p&gt;Our user model accepts the credentials first name, last name, email id, and a password to save a user to the backend and the respective user’s email id and password to sign in them into the application.&lt;/p&gt;

&lt;p&gt;Therefore, create a class User, that has four fields firstName, lastName, email, and password, as shown below-&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And now we have all the required models to interact with our API. Let’s go ahead with making the user objects interact with our RESTful service.&lt;br&gt;
Updating the API&lt;/p&gt;

&lt;p&gt;We need to update the interface API that we have created so that it also interacts with the Users API in our backend.&lt;/p&gt;

&lt;p&gt;We already have the interaction with the products API. Without disturbing that, we need to establish interaction with the Users API in our RESTful service. For the same, we are gonna update the API.java in our project.&lt;/p&gt;

&lt;p&gt;You can update the same as below-&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now we can interact with the Users API of our backend. Let’s move further!&lt;br&gt;
Creating Activities&lt;/p&gt;

&lt;p&gt;We all know that activities are the basic building blocks of the application. An activity consists of a layout file and a java class to control the same.&lt;/p&gt;

&lt;p&gt;We are provided with the pre-built activity called Main Activity. And also, we have added the following working activities to our application.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ListProducts Activity
AddProduct Activity
UpdateProduct Activity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;For this tutorial, we need three more activities to sign up a user, sign in a user, and show the dashboard to the users respectively. Go ahead and create the following activities by following the steps: Right-click on the MainActivity residing package -&amp;gt; New -&amp;gt; Activity -&amp;gt; Empty Activity&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SignupActivity

SigninActivity

DashboardActivity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;The Main Page&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The previous main page consisted mainly of buttons that navigate to add or update products and list products. But the functionalities of adding and updating products should be available only after the user is signing in. So, we are removing it from the main activity’s layout file.&lt;/p&gt;

&lt;p&gt;Instead of that, we are adding two buttons that navigate to the user signup and user sign-in activity. The respective layout file is as below-&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, we need to make those newly created buttons to navigate to respective activities. For that, add on click listeners to the buttons in the MainActivity.java as below-&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, let’s concentrate on signing up and signing in users through our application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WPTFv2UY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b7s0dxjaq7vej3683sd1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WPTFv2UY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b7s0dxjaq7vej3683sd1.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FmHjUeQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x6tvbleve2xou8gdcn46.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FmHjUeQT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x6tvbleve2xou8gdcn46.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signing Up Users&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We need mainly four edit texts — one for getting the first name, one for getting the last name, one for getting the email id and the last one for getting the password.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The input data has to be trimmed, validated and verified before we pass it to the backend. All these are done in the SignupActivity.java.&lt;/p&gt;

&lt;p&gt;An On Click Listener is added to the button that submit the data. Once the data is submitted, it is validated. After validation, a user object is created with the data and the object is passed through the API to Signup.&lt;/p&gt;

&lt;p&gt;Once the signup is completed successfully, the application navigates to the signin activity. The controlling file of the signup activity as below-&lt;/p&gt;

&lt;p&gt;And finally, we need a button to submit these data. The layout for the signup activity is modified as follows-&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ijimdcPZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fl9k8gu76y8ipprsnqvl.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ijimdcPZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fl9k8gu76y8ipprsnqvl.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We have the sign up part all ready. Let’s move to the sign in part of our application!&lt;br&gt;
Signing In Users&lt;/p&gt;

&lt;p&gt;For signing in users, we need just the user’s email to identify them and their password to verify them. To get them, we need two edit text views.&lt;/p&gt;

&lt;p&gt;And also, a button is needed to submit the data. Below given is the layout file for sign-in activity.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The data from this layout is fetched, processed and verified with the backend API by the SigninActivity.java. It also should contain the on click listener for the button to submit the data.&lt;/p&gt;

&lt;p&gt;Through the on click listener added, we receive the data from the fields and process it to create a user object. The object is then passed to the REST API, which verifies it and sends us a response to authenticate the user.&lt;/p&gt;

&lt;p&gt;After successful authentication of the user, they are directed to the dashboard activity of the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bzwap7Jq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5kp69y9h5nxbokecggqp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bzwap7Jq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5kp69y9h5nxbokecggqp.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;The only remaining task before us is to make the dashboard activity. Without any delay, let’s do that!&lt;br&gt;
Constructing the Dashboard&lt;/p&gt;

&lt;p&gt;The dashboard activity seems similar to that of our main activity. It can also be called the main activity for authenticated users.&lt;/p&gt;

&lt;p&gt;Authenticated users must be able to edit the products or add new products. For that sake, add the buttons for adding and updating the products. Also, add a button for viewing the products.&lt;/p&gt;

&lt;p&gt;The layout file of the dashboard activity should be constructed as follows-&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Let’s make these buttons in the dashboard activity functional! Go to the file DashboardActivity.java that controls the functioning of the activity. Add on click listeners to the buttons that we have added previously.&lt;/p&gt;

&lt;p&gt;Set up the navigation correctly so that the user is navigated to the respective activities from the buttons.&lt;/p&gt;

&lt;p&gt;The corresponding DashboardActivity.java file is as follows-&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aH22T__N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/byfqzha1wmx1tao1fwym.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aH22T__N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/byfqzha1wmx1tao1fwym.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Hurray! we have completed the coding section! Let’s run the application now!&lt;br&gt;
Running the Application

&lt;p&gt;Now, it’s time for running the application, after adding the required functionalities. Select the required Android Virtual Device from the toolbar and click on the run button on the same(Green triangle icon)&lt;/p&gt;

&lt;p&gt;After a certain amount of time, your android virtual device will get the application installed and opened. You can completely use it now!&lt;/p&gt;

&lt;p&gt;Some of its screenshots are as below —&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nkSzRQYk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/szi1pcke2st6zwo3z4sf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nkSzRQYk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/szi1pcke2st6zwo3z4sf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OpeZBptt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pf0g1mvygawzs97dubnh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OpeZBptt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pf0g1mvygawzs97dubnh.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kcKTzrio--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m3xfe0ommf16babcwmem.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kcKTzrio--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/m3xfe0ommf16babcwmem.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7rJffyBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/amhtn3stlf4xa12aqvty.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7rJffyBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/amhtn3stlf4xa12aqvty.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yahoo! That’s it! Hope you have learned many things from this tutorial. Stay tuned for such an awesome series of tutorials!&lt;/p&gt;

&lt;p&gt;Happy Learning!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
