Skip to content

Commit 3114a9e

Browse files
committed
Merge remote-tracking branch 'origin/main' into connect-frontend-with-user-service
2 parents dbf74f6 + f906bf1 commit 3114a9e

35 files changed

+995
-68
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,64 @@
55
### Note:
66
- You can choose to develop individual microservices within separate folders within this repository **OR** use individual repositories (all public) for each microservice.
77
- In the latter scenario, you should enable sub-modules on this GitHub classroom repository to manage the development/deployment **AND** add your mentor to the individual repositories as a collaborator.
8-
- The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements.
8+
- The teaching team should be given access to the repositories as we may require viewing the history of the repository in case of any disputes or disagreements.
9+
10+
## Pre-requisites
11+
12+
1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)
13+
2. Clone the GitHub repository
14+
```
15+
git clone https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g03.git
16+
```
17+
18+
## Getting Started
19+
20+
**Step 1: Copy Environment Configuration File**
21+
22+
To get started, copy the contents of `.env.sample` into a new `.env` file located at the root level of the project.
23+
24+
**Step 2: Build the Docker containers**
25+
26+
Next, run the following command to build the Docker containers.
27+
28+
```bash
29+
docker compose -f compose.yml build --no-cache
30+
```
31+
32+
**Step 3: Start the Docker containers**
33+
34+
Once the build is complete, you can start the Docker containers.
35+
36+
```bash
37+
docker compose -f compose.yml up -d
38+
```
39+
40+
After spinning up the services, you may access the frontend client at `127.0.0.1:4200`. Specifically, you can navigate to the Question SPA at `127.0.0.1:4200/questions` and the login page at `127.0.0.1/account`.
41+
42+
If you would like to spin up the services in development mode, you may use the following command. This enables hot reloading and exposes the ports for all microservices.
43+
44+
```bash
45+
docker compose -f compose.yml -f compose.dev.yml up -d
46+
```
47+
48+
| Service | Port |
49+
|-----------------------|------|
50+
| Frontend | 4200 |
51+
| API Gateway | 8080 |
52+
| Question Service | 8081 |
53+
| User Service | 8082 |
54+
| Match Service | 8083 |
55+
| Collaboration Service | 8084 |
56+
| Chat Service | 8085 |
57+
| History Service | 8086 |
58+
59+
60+
**Step 4: Stop the Docker containers**
61+
62+
Once you are done, stop and remove the containers using:
63+
64+
```bash
65+
docker compose down -v
66+
```
67+
68+
Note that this will clear any data stored in volumes associated with the containers. If you would like to keep your data, you can run the command without the `-v` flag, which will remove the containers but retain the data in the volumes for future use.

compose.dev.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
frontend:
3+
volumes:
4+
- /app/node_modules
5+
- ./frontend:/app
6+
7+
question:
8+
command: npm run dev
9+
volumes:
10+
- /app/node_modules
11+
- ./services/question:/app
12+
13+
question-db:
14+
ports:
15+
- 27017:27017
16+
17+
user:
18+
command: npm run dev
19+
volumes:
20+
- /app/node_modules
21+
- ./services/user:/app

docker-compose.yml renamed to compose.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ services:
77
dockerfile: Dockerfile
88
ports:
99
- 4200:4200
10-
volumes:
11-
- /app/node_modules
12-
- ./frontend:/app
13-
networks:
14-
- question-network
15-
- user-network
10+
restart: always
1611

1712
question:
1813
container_name: question
@@ -27,13 +22,9 @@ services:
2722
DB_LOCAL_URI: ${QUESTION_DB_LOCAL_URI}
2823
DB_USERNAME: ${QUESTION_DB_USERNAME}
2924
DB_PASSWORD: ${QUESTION_DB_PASSWORD}
30-
volumes:
31-
- /app/node_modules
32-
- ./services/question:/app
3325
networks:
34-
- question-network
3526
- question-db-network
36-
- user-network
27+
restart: always
3728

3829
question-db:
3930
container_name: question-db
@@ -46,6 +37,22 @@ services:
4637
- ./services/question/init-mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js
4738
networks:
4839
- question-db-network
40+
command: --quiet
41+
restart: always
42+
43+
user:
44+
container_name: user
45+
image: user
46+
build:
47+
context: services/user
48+
dockerfile: Dockerfile
49+
ports:
50+
- 8082:8082
51+
environment:
52+
USER_SERVICE_CLOUD_URI: ${USER_SERVICE_CLOUD_URI}
53+
USER_SERVICE_LOCAL_URI: ${USER_SERVICE_LOCAL_URI}
54+
ENV: ${ENV}
55+
JWT_SECRET: ${JWT_SECRET}
4956
restart: always
5057

5158
user:
@@ -72,8 +79,6 @@ volumes:
7279
question-db:
7380

