This is a back end API. The intention here is to mimick the building of a real world backend service (such as reddit) which provides information to the front end architecture.
The main database is built with PSQL by using node-postgres.
The Live Chat is separate and built with mongoDB cloud database.
I have combined the express server and socketIO server into one single listener.
- Front End Git Repo:
- Front End hosted version:
- Tested minimum version of Node v16.13.1.
- Clone the entire repo into a local folder, type 'npm install' in terminal to install all dependencies before running the app.
$ git clone https://github.com/cynthiaswill/NC_Games_Board.git
$ cd NC_Games_board
$ npm install
-
You will need to create two
.envfiles for your project:.env.testand.env.development. Into each, addPGDATABASE=<database_name_here>, with the correct database name for that environment (see/db/setup.sqlfor the database names). Double check that these.envfiles are .gitignored. -
You have also been provided with a
dbfolder with some data, a setup.sql file and aseedsfolder.
- After installed dependencies, you will need to run the following in terminal to setup database
$ npm run setup-dbs
You need to complete the provided seed function to insert the appropriate data into your database by running following scripts:
npm run seed
npm run seed-test
This will create tables
categories, reviews, users and comments.
Each category have:
slugfield which is a unique string that acts as the table's primary keydescriptionfield which is a string giving a brief description of a given category
Each user have:
usernamewhich is the primary key & uniqueavatar_urlname
Each review have:
review_idwhich is the primary keytitlereview_bodydesignerreview_img_urldefaults tohttps://images.pexels.com/photos/163064/play-stone-network-networked-interactive-163064.jpegvotesdefaults to 0categoryfield which references the slug in the categories tableownerfield that references a user's primary key (username)created_atdefaults to the current timestamp
Each comment have:
comment_idwhich is the primary keyauthorfield that references a user's primary key (username)review_idfield that references an review's primary keyvotesdefaults to 0created_atdefaults to the current timestampbody
$ npm start
You can also use
$ npm run dev
to start development server, which will automatically re-seed the data, or typing:
$ npm run test
to run test by jest, which will re-seed a pool of test data automatically.
Essential endpoints
GET /api/categories
GET /api/reviews/:review_id
PATCH /api/reviews/:review_id
GET /api/reviews
GET /api/reviews/:review_id/comments
POST /api/reviews/:review_id/comments
DELETE /api/comments/:comment_id
GET /apiGET /api/users
GET /api/users/:username
PATCH /api/comments/:comment_idAll endpoints send the responses specified below in an object, with a key name of what it is that being sent. E.g.
{
"categories": [
{
"description": "Abstact games that involve little luck",
"slug": "Euro games"
},
{
"description": "Players attempt to uncover each other's hidden role",
"slug": "Social deduction"
}
]
}Responds with an overview of the API:
- JSON describing all the available endpoints on your API
Responds with:
- an array of category objects, each of which should have the following properties:
slugdescription
Responds with:
-
a review object, which should have the following properties:
ownerwhich is theusernamefrom the users tabletitlereview_idreview_bodydesignerreview_img_urlcategorycreated_atvotescomment_countwhich is the total count of all the comments with this review_id - you should make use of queries to the database in order to achieve this
Request body accepts:
-
an object in the form
{ inc_votes: newVote }newVotewill indicate how much thevotesproperty in the database should be updated by
e.g.
{ inc_votes : 1 }would increment the current review's vote property by 1{ inc_votes : -100 }would decrement the current review's vote property by 100
Responds with:
- the updated review
Responds with:
- an
reviewsarray of review objects, each of which should have the following properties:ownerwhich is theusernamefrom the users tabletitlereview_idcategoryreview_img_urlcreated_atvotescomment_countwhich is the total count of all the comments with this review_id - you should make use of queries to the database in order to achieve this
Should accept queries:
sort_by, which sorts the reviews by any valid column (defaults to date)order, which can be set toascordescfor ascending or descending (defaults to descending)category, which filters the reviews by the category value specified in the query
Responds with:
- an array of comments for the given
review_idof which each comment should have the following properties:comment_idvotescreated_atauthorwhich is theusernamefrom the users tablebody
Request body accepts:
- an object with the following properties:
usernamebody
Responds with:
- the posted comment
Should:
- delete the given comment by
comment_id
Responds with:
- status 204 and no content
Responds with:
- an array of objects, each object should have the following property:
username
Responds with:
- a user object which should have the following properties:
usernameavatar_urlname
Request body accepts:
-
an object in the form
{ inc_votes: newVote }newVotewill indicate how much thevotesproperty in the database should be updated by
e.g.
{ inc_votes : 1 }would increment the current comment's vote property by 1{ inc_votes : -1 }would decrement the current comment's vote property by 1
Responds with:
- the updated comment
- Should accepts the following queries:
limit, which limits the number of responses (defaults to 10)p, stands for page which specifies the page at which to start (calculated using limit)
- add a
total_countproperty, displaying the total number of reviews (this should display the total number of reviews with any filters applied, discounting the limit)
Should accept the following queries:
limit, which limits the number of responses (defaults to 10)p, stands for page which specifies the page at which to start (calculated using limit)
Request body accepts:
-
an object with the following properties:
ownerwhich is theusernamefrom the users tabletitlereview_bodydesignercategorywhich is acategoryfrom the categories table
Responds with:
- the newly added review, with all the above properties as well as:
review_idvotescreated_atcomment_count
Request body accepts:
- an object in the form:
{
"slug": "category name here",
"description": "description here"
}Responds with:
- a category object containing the newly added category
Should:
- delete the given review by review_id
Respond with:
- status 204 and no content
-
GET /api/users
-
PATCH /api/comments/:comment_id
-
Patch: Edit an review body
-
Patch: Edit a comment body
-
Patch: Edit a user's information
-
Get: Search for an review by title
-
Post: add a new user
-
GET /api/messages
- serves an array of all online users
-
PATCH /api/messages
- update a list of online users
-
GET /api/messages/:room
- serves an array of all messages from a specific chat room
- There is a file in root of this folder called
request.restwhich shows example of all requests can be sent to this API. To see the example of responce, please check overview on API route at/api.