Skip to content

anil-moharana/Appiness-Task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Appiness-Task

##Steps to Run:

  1. Download the zip file
  2. Unzip it.
  3. You can import it Visaul Studio Code(Open Terminal) or Run by CMD
  4. Navigate inside of Appiness-Task(cd Appiness-Task-master)
  5. Run "npm install" to import all npm modules
  6. Navigate inside of src folder
  7. Run node index.js
  8. Open another CMD or terminal

##Steps to Run MongoDB:

1.Install MongoDB
2.Create a folder mongodb-data for string data
3.To start mongo,run below command inside of Appiness-Task-master(/bin/mongod.exe --dbpath=/mongodb-data)
4.make sure you give correct path to data folder and run it
5.Install Robo3T(connect to MongoDB) for visualization and connect to mongo db localhost:27017

##------------------------------Collection Structure in MongoDB---------------

 catalog|
    |-categories
    |-products

Categories:

/* 1 */ { "_id" : ObjectId("5e8759cf338a9a24d80c3c0e"), "name" : "Computer Accessories", "__v" : 0 }

/* 2 */ { "_id" : ObjectId("5e875a09338a9a24d80c3c0f"), "name" : "Mobile", "__v" : 0 }

/* 3 */ { "_id" : ObjectId("5e875a0e338a9a24d80c3c10"), "name" : "Fashion", "__v" : 0 }

products:

/* 1 */ { "_id" : ObjectId("5e875aaa338a9a24d80c3c11"), "name" : "Hm Shirt", "description" : "An HM Product", "owner" : "Fashion", "__v" : 0 }

/* 2 */ { "_id" : ObjectId("5e875ac5338a9a24d80c3c12"), "name" : "iPhone11", "description" : "An Apple Product", "owner" : "Mobile", "__v" : 0 }

/* 3 */ { "_id" : ObjectId("5e875ad2338a9a24d80c3c13"), "name" : "Honor9", "description" : "An Honor Product", "owner" : "Mobile", "__v" : 0 }

/* 4 */ { "_id" : ObjectId("5e875aed338a9a24d80c3c14"), "name" : "Hp Mouse", "description" : "An HP Product", "owner" : "Computer Accessories", "__v" : 0 }


RelationShip between Caterory and Prodcut:
Category "name" is taken as foreign field in products as "owner".
So When you retrieve category ,it will retreive corresponding products that belongs that particular category.

##API TESTING

AddNewCategory:
endpoint: localhost:3000/addNewCategory
method:post
requestBody:
{ "name":"Mobile" }


Add multiple Category similary One by One

AddNewProduct:
endpoint: localhost:3000/addNewProduct
method:post
requestBody:
{ "name":"iPhone11", "description":"An Apple Product", "owner":"Mobile" }


You add mutiple similarly one by one


#If you see above category "Mobile" has been taken as owner in Product to provide one-to-many relationship

getAllCategoryWithProducts:
endpoint: localhost:3000/getAllCategoryWithProducts
method:get

Response:
[ { "name": "Mobile", "productsArr": [ { "name": "iPhone11", "description": "An Apple Product", "owner": "Mobile" }, { "name": "Honor9", "description": "An Honor Product", "owner": "Mobile" } ] } ]


If you see Response ,productsArr[] property is there which I am generating as virtual field uisng moongoose schema for Category which contains all products belonging to a particular category.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published