Skip to content

Commit 7cd1f5b

Browse files
backend setup
1 parent dd99301 commit 7cd1f5b

File tree

5 files changed

+224
-40
lines changed

5 files changed

+224
-40
lines changed

README.md

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
1-
details:
2-
3-
database used: postgres (docker)
4-
5-
- postgres docker image pull:
6-
docker pull postgres
7-
8-
- postgres docker container run:
9-
sudo docker run --name postgres-nexus -e POSTGRES_USER=postgres -e \ POSTGRES_PASSWORD=nexus -e POSTGRES_DB=nexus_db -p 5432:5432 -d postgres
10-
11-
12-
container name: postgres-nexus
13-
database: nexus_db
14-
postgres user: postgres
15-
postgres password: nexus
16-
17-
- manipulate database nexus_db:
18-
- docker exec -it postgres-container bash
19-
- su - postgres
20-
- psql -d nexus_db
21-
22-
23-
For each event :
24-
- CREATE TABLE events (
25-
id SERIAL PRIMARY KEY,
26-
title VARCHAR(255) NOT NULL,
27-
date DATE NOT NULL,
28-
type VARCHAR(255) DEFAULT 'offline'
29-
description TEXT,
30-
image VARCHAR(255),
31-
link VARCHAR(255)
32-
);
1+
### Details:
2+
- Backend to https://github.com/pawarspeaks/TechNexus
3+
4+
### Prequisites:
5+
- nodejs
6+
- docker
7+
8+
### Steps to run the project:
9+
- npm install
10+
- docker postgres docker image pull:```docker compose up```
11+
- node index.js
12+
13+
### Schema:
14+
15+
- database: events_db
16+
- table: events
17+
18+
### API Endpoints:
19+
- GET /events: Retrieve all events.
20+
- GET '/events/online'
21+
- GET '/events/offline'
22+
23+
24+
25+
** To play around with the database
26+
```
27+
docker exec -it <docker-postgres-container> bash
28+
su - postgres
29+
psql -d <db-name>
30+
```

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const app = express();
66
const port = 3000;
77

88
const pool = new Pool({
9-
user: 'nexus',
9+
user: 'postgres',
1010
host: 'localhost',
11-
database: 'nexus_db',
12-
password: 'nexus',
11+
database: 'events_db',
12+
password: 'password',
1313
port: 5432,
1414
});
1515

@@ -23,7 +23,7 @@ app.get('/', (req, res) => {
2323
res.send('Hello from the Node.js backend!');
2424
});
2525

26-
app.get('/events/all', async (req, res) => {
26+
app.get('/events', async (req, res) => {
2727
try {
2828
const result = await pool.query('SELECT * FROM events');
2929
res.json(result.rows);
@@ -35,7 +35,7 @@ app.get('/events/all', async (req, res) => {
3535

3636
app.get('/events/online', async (req, res) => {
3737
try {
38-
const result = await pool.query('SELECT * FROM events');
38+
const result = await pool.query(`SELECT * FROM events WHERE type = 'online'`);
3939
res.json(result.rows);
4040
} catch (err) {
4141
console.error(err);
@@ -45,7 +45,7 @@ app.get('/events/online', async (req, res) => {
4545

4646
app.get('/events/offline', async (req, res) => {
4747
try {
48-
const result = await pool.query('SELECT * FROM events where eve');
48+
const result = await pool.query(`SELECT * FROM events WHERE type = 'offline'`);
4949
res.json(result.rows);
5050
} catch (err) {
5151
console.error(err);

init.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- Create the events table
2+
CREATE TABLE events (
3+
id SERIAL PRIMARY KEY,
4+
title VARCHAR(255) NOT NULL,
5+
date DATE NOT NULL,
6+
type VARCHAR(255) DEFAULT 'offline',
7+
description TEXT,
8+
image VARCHAR(255),
9+
link VARCHAR(255)
10+
);
11+
12+
-- Insert sample data
13+
INSERT INTO events (
14+
title, date, type, description, image, link
15+
) VALUES (
16+
'AI Driven India Hackathon 2024', '2024-11-15', 'offline', 'The AI-Driven India Hackathon is proudly organized by XLRI Jamshedpur in collaboration with Vipas.AI, empowering AI creators to create and showcase innovative AI solutions.', '/images/onlineEvents/ai_driven_india_hackathon.png', 'https://vipas.ai/hackathon/register'
17+
);
18+
19+
INSERT INTO events (
20+
title, date, type, description, image, link
21+
) VALUES (
22+
'Flutter Conf India 2023', '2023-12-09', 'offline',
23+
'Get ready to dive deep into the world of Dart and Flutter at Flutter Conf India, the country''s leading conference dedicated to top-quality content.', '/images/onlineEvents/flutterconfin.png', 'https://konfhub.com/flutterconfin'
24+
);
25+
26+
INSERT INTO events (
27+
title, date, type, description, image, link
28+
) VALUES (
29+
'CYBERX INDIA ROADSHOW 2023', '2023-11-03', 'offline', 'Join over 200+ leading cybersecurity experts with this Roadshow in Delhi and Bangalore for insightful and cutting-edge discussions on latest cybersecurity trends in INDIA.', '/images/onlineEvents/cyberx.png', 'https://www.cyberxindia.com/'
30+
);
31+
32+
INSERT INTO events (
33+
title, date, type, description, image, link)
34+
VALUES ('Flutter Conf India 2023', '2023-12-09', 'online', 'Get ready to dive deep into the world of Dart and Flutter at Flutter Conf India, the country''s leading conference dedicated to top-quality content.', '/images/offlineEvents/flutterconfin.png', 'https://konfhub.com/flutterconfin');
35+
36+
INSERT INTO events
37+
(title, date, type, description, image, link)
38+
VALUES ('CYBERX INDIA ROADSHOW 2023', '2023-11-03', 'online', 'Join over 200+ leading cybersecurity experts with this Roadshow in Delhi and Bangalore for insightful and cutting-edge discussions on latest cybersecurity trends in INDIA.', '/images/offlineEvents/cyberx.png', 'https://www.cyberxindia.com/');

package-lock.json

Lines changed: 148 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"license": "ISC",
1212
"dependencies": {
1313
"cors": "^2.8.5",
14-
"express": "^4.21.1"
14+
"express": "^4.21.1",
15+
"pg": "^8.13.0"
1516
}
1617
}

0 commit comments

Comments
 (0)