RESTful route structure of 3 related categories in Express/Node - javascript

I am a noob designing an API for an ecommerce site and I need to work out my restful route structure. We are basically using Node and React along with Express + GraphQL. I was wondering if someone could shine a light on the structure?
Here is what we Have:
It is a fashion store that has many products: skirts, blouses, tops, shirts, dresses, etc. You know the drill.
Each of these items will be in categories like this:
/dresses (GET all dresses)
/dresses/:id (GET a particular dress)
/skirts (GET all skirts)
/skirts/:id (GET a particular skirt)
In addition to all the products and the categories of products, at the top level we have DESIGNERS.
So, you would have a designer who has many categories, and each category has many products. Make sense?
I am puzzling over how to nest the express routes.
I want to do these things....
Get all designers
Get all categories a designer has a product in
Get all products a designer has in the store
Get an individual (:id) of a product a designer has.
by the same token I also want to ...
Get all categories.
Get all products in a category
Get and individual product (:id) in a category.
So we have a parent route (designers)
and then two child routes (I think) within designers which
are /categories, /categories/:id, and /categories/products, and /categories/products/:id
Could someone get me a code hint on creating the routes in express? I am wanting to create a JSON structure to render with this
Thanks!

You're essentially asking how to build out an entire REST framework for a backend, which is quite a lengthy thing to answer :)
I'd suggest you start by designing the structure of the JSON for all these objects. Here's a handy site that allows you to visually see the layout of the JSON: https://jsoneditoronline.org/
Once you've done that for all the objects you've mentioned, here's a good tutorial on how to build basic node.js endpoints: https://medium.com/#purposenigeria/build-a-restful-api-with-node-js-and-express-js-d7e59c7a3dfb

Related

GatsbyJS, linking related items from CMS data using GraphQL

I am more of a beginner with graphql and a bit confused between learning the basics and how Gatsby uses it to import all data for its static site needs. And wanted to know what might be best practice when it comes to my situation.
I have two content types setup in GraphCMS. {Content type A} links to {Content type B} in a one to many relationship. And in my site I have a few places where I want a list of A that shows the links to B in them and visa versa.
I would love any ideas on what might be the best way to go about making this data available when its imported from Graphcms on build startup/generation of pages. I could just reference all fields twice (using fragments?) in the configs query. Or do I query each the list of a and b separate and have a field reserved for their id and then in gatsby-node attach their linked items matching their ids. Alternatively it could be done at on client side but I imagine i should take full advantage of the generator tools?
Any and all help is greatly appreciated.

JHipster - add a relationship to jhi_user_authority

I'm acutually trying to make a one-to-many relationship between the auto generated table "jhi_user_authority" and my own table called socialMediaFilter.
My situation is the following:
On the one side I have users, these are saved in the table "jhi_user" these users have roles and the roles for themselves are saved in a table called "jhi_authority". Between users and roles is a many-to-many relation, that means that many users can have many roles. These relationships are saved in a join-table called "jhi_user_authority". All these 3 tables are auto-generated by Jhipster when I created the project.
In my project I need to add some filters for filtering data from social media networks, twitter, fb and so on. A filter belongs to a role and a role can have many filters. So between these two tables is a one-to-many relationship and I'm struggling implementing this in my project.
I cannot access these auto-generated tables with the jhipster:entity generator. When I'm using for example yo jhipster:entity authority jhipster tries to generate a new entity. And as far as I know - these auto-generated tables are not meant to be accessed by the entity-generator. So when I want to edit them I need to edit them manually, so I can not follow the instructions in the tutorial.
Is there maybe someone who can pushes me to right direction? :D
thanks,
Alex
EDIT:
okay...after thinking for a while i figured out that i need to do it different
the relationships i need to implement should be like this uml
but i still have problems realizing it
Good morning, you have to do an n-m relation with the "Authority" class, in which you must specify that the relationship table is "jhi_user_authority"

Should I use angular for a keyword/product aggregator website?

