Skip to content

Commit

Permalink
Change server.go connection to localhost:4200
Browse files Browse the repository at this point in the history
Add service.ts
Edit edit question page
  • Loading branch information
AidenLYT committed Sep 27, 2024
1 parent 86146d5 commit 4e50c62
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions peer-prep-be/src/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
e.Use(middleware.Recover()) // Recover
// CORS
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowOrigins: []string{"http://localhost:4200"},
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.PATCH, echo.POST, echo.DELETE},
}))

Expand All @@ -28,5 +28,5 @@ func main() {
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Logger.Fatal(e.Start(":1323"))
e.Logger.Fatal(e.Start(":8080"))
}
10 changes: 5 additions & 5 deletions peer-prep-fe/src/edit-page/edit-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {ActivatedRoute, Router} from "@angular/router";
import {FormsModule} from "@angular/forms";
import {NgClass, NgForOf} from "@angular/common";
import {QuestionService} from "../services/question.service";

@Component({
selector: 'app-edit-page',
Expand Down Expand Up @@ -31,20 +31,20 @@ export class EditPageComponent implements OnInit {
dropdownOpen: boolean = false;

constructor(
private http: HttpClient,
private questionService: QuestionService,
private router: Router,
private route: ActivatedRoute
) {}

ngOnInit() {
this.route.params.subscribe((params) => {
this.questionId = params['id'];
this.questionId = '66f2a8a8aea02b6b4babc749';
this.loadQuestionData();
});
}

loadQuestionData() {
this.http.get(`/api/questions/$(this.questionId)`).subscribe((data: any) => {
this.questionService.getQuestion(this.questionId).subscribe((data: any) => {
this.questionTitle = data.title;
this.questionDescription = data.description;
this.categories.forEach(cat => {
Expand All @@ -65,7 +65,7 @@ export class EditPageComponent implements OnInit {
categories: this.categories.filter(cat => cat.selected).map(cat => cat.name),
difficulty: this.difficulty
};
this.http.put(`/api/questions/$(this.questionId)`, updatedQuestion).subscribe((response) => {
this.questionService.updateQuestion(this.questionId, updatedQuestion).subscribe((response) => {
alert('Question updated successfully!');
},
(error) => {
Expand Down
16 changes: 16 additions & 0 deletions peer-prep-fe/src/services/question.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { QuestionService } from './question.service';

describe('QuestionService', () => {
let service: QuestionService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(QuestionService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions peer-prep-fe/src/services/question.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Observable} from "rxjs";

@Injectable({
providedIn: 'root'
})
export class QuestionService {
private baseUrl = 'http://localhost:8080/api/questions'
constructor(private http: HttpClient) { }

getQuestion(id: string): Observable<any> {
return this.http.get(`${this.baseUrl}/${id}`);
}

updateQuestion(id: string, updatedQuestion: any): Observable<any> {
return this.http.put(`${this.baseUrl}/${id}`, updatedQuestion);
}
}

0 comments on commit 4e50c62

Please sign in to comment.