Code Monkey home page Code Monkey logo

productmanager's Introduction

Product Manager

The Product Manager is a micro-service that works as the catalog for an e-commerce app. It is built with the server-side Swift framework Vapor.

Setup

After you have forked and cloned the service, you will need to do a little setup so it can run:

  1. MySQL

    Product Manager stores its data in a MySQL database. First, you need to install it:

    Homebrew:

    brew install mysql
    mysql_secure_installation

    APT:

    sudo apt-get update
    sudo apt-get install mysql-server
    mysql_secure_installation

    By default, the service expects the MySQL user to be root and the password to be password, but you can either change the value in the configuration of set the DATABASE_USER and DATABASE_PASSWORD environment variables.

    You then need to create a database called product_manager, or, as before, you can name it something else and change the config or set DATABASE_DB

  2. JWT Tokens

    Product Manager uses JWT bearer authentication for protecting routes that mutate a collection (POST, PATCH, and DELETE routes). Product Manager relies on another service to create the token when the user authenticates, but it still needs to verify the token. To do this, it needs access to the token's public key. You can give access by assigning it to the JWT_PUBLIC key.

Documentation

You can read the API documentation here.

Vapor Cloud

The MySQL configuration is setup to work seamlessly with Vapor Cloud. Just make sure your replica has a MySQL database for it.

To set the JWT public key, you can run vapor cloud config modify JWT_PUBLIC=<TOKEN> from your project root.

productmanager's People

Contributors

calebkleveter avatar proggeramlug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

productmanager's Issues

Add CreatedAt, UpdatedAt & DeletedAt

Not urgent!

We need to add UpdatedAt and DeletedAt as all as CreatedAt for:

  • Products
  • Categories
  • Attributes
  • ProductAttributes
  • ProductCategories

Attribute structure needs to change

The way it should work is:

Attribute-Table contains all attributes that are available at all. Pretty much just the same.

Attribute-Product-Tabe contains the associations between the attribute and the product. So it would be:

  1. Attribute id
  2. product id
  3. value

Products need prices

Prices need to be assignable to products. Note: Multiple prices need to be assignable to the same product.

For example:

  • Piano = 50 USD, 45 EUR, 40 GBR (so 3 prices for the same product)

CategoryTree: Prohibit endless recursion

When two entries are invested (left = right & right = left) it can lead to endless recursion.

To prevent this we should:

  • Prevent the user from entering such a condition in the first place
  • More importantly though: Have the category-tree parser detect this and stop by itself

Filter

We need to implement a few filters for products:

  • By category (we have that already but we may want to change the URL structure for it)
  • By price (min & max price)
  • By attribute
  • By status

Ideally I would like to have a call like:

/products?minPrice=10&maxPrice=50&attribute[name]=Test+Product&status=1

or something like that

ElasticSearch

This one is not needed for quite a while but I don't want to loose sight of it:

We should use ElasticSearch as a Cache as well as a search engine for products. So every product would be put into elastic search as an exported json-string.

Through elastic search we can run effective searches and also cache outputs.

Order in category tree

Categories need to have a "sort" flag (integer) that will dictate the order in which they are showing. lowest = top, highest = bottom.

Sortable

This is neither urgent nor needed right now but will be relevant soon:

Every attribute and field of a product or category needs to be sortable. So for example:

  • Sort products by lowest price
  • sort products by name ascending
  • sort products by category name

Offsets

This is neither urgent nor needed right now but it will be needed soon:

Every list return (categories + products) needs to be returned in a format that we can put it on different pages. Say we have 1000 categories and 1000 products:

  1. We need a return with a max number of results ("per page") Like "25 per page". So every call should return max 25 results.
  2. We need a number of results in total (1000 products)
  3. We need an offset that we can set so that we get for example products 100-125.

Ideally this will look like:
products?max=25&offset=100
categories?max=25&offset=100

Should not be very hard to implement. It really just comes down to the sql function "LIMIT x, y".
Important though: The total number of results needs to be returned as well.

Categories are not always main categories

We need to have a flag that indicates whether a category is a main category or not. Some categories will only be sub categories and never main.

I suggest a flag called "mainCateegory" that is either true or false.

The tree should start with the main categories.

Attributes need to be translatable

This is neither urgent nor needed right now, but attributes should be translatable.

Use case is that an attribute may be a description that needs to be available in multiple languages.

CORS Headers

We need to add CORS headers so that web browser clients can load content.
"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://product-manager-development.vapor.cloud/categories. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).".

In Vapor 2 there was a middleware module that did the trick, do we have that in vapor 3 as well?

Add Revert Command to Service

Add RevertCommand to CommandConfig and register it to the application's services. This allows you to run vapor run revert to revert the database.

Creating attributes should be decoupled from products

The attribute controller/routes should have their own identity.

So we should have routes like
attributes/create
attributes/update
attributes (list)

etc. that deal with the attributes independently of products

likewise when creating an attribute for a product it should link to the ID of attribute.
so
POST products/1/attributes should take arguments such as (attributeId,language, value)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.