Skip to content

Commit 02a5bdb

Browse files
authored
Merge pull request #69 from CS3219-AY2425S1/PEER-236-Messaging-UI
PEER-236: Add-Chat-Functionality
2 parents 11e95c2 + 1493798 commit 02a5bdb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1936
-76
lines changed

.env.local

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@ MATCHING_DB_PASSWORD="password"
2020
MATCHING_DB_HOST_PORT=6378
2121
MATCHING_DB_HOST_MGMT_PORT=3001
2222

23+
CHAT_SERVICE_NAME=chat-express
24+
CHAT_EXPRESS_PORT=9005
25+
CHAT_EXPRESS_DB_PORT=5435
26+
CHAT_PGDATA="/data/chat-db"
27+
2328
FRONTEND_SERVICE_NAME=frontend
2429
FRONTEND_PORT=3000
30+
OPENAI_API_KEY=PUT_YOUR_OPENAI_API_KEY_HERE
31+

.github/workflows/build-deploy-docker.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
QUESTION_EXPRESS_PORT: 9002
1717
COLLAB_EXPRESS_PORT: 9003
1818
MATCH_EXPRESS_PORT: 9004
19+
CHAT_EXPRESS_PORT: 9005
1920
FRONTEND_PORT: 3000
2021

2122
jobs:
@@ -44,6 +45,8 @@ jobs:
4445
- 'backend/collaboration/**'
4546
matching:
4647
- 'backend/matching/**'
48+
chat:
49+
- 'backend/chat/**'
4750
frontend:
4851
- 'frontend/**'
4952
- name: output-job-matrix
@@ -91,6 +94,16 @@ jobs:
9194
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
9295
matrix+=("$config")
9396
fi
97+
if [[ "${{ steps.filter.outputs.chat }}" == "true" || "$is_main" == "true" ]]; then
98+
config=$(jq -n \
99+
--arg pkg "chat" \
100+
--arg img "$DOCKER_REGISTRY_USN/chat-express" \
101+
--arg ctx "./backend/chat" \
102+
--arg dkr "./backend/chat/express.Dockerfile" \
103+
--arg bag "port=$CHAT_EXPRESS_PORT" \
104+
'{package: $pkg, image: $img, context: $ctx, dockerfile: $dkr, "build-args": $bag}')
105+
matrix+=("$config")
106+
fi
94107
if [[ "${{ steps.filter.outputs.frontend }}" == "true" || "$is_main" == "true" ]]; then
95108
config=$(jq -n \
96109
--arg pkg "frontend" \

backend/chat/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist/

backend/chat/.env.compose

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EXPRESS_PORT=9005
2+
EXPRESS_DB_HOST=chat-db
3+
EXPRESS_DB_PORT=5435
4+
POSTGRES_DB=chat
5+
POSTGRES_USER=peerprep-chat-express
6+
POSTGRES_PASSWORD=Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ=
7+
PGDATA="/data/chat-db"

backend/chat/.env.docker

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PEERPREP_UI_HOST=http://host.docker.internal:5173
2+
3+
EXPRESS_PORT=9005
4+
EXPRESS_DB_HOST=host.docker.internal
5+
EXPRESS_DB_PORT=5435
6+
POSTGRES_DB=chat
7+
POSTGRES_USER=peerprep-chat-express
8+
POSTGRES_PASSWORD=Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ=
9+
PGDATA=/data/chat-db

backend/chat/.env.local

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PEERPREP_UI_HOST=http://localhost:5173
2+
3+
EXPRESS_PORT=9005
4+
EXPRESS_DB_HOST=localhost
5+
EXPRESS_DB_PORT=5435
6+
POSTGRES_DB=chat
7+
POSTGRES_USER=peerprep-chat-express
8+
POSTGRES_PASSWORD=Xk8qEcEI2sizjfEn/lF6mLqiyBECjIHY3q6sdXf9poQ=
9+
PGDATA=/data/chat-db

backend/chat/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Matching Service
2+
3+
## Running with Docker (Standalone)
4+
5+
1. Run this command to build:
6+
```sh
7+
docker build \
8+
-t chat-express-local \
9+
--build-arg port=9005 \
10+
-f express.Dockerfile .
11+
```
12+
2. Run this command, from the roxot folder:
13+
14+
```sh
15+
make db-up
16+
```
17+
18+
3. Run the necessary migrate and seed commands, if you haven't yet.
19+
20+
4. Run this command to expose the container:
21+
```sh
22+
docker run -p 9005:9005 --env-file ./.env.docker chat-express-local
23+
```
24+
5. To stop the process, use the Docker UI or CLI with `docker rm -f <container_id>` (The child process loop has issues terminating)
25+
26+
## Running with Docker-Compose (Main config)
27+
28+
Edit the variables in the `.env.compose` file and run `make up` from the root folder.
29+
30+
Any startup instructions will be run from `entrypoint.sh` instead.

backend/chat/drizzle.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig } from 'drizzle-kit';
2+
3+
const config = {
4+
host: process.env.EXPRESS_DB_HOST!,
5+
port: Number.parseInt(process.env.EXPRESS_DB_PORT!),
6+
database: process.env.POSTGRES_DB!,
7+
user: process.env.POSTGRES_USER,
8+
password: process.env.POSTGRES_PASSWORD,
9+
};
10+
11+
export default defineConfig({
12+
schema: './src/lib/db/schema.ts',
13+
out: './drizzle',
14+
dialect: 'postgresql',
15+
dbCredentials: config,
16+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
DO $$
2+
BEGIN
3+
CREATE TYPE "public"."action" AS ENUM('SEED');
4+
EXCEPTION
5+
WHEN duplicate_object THEN null;
6+
END $$;
7+
8+
CREATE TABLE IF NOT EXISTS "admin" (
9+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
10+
"created_at" timestamp DEFAULT now(),
11+
"action" "public"."action" NOT NULL
12+
);
13+
14+
CREATE TABLE IF NOT EXISTS "chat_messages" (
15+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
16+
"room_id" varchar(255) NOT NULL,
17+
"sender_id" uuid NOT NULL,
18+
"message" text NOT NULL,
19+
"created_at" timestamp DEFAULT now()
20+
);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"id": "fb253102-46c6-477c-a0e6-5dad3ea879eb",
3+
"prevId": "00000000-0000-0000-0000-000000000000",
4+
"version": "7",
5+
"dialect": "postgresql",
6+
"tables": {
7+
"public.admin": {
8+
"name": "admin",
9+
"schema": "",
10+
"columns": {
11+
"id": {
12+
"name": "id",
13+
"type": "uuid",
14+
"primaryKey": true,
15+
"notNull": true,
16+
"default": "gen_random_uuid()"
17+
},
18+
"created_at": {
19+
"name": "created_at",
20+
"type": "timestamp",
21+
"primaryKey": false,
22+
"notNull": false,
23+
"default": "now()"
24+
},
25+
"action": {
26+
"name": "action",
27+
"type": "action",
28+
"typeSchema": "public",
29+
"primaryKey": false,
30+
"notNull": true
31+
}
32+
},
33+
"indexes": {},
34+
"foreignKeys": {},
35+
"compositePrimaryKeys": {},
36+
"uniqueConstraints": {}
37+
},
38+
"public.chat_messages": {
39+
"name": "chat_messages",
40+
"schema": "",
41+
"columns": {
42+
"id": {
43+
"name": "id",
44+
"type": "uuid",
45+
"primaryKey": true,
46+
"notNull": true,
47+
"default": "gen_random_uuid()"
48+
},
49+
"room_id": {
50+
"name": "room_id",
51+
"type": "varchar(255)",
52+
"primaryKey": false,
53+
"notNull": true
54+
},
55+
"sender_id": {
56+
"name": "sender_id",
57+
"type": "uuid",
58+
"primaryKey": false,
59+
"notNull": true
60+
},
61+
"message": {
62+
"name": "message",
63+
"type": "text",
64+
"primaryKey": false,
65+
"notNull": true
66+
},
67+
"created_at": {
68+
"name": "created_at",
69+
"type": "timestamp",
70+
"primaryKey": false,
71+
"notNull": false,
72+
"default": "now()"
73+
}
74+
},
75+
"indexes": {},
76+
"foreignKeys": {},
77+
"compositePrimaryKeys": {},
78+
"uniqueConstraints": {}
79+
}
80+
},
81+
"enums": {
82+
"public.action": {
83+
"name": "action",
84+
"schema": "public",
85+
"values": [
86+
"SEED"
87+
]
88+
}
89+
},
90+
"schemas": {},
91+
"sequences": {},
92+
"_meta": {
93+
"columns": {},
94+
"schemas": {},
95+
"tables": {}
96+
}
97+
}

0 commit comments

Comments
 (0)