7481
networks:
75-
question-network:
76-
driver: bridge
7782
question-db-network:
7883
driver: bridge
7984
user-network:

frontend/angular.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"budgets": [
3737
{
3838
"type": "initial",
39-
"maximumWarning": "500kB",
40-
"maximumError": "1MB"
39+
"maximumWarning": "2MB",
40+
"maximumError": "3MB"
4141
},
4242
{
4343
"type": "anyComponentStyle",

frontend/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@angular/platform-browser-dynamic": "^18.2.0",
2222
"@angular/router": "^18.2.0",
2323
"primeflex": "^3.3.1",
24+
"primeicons": "^7.0.0",
2425
"primeng": "^17.18.10",
2526
"rxjs": "~7.8.0",
2627
"tslib": "^2.3.0",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { QuestionService } from './question.service';
4+
5+
describe('QuestionService', () => {
6+
let service: QuestionService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(QuestionService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
2+
import { Injectable } from '@angular/core';
3+
import { API_CONFIG } from '../app/api.config';
4+
import { catchError, Observable, throwError } from 'rxjs';
5+
import { SingleQuestionResponse, QuestionResponse, QuestionBody } from '../app/questions/question.model';
6+
import { TopicResponse } from '../app/questions/topic.model';
7+
8+
@Injectable({
9+
providedIn: 'root',
10+
})
11+
export class QuestionService {
12+
private baseUrl = API_CONFIG.baseUrl;
13+
14+
private httpOptions = {
15+
headers: new HttpHeaders({
16+
'Content-Type': 'application/json',
17+
}),
18+
};
19+
20+
constructor(private http: HttpClient) {}
21+
22+
getQuestions(
23+
title?: string,
24+
description?: string,
25+
topics?: string[],
26+
difficulty?: string,
27+
): Observable<QuestionResponse> {
28+
let params = new HttpParams();
29+
30+
if (title) {
31+
params = params.append('title', title);
32+
}
33+
if (description) {
34+
params = params.append('description', description);
35+
}
36+
if (topics && topics.length > 0) {
37+
params = params.append('topics', topics.join(','));
38+
}
39+
if (difficulty) {
40+
params = params.append('difficulty', difficulty);
41+
}
42+
43+
// send request
44+
return this.http.get<QuestionResponse>(this.baseUrl + '/questions', { params });
45+
}
46+
47+
getQuestionByID(id: number): Observable<QuestionResponse> {
48+
return this.http.get<QuestionResponse>(this.baseUrl + '/questions/' + id);
49+
}
50+
51+
getQuestionByParam(topics: string[], difficulty: string, limit?: number): Observable<QuestionResponse> {
52+
let params = new HttpParams();
53+
54+
if (limit) {
55+
params = params.append('limit', limit);
56+
}
57+
params = params.append('topics', topics.join(',')).append('difficulty', difficulty);
58+
59+
return this.http.get<QuestionResponse>(this.baseUrl + '/questions/search', { params });
60+
}
61+
62+
getTopics(): Observable<TopicResponse> {
63+
return this.http.get<TopicResponse>(this.baseUrl + '/questions/topics');
64+
}
65+
66+
addQuestion(question: QuestionBody): Observable<SingleQuestionResponse> {
67+
return this.http
68+
.post<SingleQuestionResponse>(this.baseUrl + '/questions', question, this.httpOptions)
69+
.pipe(catchError(this.handleError));
70+
}
71+
72+
updateQuestion(id: number, question: QuestionBody): Observable<SingleQuestionResponse> {
73+
return this.http
74+
.put<SingleQuestionResponse>(this.baseUrl + '/questions/' + id, question, this.httpOptions)
75+
.pipe(catchError(this.handleError));
76+
}
77+
78+
deleteQuestion(id: number): Observable<SingleQuestionResponse> {
79+
return this.http
80+
.delete<SingleQuestionResponse>(this.baseUrl + '/questions/' + id)
81+
.pipe(catchError(this.handleError));
82+
}
83+
84+
handleError(error: HttpErrorResponse) {
85+
return throwError(error);
86+
}
87+
}

frontend/src/app/api.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const API_CONFIG = {
2+
baseUrl: 'http://localhost:8081',
3+
};

frontend/src/app/app.routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Routes } from '@angular/router';
2+
import { QuestionsComponent } from './questions/questions.component';
23

34
const accountModule = () => import('./account/account.module').then(x => x.AccountModule);
45

@@ -7,4 +8,8 @@ export const routes: Routes = [
78
path: 'account',
89
loadChildren: accountModule,
910
},
11+
{
12+
path: 'questions',
13+
component: QuestionsComponent,
14+
},
1015
];

0 commit comments

Comments
 (0)