Skip to content

Commit 5bcfe98

Browse files
Merge pull request #799 from bounswe/url-fix
Backend url is connected to environment variable
2 parents dbe8463 + 32eeed8 commit 5bcfe98

23 files changed

+142
-75
lines changed

Diff for: app/frontend/src/app/auth.service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { Injectable } from '@angular/core'
22
import { HttpClient, HttpHeaders } from '@angular/common/http'
33
import { Observable, of } from 'rxjs'
44
import { catchError, tap } from 'rxjs/operators'
5+
import { environment } from 'src/environments/environment'
6+
57

68
@Injectable({
79
providedIn: 'root',
810
})
911
export class AuthService {
1012
private user: any
11-
private apiUrl = 'http://34.105.66.254:1923/auth'
13+
private apiUrl = environment.apiBaseUrl + "/auth";
1214

1315
constructor(private http: HttpClient) {}
1416

@@ -35,7 +37,7 @@ export class AuthService {
3537
moderatorLogin(email: string, password: string): Observable<any> {
3638
const credentials = { email, password }
3739
return this.http
38-
.post<any>(`http://34.105.66.254:1923/moderator/login`, credentials)
40+
.post<any>(environment.apiBaseUrl + `/moderator/login`, credentials)
3941
.pipe(
4042
tap((response: any) => {
4143
localStorage.setItem('authToken', response.access_token)

Diff for: app/frontend/src/app/badges-bar/badges-bar.component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { HttpClient } from '@angular/common/http'
22
import { Component, Input } from '@angular/core'
3+
import { environment } from 'src/environments/environment'
4+
35

46
@Component({
57
selector: 'app-badges-bar',
@@ -9,6 +11,8 @@ import { Component, Input } from '@angular/core'
911
export class BadgesBarComponent {
1012
@Input() userId!: string
1113
badges!: any
14+
apiUrl = environment.apiBaseUrl;
15+
1216

1317
colors: string[] = [
1418
'#f2545b',
@@ -21,7 +25,7 @@ export class BadgesBarComponent {
2125
constructor(private http: HttpClient) {}
2226

2327
ngOnInit() {
24-
this.http.get('http://34.105.66.254:1923/user/' + this.userId).subscribe(
28+
this.http.get(this.apiUrl + '/user/' + this.userId).subscribe(
2529
(response: any) => {
2630
this.badges = response.badges
2731
},

Diff for: app/frontend/src/app/change-password/change-password.component.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { HttpClient } from '@angular/common/http';
22
import { Component } from '@angular/core';
33
import { Router } from '@angular/router';
44
import { AuthService } from '../auth.service';
5+
import { environment } from 'src/environments/environment'
6+
57

68
@Component({
79
selector: 'app-change-password',
@@ -13,6 +15,7 @@ export class ChangePasswordComponent {
1315
password: string = ''
1416
passwordConfirm: string = ''
1517
options!: any
18+
apiUrl = environment.apiBaseUrl;
1619

1720
constructor(
1821
private http: HttpClient,
@@ -23,7 +26,7 @@ export class ChangePasswordComponent {
2326
}
2427

2528
onSubmit(){
26-
this.http.put('http://34.105.66.254:1923/user/password',{"oldPassword":this.oldPassword,"password":this.password,
29+
this.http.put(this.apiUrl + '/user/password',{"oldPassword":this.oldPassword,"password":this.password,
2730
"passwordConfirm":this.passwordConfirm},this.options).subscribe(
2831
(response: any) => {
2932
window.location.reload()

Diff for: app/frontend/src/app/forgetpassword/forgetpassword.component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Component } from '@angular/core'
22
import { HttpClient } from '@angular/common/http'
33
import { Router } from '@angular/router'
4+
import { environment } from 'src/environments/environment'
5+
46

57
@Component({
68
selector: 'app-forget-password',
@@ -10,6 +12,8 @@ import { Router } from '@angular/router'
1012
export class ForgetpasswordComponent {
1113
email!: string
1214
errorMessage: string = ''
15+
apiUrl = environment.apiBaseUrl;
16+
1317
constructor(
1418
private http: HttpClient,
1519
private router: Router,
@@ -22,7 +26,7 @@ export class ForgetpasswordComponent {
2226

2327
// Send a POST request to the backend for authentication
2428
this.http
25-
.post('http://34.105.66.254:1923/auth/forgot-password', userCredentials)
29+
.post(this.apiUrl + '/auth/forgot-password', userCredentials)
2630
.subscribe(
2731
(response: any) => {
2832
// Authentication successful, you can handle the response here

Diff for: app/frontend/src/app/home/home.component.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ import { SideBarComponent } from '../side-bar/side-bar.component'
1515
import { TagsBarComponent } from '../tags-bar/tags-bar.component'
1616
import { LeaderboardBarComponent } from '../leaderboard-bar/leaderboard-bar.component'
1717
import { of } from 'rxjs'
18+
import { environment } from 'src/environments/environment'
1819

1920
describe('HomeComponent', () => {
2021
let component: HomeComponent
2122
let fixture: ComponentFixture<HomeComponent>
2223
let httpTestingController: HttpTestingController
24+
let apiUrl = environment.apiBaseUrl;
2325

2426
beforeEach(() => {
2527
TestBed.configureTestingModule({
@@ -53,10 +55,9 @@ describe('HomeComponent', () => {
5355
of(mockResponse),
5456
)
5557

56-
component.trendingPolls()
5758

5859
expect(httpClientSpy).toHaveBeenCalledWith(
59-
'http://34.105.66.254:1923/poll/',
60+
apiUrl + '/poll/',
6061
)
6162

6263
expect(component.polls.length).toEqual(1)

Diff for: app/frontend/src/app/home/home.component.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { HttpClient } from '@angular/common/http'
22
import { Component, Input, EventEmitter, Output } from '@angular/core'
33
import { AuthService } from '../auth.service'
4+
import { environment } from 'src/environments/environment'
5+
46

57
@Component({
68
selector: 'app-home',
@@ -18,6 +20,7 @@ export class HomeComponent {
1820
query!: string
1921
settleEnum!: number
2022
user_id!: any
23+
apiUrl = environment.apiBaseUrl;
2124

2225

2326
constructor(private http: HttpClient,private authService: AuthService) {
@@ -26,7 +29,7 @@ export class HomeComponent {
2629

2730
this.followingPolls(this.settledMode)
2831

29-
this.http.get('http://34.105.66.254:1923/ranking/0493fe16-9536-46d9-98cd-bbf1c6e8bd12',this.authService.getHeaders()).subscribe(
32+
this.http.get(this.apiUrl + '/ranking/0493fe16-9536-46d9-98cd-bbf1c6e8bd12',this.authService.getHeaders()).subscribe(
3033
(response: any) => {
3134
this.leaders = response.ranking
3235
console.log(this.leaders)
@@ -75,7 +78,7 @@ export class HomeComponent {
7578
this.settleEnum = 0
7679
}
7780
this.clickedButton = 'trending';
78-
this.http.get('http://34.105.66.254:1923/poll/not-voted-by-me/?is_settled=' + this.settleEnum, this.options).subscribe(
81+
this.http.get(this.apiUrl + '/poll/not-voted-by-me/?is_settled=' + this.settleEnum, this.options).subscribe(
7982
(response: any) => {
8083
this.polls = response
8184
},
@@ -89,7 +92,7 @@ export class HomeComponent {
8992
followingPolls(isChecked: boolean) {
9093
this.clickedButton = 'following';
9194
if (isChecked) {
92-
this.http.get('http://34.105.66.254:1923/poll/?followedById=' + this.user_id + "&is_settled=" + 2 ,this.options).subscribe(
95+
this.http.get(this.apiUrl + '/poll/?followedById=' + this.user_id + "&is_settled=" + 2 ,this.options).subscribe(
9396
(response: any) => {
9497
this.polls = response
9598
},
@@ -100,7 +103,7 @@ export class HomeComponent {
100103

101104
} else {
102105

103-
this.http.get('http://34.105.66.254:1923/poll/my-followings',this.options).subscribe(
106+
this.http.get(this.apiUrl + '/poll/my-followings',this.options).subscribe(
104107
(response: any) => {
105108
this.polls = response
106109
},
@@ -119,7 +122,7 @@ export class HomeComponent {
119122
{
120123
query
121124
}
122-
this.http.post("http://34.105.66.254:1923/poll/pinecone/search", payload,this.options).subscribe(
125+
this.http.post(this.apiUrl + "/poll/pinecone/search", payload,this.options).subscribe(
123126
(response: any) => {
124127
this.polls = response
125128
},

Diff for: app/frontend/src/app/moderator-poll-review/moderator-poll-review.component.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Component } from '@angular/core'
33
import { ActivatedRoute } from '@angular/router';
44
import { AuthService } from '../auth.service';
55
import { Router } from '@angular/router';
6+
import { environment } from 'src/environments/environment'
67

78
@Component({
89
selector: 'app-moderator-poll-review',
@@ -22,6 +23,7 @@ export class ModeratorPollReviewComponent {
2223
is_settled!: number
2324
outcome!: any
2425
outcome_source!: any
26+
apiUrl = environment.apiBaseUrl;
2527

2628
constructor(
2729
private http: HttpClient,
@@ -41,7 +43,7 @@ export class ModeratorPollReviewComponent {
4143
})
4244

4345

44-
this.http.get('http://34.105.66.254:1923/poll/' + this.pollId).subscribe(
46+
this.http.get(this.apiUrl + '/poll/' + this.pollId).subscribe(
4547
(response: any) => {
4648
this.username = response.creator.username
4749
this.question = response.question
@@ -52,7 +54,7 @@ export class ModeratorPollReviewComponent {
5254
this.is_settled = response.is_settled
5355
this.outcome_source = response.outcome_source
5456
if(this.is_settled){
55-
this.http.get('http://34.105.66.254:1923/option/' + response.outcome ).subscribe(
57+
this.http.get(this.apiUrl + '/option/' + response.outcome ).subscribe(
5658
(outcomeResponse: any) => {
5759
this.outcome = outcomeResponse.answer
5860
},
@@ -70,7 +72,7 @@ export class ModeratorPollReviewComponent {
7072

7173
onApprove(){
7274
if(this.is_settled==1){
73-
this.http.post('http://34.105.66.254:1923/poll/settle/'+this.pollId,{'decision': true,
75+
this.http.post(this.apiUrl + '/poll/settle/'+this.pollId,{'decision': true,
7476
'settle_poll_request_feedback': "xx"},this.token).subscribe(
7577
(response: any) => {
7678
},
@@ -81,7 +83,7 @@ export class ModeratorPollReviewComponent {
8183
return
8284
}
8385

84-
this.http.post('http://34.105.66.254:1923/moderator/approve/'+this.pollId,{'approveStatus': true},this.token).subscribe(
86+
this.http.post(this.apiUrl + '/moderator/approve/'+this.pollId,{'approveStatus': true},this.token).subscribe(
8587
(response: any) => {
8688
},
8789
(error) => {
@@ -96,7 +98,7 @@ export class ModeratorPollReviewComponent {
9698
onReject(){
9799

98100
if(this.is_settled==1){
99-
this.http.post('http://34.105.66.254:1923/poll/settle/'+this.pollId,
101+
this.http.post(this.apiUrl + '/poll/settle/'+this.pollId,
100102
{
101103
"decision": false,
102104
"settle_poll_request_feedback": "not a good to time to settle it"
@@ -114,7 +116,7 @@ export class ModeratorPollReviewComponent {
114116
return
115117
}
116118

117-
this.http.post('http://34.105.66.254:1923/moderator/approve/'+this.pollId,{'approveStatus': false,
119+
this.http.post(this.apiUrl + '/moderator/approve/'+this.pollId,{'approveStatus': false,
118120
"poll_request_rejection_feedback": "not a precise poll"}, this.token).subscribe(
119121
(response: any) => {
120122
},
@@ -123,7 +125,7 @@ export class ModeratorPollReviewComponent {
123125
},
124126
)
125127

126-
this.http.delete('http://34.105.66.254:1923/poll/'+this.pollId,this.token).subscribe(
128+
this.http.delete(this.apiUrl + '/poll/'+this.pollId,this.token).subscribe(
127129
(response: any) => {
128130
},
129131
(error) => {

Diff for: app/frontend/src/app/moderator-requests/moderator-requests.component.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Component } from '@angular/core'
22
import { HttpClient } from '@angular/common/http'
33
import { AuthService } from '../auth.service'
44
import { ActivatedRoute, Router } from '@angular/router'
5+
import { environment } from 'src/environments/environment'
6+
57

68
@Component({
79
selector: 'app-moderator-requests',
@@ -13,14 +15,15 @@ export class ModeratorRequestsComponent {
1315
options!: any
1416
outcomeReq: boolean = false
1517
activeButton: string | null = null;
18+
apiUrl = environment.apiBaseUrl;
1619

1720

1821
constructor(private http: HttpClient,
1922
private authService: AuthService,
2023
private router: Router,
2124
private route: ActivatedRoute,) {
2225
this.options=this.authService.getHeaders()
23-
this.http.get('http://34.105.66.254:1923/moderator/polls/',this.options).subscribe(
26+
this.http.get(this.apiUrl + '/moderator/polls/',this.options).subscribe(
2427
(response: any) => {
2528
this.polls = response
2629
this.activeButton = "PollCreationRequests"
@@ -51,7 +54,7 @@ export class ModeratorRequestsComponent {
5154
onPollCreationReq(){
5255
this.outcomeReq = false
5356
this.activeButton = 'PollCreationRequests';
54-
this.http.get('http://34.105.66.254:1923/moderator/polls/',this.options).subscribe(
57+
this.http.get(this.apiUrl + '/moderator/polls/',this.options).subscribe(
5558
(response: any) => {
5659
this.polls = response
5760
this.polls.forEach(poll => {
@@ -68,7 +71,7 @@ export class ModeratorRequestsComponent {
6871
handleDisapprove(pollId: any){
6972

7073
if(this.outcomeReq){
71-
this.http.post('http://34.105.66.254:1923/poll/settle/'+pollId,
74+
this.http.post(this.apiUrl + '/poll/settle/'+pollId,
7275
{
7376
"decision": false,
7477
"settle_poll_request_feedback": "not a good to time to settle it"
@@ -87,7 +90,7 @@ export class ModeratorRequestsComponent {
8790
return
8891
}
8992

90-
this.http.delete('http://34.105.66.254:1923/poll/'+pollId,this.options).subscribe(
93+
this.http.delete(this.apiUrl + '/poll/'+pollId,this.options).subscribe(
9194
(response: any) => {
9295
},
9396
(error) => {
@@ -104,7 +107,7 @@ export class ModeratorRequestsComponent {
104107
onOutcomeVerifiationReq(){
105108
this.outcomeReq = true
106109
this.activeButton = 'OutcomeVerificationRequests';
107-
this.http.get('http://34.105.66.254:1923/poll/').subscribe(
110+
this.http.get(this.apiUrl + '/poll/').subscribe(
108111
(response: any) => {
109112

110113
this.polls = []

0 commit comments

Comments
 (0)