shopping cart system
Add, delete, modify, check
Add shopping cart business logic:
Create an interceptor in the shopping cart system to determine whether the current user is logged in or not. Regardless of whether they are logged in or not, they must be able to use the shopping cart. The interception here is not used to intercept the request, but to determine whether the user is logged in, and store the login user information in the request .
Interceptor:
1. Get the token from the cookie
2. If you don't get the token and you are not logged in, let it go directly
3. If you get the token , you need to call the service of the sso system, and check the user information according to the token
① If you can't find it, it means that the login has expired, and you will be released directly
②If it is found, it means that the user has logged in, put the user information in the request , and let it go.
Controller:
1. Determine whether the user is logged in (by judging whether there is a user object in the request )
2. If it is in the login state, store the product information added to the shopping cart in redis (in hash data type: userId, itemId, json format of item object )
①Determine whether the product exists ( check redis according to userId and itemId )
② If it exists, add up the number of items
③ If it does not exist, get the product information from the database according to the product id , and store it in redis as a hash type
④ Return to the Add to Cart success page
3. If you are not logged in , store the product information added to the shopping cart in a cookie
①Retrieve the product list from the cookie
② Traverse the product list, if the corresponding product is found, add 1 to the quantity
③ If the corresponding product cannot be found, it means that the product does not exist in the cookie , query the product information according to the product id , get a product object, add it to the product list, and write the cookie
④ Return to the Add to Cart success page
Query the shopping cart business logic:
Interceptor:
1. Get the token from the cookie
2. If you don't get the token and you are not logged in, let it go directly
3. If you get the token , you need to call the service of the sso system, and check the user information according to the token
① If you can't find it, it means that the login has expired, and you will be released directly
②If it is found, it means that the user has logged in, put the user information in the request , and let it go.
Controller:
1. Determine whether the user is logged in (by judging whether there is a user object in the request )
2. If you are logged in
① Get the shopping cart list from the cookie
②If it is not empty, combine the shopping cart items in the cookie with the shopping cart items on the server, and delete the shopping cart data in the cookie
③ Take the product list from the server and pass the product list to the page
3. If you are not logged in
①Remove the shopping cart list from the cookie
② Pass the product list to the page
Modify the business logic of the number of items in the shopping cart:
Interceptor:
1. Get the token from the cookie
2. If you don't get the token and you are not logged in, let it go directly
3. If you get the token , you need to call the service of the sso system, and check the user information according to the token
① If you can't find it, it means that the login has expired, and you will be released directly
②If it is found, it means that the user has logged in, put the user information in the request , and let it go.
Controller:
1. Determine whether the user is logged in (by judging whether there is a user object in the request )
2. If you are logged in
①Retrieve product information from redis according to userId and itemId
② Update the number of products
③Written by redis
3. If you are not logged in
①Retrieve the product list from the cookie
② Traverse the product list to find the corresponding product
③ Update the number of products
④Write the product list into the cookie
The business logic for deleting the items in the shopping cart:
Interceptor:
1. Get the token from the cookie
2. If you don't get the token and you are not logged in, let it go directly
3. If you get the token , you need to call the service of the sso system, and check the user information according to the token
① If you can't find it, it means that the login has expired, and you will be released directly
②If it is found, it means that the user has logged in, put the user information in the request , and let it go.
Controller:
1. Determine whether the user is logged in (by judging whether there is a user object in the request )
2. If you are logged in
①Delete the data stored in redis according to userId and itemId
② Jump to the successful page of deleting the shopping cart
3. If you are not logged in
①Retrieve the product list from the cookie
② Traverse the product list to find the corresponding product
③ Delete product
④ Then write the product list into the cookie
⑤ Jump to the successful page of deleting the shopping cart