I am developing a website where users can search for products using keywords. The one of the main functions is searching and showing the search results. Each search result (product) clicks onto a detail page (which will be deleted in 2 weeks +)
What I'v Done
Developed the UI/Javascript for the website.
All product components in the html/css are reusable
So all of the basic stuff is done. Now I'm focusing on AJAX and maybe Angular depending on your opinions as well.
My partner is building the backend in Node. He told me he will send search results in JSON and ill have to use AJAX to grab it. So far I'v learned how to store the JSON object in the user's localStorage (local).
Now I can't wrap my head around how I'm going to transfer the data and display a certain number of products on the page etc..
I have some pieces but not the details.
If you can help me the areas I'm lacking that will be great, thank you.
Google list:
ng-repeat to iterate through collection
Angular Directives to create reusable DOM
ng-include if you have to display inline details
ng-if to determinate functionality for above (not ng-show coz it have troubles in IE9-)
ui-router to create separate details "states" (aka pages)
$state to translate through application
$stateParams to determinate id of products to display on details page
About AJAX and JSONs responses that you will acquire:
{
items: [{ id:0, ... }], //collection of products
meta: {
totalPagesCount: '100',
totalItemsCount: '1000'
itemsPerPage: '10',
currentPage: '1',
}
}
Power that let you adapt to anything
Power that let you to find anything
Obviously you will create two directives and one controller:
Directive for items
Directive for paging
Controller to serve the page handling your input that will send requests for collection with keyword as GET parameter and translate updated data to directives
Service that will do business logic as $http.get() with deserialization (if needed), storing information (if you gonna cache something) etc.
Passing in ng-model of your directives appropriate values of collection, pagination etc will let you avoid writing $watch and business logic inside of controller.
Keep everything simple, clear and paterned.

How can I use D3 to graph configuration items and their dependencies?

I'm a new user to D3 and am trying to think about how to best implement a mapping of our configuration items.
What I'm looking for is essentially a treemap (I think) but with inter-related dependencies.
The Data
I'm working with ITIL-style configuration items, so logical services, applications, machines, etc. that make up an IT service that we offer to our customers.
The JSON data I'd be providing is going to come from a WebAPI service that I am defining and so the data can be returned however is necessary.
The Goal
I need to get across:
The name of the configuration item ("Service A", "Server 1", "Database XYZ", etc.)
The configuration item type (represented by either an icon or color -- not too important right now)
Those things with the least dependents at the top
i.e. a service is represented by all the things that compose it -- applications, DBs, etc. and I'd like to have the hierarchy in order from services down.
The relationships between all the elements, which aren't strictly hierarchical.
Multiple services could depend on one application
Multiple applications could depend on multiple databases which could depend on one database server.
If possible, the ability to focus on one branch of the tree from top to bottom by clicking on it (though this can come way later)
Once I get my head around it, I'd like to set up something simple on GitHub and see if I can use D3 to help contribute to the world of IT Service Management.
The Question
Philosophically, is D3 designed to support a visualization of this nature, and what is my best route to accomplish it?
Thanks!

Controller and View for creating one-to-many object, both "container" and unlimited number of "content" objects?

Users will be able to write some documents. Those documents will consists of chapters (one-to-many relation).
Normally I would do this by creating separate views for creating chapter and document.
How to implement web page that allow to edit "composite" view? Where I can edit document details, but also create chapters, without visiting different pages? Also how can I ensure that I pass order of chapter user have arranged (by moving chapters freely up and down)?
(Sorry if that question already have be asked&answered but I do not even know how to search for it :| since I do not know proper keywords beyond "AJAX", so help in naming my requirement would also be welcomed!)
Backend servers applications based on REST principles work nicely with Ajax client-side implementations.
For example, your URLs could be:
/book/1
/book/1/chapters
/book/1/chapter/1
You could set it up so that a POST to /book/1/chapters would add a chapter. A GET on that same URL would return all chapters. A GET on /book/1/chapter/1/ would only return chapter 1. A PUT on /book/1/chapter/1/ would update an existing chapter. This is a "RESTful" architecture:
http://en.wikipedia.org/wiki/Representational_state_transfer
This is an interesting introduction: http://tomayko.com/writings/rest-to-my-wife
This is a big subject, but if you create the right backend server architecture you will find your job a lot easier. Hope this helps answer your question.
Ok Partial solution.
Just google Nested Forms Ruby on Rails. Plenty of examples, all in ajax, all easy.

Categories