Skip to content

Commit 120cf93

Browse files
authored
Feature - Discussions connected to DB (#21)
* chore: NodeJS template added with middlewares: JOI and Boom. Jest added. * docs: added discussion endpoint documentation to readme.md (#4) * feat: discussion CRUD without SQL connection feat: CRUD without SQL connection docs: discussion endpoints updated * feat: cors for accepting all CORS request (#11) Added Cors for accepting all requests * Feature - Discussion_Like capabilities (#8) feat: CRUD without SQL connection for discussion_likes docs: discussion endpoints updated docs: like endpoints updated docs: readme.md modified with endpoint description for use * chore: Procfile added for Heroku deployment, port from environment added (#13) * chore: added dummy data for discussion testing (#17) * chore: dotenv capabilities added, .env.example file added (#20) chore: added localhost postgres environment chore: added db config docs: discussion endpoint doc modified feat: discussions db connection without pagination chore: migrations and seeders added for deployment docs: discussion instrictions added for local env
1 parent 348bd2f commit 120cf93

25 files changed

+7924
-104
lines changed

.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#Docker Postgres Variables
2+
POSTGRES_DB=communitydb
3+
POSTGRES_USER=dev_admin
4+
POSTGRES_PASSWORD=devAdmin123
5+
6+
#PGAdmin docker image
7+
PGADMIN_DEFAULT_EMAIL=admin@mail.com
8+
PGADMIN_DEFAULT_PASSWORD=root
9+
10+
#Server config
11+
PORT=3002
12+
13+
#Database connection configuration (If you are using docker postgress image, use the same configuration)
14+
DB_HOST=localhost
15+
DB_PORT=5432
16+
DB_USER=dev_admin
17+
DB_PASSWORD=devAdmin123
18+
DB_NAME=communitydb
19+
DB_SCHEMA= 'sch_comm'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,7 @@ $RECYCLE.BIN/
191191
# Windows shortcuts
192192
*.lnk
193193

194+
# Postgres data files
195+
data
196+
194197
# End of https://www.toptal.com/developers/gitignore/api/node,windows,linux,macos

.sequelizerc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
'config': './src/db/config.js',
3+
'models-path': './src/db/models/',
4+
'migrations-path': './src/db/migrations/',
5+
'seeders-path': './src/db/seeders/',
6+
}

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22
This backend API is used as an interface for Forum interaction with backend.
33

44
## Steps to run & deploy
5-
### Load and Connect Database
5+
6+
### Initial setup
7+
For local environment setup for first time, please copy information from file .env.example to .env and run following command:
8+
9+
docker-compose up -d
10+
11+
that will setup postgres and PGAdmin 4 for initial setup.
12+
13+
After that, run all migrations:
14+
15+
migrations:run
16+
17+
After migrations are completed as an aditional step you can copy information inside ./tests/dummy-data.json and create a file under ./src/data/ with the name seed_data.json. It contains the information for demo/testing purposes.
18+
19+
620

721
### Running in dev
822
For running your server in dev environment please use the following command:
@@ -41,21 +55,26 @@ You can get a list of all invoices using endpoint `/api/discussions/{id}` by a G
4155
"title": "Example Title",
4256
"content": "Example Content",
4357
"category": 1,
44-
"created_at": "2012-04-23T18:25:43.511Z",
45-
"created_by": 1,
46-
"modified_at": null,
47-
"modified_by": null,
58+
59+
"createdAt": "2012-04-23T18:25:43.511Z",
60+
"userId": 1,
61+
"modifiedAt": null,
62+
"modifiedBy": null,
4863
"status": 1,
49-
"discussion_version_no": 1
64+
"discussionVersionNo": 1
5065
}
5166
```
5267
### Create a new discussion
53-
You can create a new discussion using endpoint `/api/discussions/create` by a POST HTTP request with following body:
68+
You can create a new discussion using endpoint `/api/discussions` by a POST HTTP request with following body:
69+
5470
```json
5571
{
5672
"title": "Example Title",
5773
"content": "Example Content",
58-
"category": 1,
74+
75+
"categoryId": 1,
76+
"userId": 1
77+
5978
}
6079
```
6180
This will return the created discussion with void comments as:
@@ -65,12 +84,14 @@ This will return the created discussion with void comments as:
6584
"title": "Example Title",
6685
"content": "Example Content",
6786
"category": 1,
68-
"created_at": "2012-04-23T18:25:43.511Z",
69-
"created_by": 1,
70-
"modified_at": null,
71-
"modified_by": null,
87+
88+
"createdAt": "2012-04-23T18:25:43.511Z",
89+
"userId": 1,
90+
"modifiedAt": null,
91+
"modifiedBy": null,
7292
"status": 1,
73-
"discussion_version_no": 1
93+
"discussionVersionNo": 1
94+
7495
}
7596
```
7697
### Get all discussion likes
@@ -114,7 +135,8 @@ You can give like to an existing discussion using endpoint `/api/likes/discussio
114135
```json
115136
{
116137
"discussionId": 1,
117-
"user_id": 2
138+
"userId": 2
139+
118140
}
119141
```
120142
This will return the created like as:

app/app.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/routes/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: ‘3.3’
2+
3+
services:
4+
postgres:
5+
image: postgres:13
6+
env_file:
7+
.env
8+
ports:
9+
- 5432:5432
10+
volumes:
11+
- ./data/postgres:/var/lib/postgresql/data
12+
- ./sql/1_init.sql:/docker-entrypoint-initdb.d/1_init.sql
13+
restart: always
14+
networks:
15+
- default
16+
pgadmin:
17+
image: dpage/pgadmin4
18+
env_file:
19+
.env
20+
ports:
21+
- 5050:80

0 commit comments

Comments
 (0)