Skip to content

Commit

Permalink
Merge pull request #799 from bounswe/url-fix
Browse files Browse the repository at this point in the history
Backend url is connected to environment variable
  • Loading branch information
HaticeSerraHakyemez authored Dec 29, 2023
2 parents dbe8463 + 32eeed8 commit 5bcfe98
Show file tree
Hide file tree
Showing 23 changed files with 142 additions and 75 deletions.
6 changes: 4 additions & 2 deletions app/frontend/src/app/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { Injectable } from '@angular/core'
import { HttpClient, HttpHeaders } from '@angular/common/http'
import { Observable, of } from 'rxjs'
import { catchError, tap } from 'rxjs/operators'
import { environment } from 'src/environments/environment'


@Injectable({
providedIn: 'root',
})
export class AuthService {
private user: any
private apiUrl = 'http://34.105.66.254:1923/auth'
private apiUrl = environment.apiBaseUrl + "/auth";

constructor(private http: HttpClient) {}

Expand All @@ -35,7 +37,7 @@ export class AuthService {
moderatorLogin(email: string, password: string): Observable<any> {
const credentials = { email, password }
return this.http
.post<any>(`http://34.105.66.254:1923/moderator/login`, credentials)
.post<any>(environment.apiBaseUrl + `/moderator/login`, credentials)
.pipe(
tap((response: any) => {
localStorage.setItem('authToken', response.access_token)
Expand Down
6 changes: 5 additions & 1 deletion app/frontend/src/app/badges-bar/badges-bar.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HttpClient } from '@angular/common/http'
import { Component, Input } from '@angular/core'
import { environment } from 'src/environments/environment'


@Component({
selector: 'app-badges-bar',
Expand All @@ -9,6 +11,8 @@ import { Component, Input } from '@angular/core'
export class BadgesBarComponent {
@Input() userId!: string
badges!: any
apiUrl = environment.apiBaseUrl;


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

ngOnInit() {
this.http.get('http://34.105.66.254:1923/user/' + this.userId).subscribe(
this.http.get(this.apiUrl + '/user/' + this.userId).subscribe(
(response: any) => {
this.badges = response.badges
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../auth.service';
import { environment } from 'src/environments/environment'


@Component({
selector: 'app-change-password',
Expand All @@ -13,6 +15,7 @@ export class ChangePasswordComponent {
password: string = ''
passwordConfirm: string = ''
options!: any
apiUrl = environment.apiBaseUrl;

constructor(
private http: HttpClient,
Expand All @@ -23,7 +26,7 @@ export class ChangePasswordComponent {
}

onSubmit(){
this.http.put('http://34.105.66.254:1923/user/password',{"oldPassword":this.oldPassword,"password":this.password,
this.http.put(this.apiUrl + '/user/password',{"oldPassword":this.oldPassword,"password":this.password,
"passwordConfirm":this.passwordConfirm},this.options).subscribe(
(response: any) => {
window.location.reload()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { Router } from '@angular/router'
import { environment } from 'src/environments/environment'


@Component({
selector: 'app-forget-password',
Expand All @@ -10,6 +12,8 @@ import { Router } from '@angular/router'
export class ForgetpasswordComponent {
email!: string
errorMessage: string = ''
apiUrl = environment.apiBaseUrl;

constructor(
private http: HttpClient,
private router: Router,
Expand All @@ -22,7 +26,7 @@ export class ForgetpasswordComponent {

// Send a POST request to the backend for authentication
this.http
.post('http://34.105.66.254:1923/auth/forgot-password', userCredentials)
.post(this.apiUrl + '/auth/forgot-password', userCredentials)
.subscribe(
(response: any) => {
// Authentication successful, you can handle the response here
Expand Down
5 changes: 3 additions & 2 deletions app/frontend/src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { SideBarComponent } from '../side-bar/side-bar.component'
import { TagsBarComponent } from '../tags-bar/tags-bar.component'
import { LeaderboardBarComponent } from '../leaderboard-bar/leaderboard-bar.component'
import { of } from 'rxjs'
import { environment } from 'src/environments/environment'

describe('HomeComponent', () => {
let component: HomeComponent
let fixture: ComponentFixture<HomeComponent>
let httpTestingController: HttpTestingController
let apiUrl = environment.apiBaseUrl;

beforeEach(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -53,10 +55,9 @@ describe('HomeComponent', () => {
of(mockResponse),
)

component.trendingPolls()

expect(httpClientSpy).toHaveBeenCalledWith(
'http://34.105.66.254:1923/poll/',
apiUrl + '/poll/',
)

expect(component.polls.length).toEqual(1)
Expand Down
13 changes: 8 additions & 5 deletions app/frontend/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { HttpClient } from '@angular/common/http'
import { Component, Input, EventEmitter, Output } from '@angular/core'
import { AuthService } from '../auth.service'
import { environment } from 'src/environments/environment'


@Component({
selector: 'app-home',
Expand All @@ -18,6 +20,7 @@ export class HomeComponent {
query!: string
settleEnum!: number
user_id!: any
apiUrl = environment.apiBaseUrl;


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

this.followingPolls(this.settledMode)

this.http.get('http://34.105.66.254:1923/ranking/0493fe16-9536-46d9-98cd-bbf1c6e8bd12',this.authService.getHeaders()).subscribe(
this.http.get(this.apiUrl + '/ranking/0493fe16-9536-46d9-98cd-bbf1c6e8bd12',this.authService.getHeaders()).subscribe(
(response: any) => {
this.leaders = response.ranking
console.log(this.leaders)
Expand Down Expand Up @@ -75,7 +78,7 @@ export class HomeComponent {
this.settleEnum = 0
}
this.clickedButton = 'trending';
this.http.get('http://34.105.66.254:1923/poll/not-voted-by-me/?is_settled=' + this.settleEnum, this.options).subscribe(
this.http.get(this.apiUrl + '/poll/not-voted-by-me/?is_settled=' + this.settleEnum, this.options).subscribe(
(response: any) => {
this.polls = response
},
Expand All @@ -89,7 +92,7 @@ export class HomeComponent {
followingPolls(isChecked: boolean) {
this.clickedButton = 'following';
if (isChecked) {
this.http.get('http://34.105.66.254:1923/poll/?followedById=' + this.user_id + "&is_settled=" + 2 ,this.options).subscribe(
this.http.get(this.apiUrl + '/poll/?followedById=' + this.user_id + "&is_settled=" + 2 ,this.options).subscribe(
(response: any) => {
this.polls = response
},
Expand All @@ -100,7 +103,7 @@ export class HomeComponent {

} else {

this.http.get('http://34.105.66.254:1923/poll/my-followings',this.options).subscribe(
this.http.get(this.apiUrl + '/poll/my-followings',this.options).subscribe(
(response: any) => {
this.polls = response
},
Expand All @@ -119,7 +122,7 @@ export class HomeComponent {
{
query
}
this.http.post("http://34.105.66.254:1923/poll/pinecone/search", payload,this.options).subscribe(
this.http.post(this.apiUrl + "/poll/pinecone/search", payload,this.options).subscribe(
(response: any) => {
this.polls = response
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Component } from '@angular/core'
import { ActivatedRoute } from '@angular/router';
import { AuthService } from '../auth.service';
import { Router } from '@angular/router';
import { environment } from 'src/environments/environment'

@Component({
selector: 'app-moderator-poll-review',
Expand All @@ -22,6 +23,7 @@ export class ModeratorPollReviewComponent {
is_settled!: number
outcome!: any
outcome_source!: any
apiUrl = environment.apiBaseUrl;

constructor(
private http: HttpClient,
Expand All @@ -41,7 +43,7 @@ export class ModeratorPollReviewComponent {
})


this.http.get('http://34.105.66.254:1923/poll/' + this.pollId).subscribe(
this.http.get(this.apiUrl + '/poll/' + this.pollId).subscribe(
(response: any) => {
this.username = response.creator.username
this.question = response.question
Expand All @@ -52,7 +54,7 @@ export class ModeratorPollReviewComponent {
this.is_settled = response.is_settled
this.outcome_source = response.outcome_source
if(this.is_settled){
this.http.get('http://34.105.66.254:1923/option/' + response.outcome ).subscribe(
this.http.get(this.apiUrl + '/option/' + response.outcome ).subscribe(
(outcomeResponse: any) => {
this.outcome = outcomeResponse.answer
},
Expand All @@ -70,7 +72,7 @@ export class ModeratorPollReviewComponent {

onApprove(){
if(this.is_settled==1){
this.http.post('http://34.105.66.254:1923/poll/settle/'+this.pollId,{'decision': true,
this.http.post(this.apiUrl + '/poll/settle/'+this.pollId,{'decision': true,
'settle_poll_request_feedback': "xx"},this.token).subscribe(
(response: any) => {
},
Expand All @@ -81,7 +83,7 @@ export class ModeratorPollReviewComponent {
return
}

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

if(this.is_settled==1){
this.http.post('http://34.105.66.254:1923/poll/settle/'+this.pollId,
this.http.post(this.apiUrl + '/poll/settle/'+this.pollId,
{
"decision": false,
"settle_poll_request_feedback": "not a good to time to settle it"
Expand All @@ -114,7 +116,7 @@ export class ModeratorPollReviewComponent {
return
}

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

this.http.delete('http://34.105.66.254:1923/poll/'+this.pollId,this.token).subscribe(
this.http.delete(this.apiUrl + '/poll/'+this.pollId,this.token).subscribe(
(response: any) => {
},
(error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Component } from '@angular/core'
import { HttpClient } from '@angular/common/http'
import { AuthService } from '../auth.service'
import { ActivatedRoute, Router } from '@angular/router'
import { environment } from 'src/environments/environment'


@Component({
selector: 'app-moderator-requests',
Expand All @@ -13,14 +15,15 @@ export class ModeratorRequestsComponent {
options!: any
outcomeReq: boolean = false
activeButton: string | null = null;
apiUrl = environment.apiBaseUrl;


constructor(private http: HttpClient,
private authService: AuthService,
private router: Router,
private route: ActivatedRoute,) {
this.options=this.authService.getHeaders()
this.http.get('http://34.105.66.254:1923/moderator/polls/',this.options).subscribe(
this.http.get(this.apiUrl + '/moderator/polls/',this.options).subscribe(
(response: any) => {
this.polls = response
this.activeButton = "PollCreationRequests"
Expand Down Expand Up @@ -51,7 +54,7 @@ export class ModeratorRequestsComponent {
onPollCreationReq(){
this.outcomeReq = false
this.activeButton = 'PollCreationRequests';
this.http.get('http://34.105.66.254:1923/moderator/polls/',this.options).subscribe(
this.http.get(this.apiUrl + '/moderator/polls/',this.options).subscribe(
(response: any) => {
this.polls = response
this.polls.forEach(poll => {
Expand All @@ -68,7 +71,7 @@ export class ModeratorRequestsComponent {
handleDisapprove(pollId: any){

if(this.outcomeReq){
this.http.post('http://34.105.66.254:1923/poll/settle/'+pollId,
this.http.post(this.apiUrl + '/poll/settle/'+pollId,
{
"decision": false,
"settle_poll_request_feedback": "not a good to time to settle it"
Expand All @@ -87,7 +90,7 @@ export class ModeratorRequestsComponent {
return
}

this.http.delete('http://34.105.66.254:1923/poll/'+pollId,this.options).subscribe(
this.http.delete(this.apiUrl + '/poll/'+pollId,this.options).subscribe(
(response: any) => {
},
(error) => {
Expand All @@ -104,7 +107,7 @@ export class ModeratorRequestsComponent {
onOutcomeVerifiationReq(){
this.outcomeReq = true
this.activeButton = 'OutcomeVerificationRequests';
this.http.get('http://34.105.66.254:1923/poll/').subscribe(
this.http.get(this.apiUrl + '/poll/').subscribe(
(response: any) => {

this.polls = []
Expand Down
Loading

0 comments on commit 5bcfe98

Please sign in to comment.