From 06d1b3229df43e20edcf98f29f2b91b024e61def Mon Sep 17 00:00:00 2001 From: Aayush Mehra Date: Tue, 28 Mar 2023 16:53:47 -0400 Subject: [PATCH 1/5] build forum post frontend part 1 --- frontend/src/app/forum/forum.component.ts | 22 +++++++++++++ frontend/src/app/post.service.ts | 40 +++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 frontend/src/app/post.service.ts diff --git a/frontend/src/app/forum/forum.component.ts b/frontend/src/app/forum/forum.component.ts index edfd79e..b2e3e71 100644 --- a/frontend/src/app/forum/forum.component.ts +++ b/frontend/src/app/forum/forum.component.ts @@ -1,4 +1,8 @@ import { Component } from '@angular/core'; +import { FormBuilder } from '@angular/forms'; +import { PostService} from '../post.service'; +import { Role } from "../role"; +import { HttpErrorResponse } from '@angular/common/http'; @Component({ selector: 'app-forum', @@ -10,4 +14,22 @@ export class ForumComponent { path: 'forum', component: ForumComponent }; + + form = this.formBuilder.group({ + content: '' + }); + + constructor ( + // private postService: postService, + private formBuilder: FormBuilder + ) {} + + onSubmit(): void { + let form = this.form.value; + if (this.form.value.content?.length == 0) { + window.alert("Please check your input!") + } + + } + } diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts new file mode 100644 index 0000000..bba6e31 --- /dev/null +++ b/frontend/src/app/post.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable, throwError } from 'rxjs'; +import { Profile } from './profile/profile.service'; +import { Role } from './role'; + +export interface Post { + id: number; + content: string; + user: Role; + votes: []; + timestamp: Date; +} +// these attributes will most likely change + +@Injectable ({ + providedIn: 'root' +}) + +export class PostService { + + constructor(private http: HttpClient) {} + posts: Post[] = []; + getPost() { + return this.posts; + } + getPosts(): Observable { + return this.http.get("/api/post"); + } + + makePost(id: number, content: string, user: Role, votes: [], timestamp: Date): Observable { + let post: Post = {id, content, user, votes, timestamp}; + return this.http.post("/api/post/", post); + } + + deletePost(id: number) { + return this.http.delete("/api/post/" + id) + } + +} From 4b761959a148d7042feb1766d36f8da7bd108433 Mon Sep 17 00:00:00 2001 From: Aayush Mehra Date: Wed, 29 Mar 2023 20:14:50 -0400 Subject: [PATCH 2/5] created viewforum as a page to look at all forums --- frontend/src/app/app-routing.module.ts | 2 +- frontend/src/app/app.module.ts | 8 ++- frontend/src/app/forum/forum.component.html | 1 - frontend/src/app/forum/forum.component.ts | 35 --------- frontend/src/app/getforum.service.spec.ts | 16 +++++ frontend/src/app/getforum.service.ts | 12 ++++ .../makeforum.component.css} | 0 .../app/makeforum/makeforum.component.html | 12 ++++ .../makeforum.component.spec.ts} | 2 +- .../src/app/makeforum/makeforum.component.ts | 72 +++++++++++++++++++ frontend/src/app/post.service.ts | 5 +- .../src/app/viewforum/viewforum.component.css | 0 .../app/viewforum/viewforum.component.html | 1 + .../app/viewforum/viewforum.component.spec.ts | 23 ++++++ .../src/app/viewforum/viewforum.component.ts | 10 +++ 15 files changed, 156 insertions(+), 43 deletions(-) delete mode 100644 frontend/src/app/forum/forum.component.html delete mode 100644 frontend/src/app/forum/forum.component.ts create mode 100644 frontend/src/app/getforum.service.spec.ts create mode 100644 frontend/src/app/getforum.service.ts rename frontend/src/app/{forum/forum.component.css => makeforum/makeforum.component.css} (100%) create mode 100644 frontend/src/app/makeforum/makeforum.component.html rename frontend/src/app/{forum/forum.component.spec.ts => makeforum/makeforum.component.spec.ts} (90%) create mode 100644 frontend/src/app/makeforum/makeforum.component.ts create mode 100644 frontend/src/app/viewforum/viewforum.component.css create mode 100644 frontend/src/app/viewforum/viewforum.component.html create mode 100644 frontend/src/app/viewforum/viewforum.component.spec.ts create mode 100644 frontend/src/app/viewforum/viewforum.component.ts diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index 0acaef7..83cccef 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -4,7 +4,7 @@ import { AppTitleStrategy } from './app-title.strategy'; import { GateComponent } from './gate/gate.component'; import { HomeComponent } from './home/home.component'; import { ProfileEditorComponent } from './profile/profile-editor/profile-editor.component'; -import { ForumComponent } from './forum/forum.component'; +import { ForumComponent } from './makeforum/makeforum.component'; const routes: Routes = [ diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 72bccfe..cb008ed 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -32,8 +32,9 @@ import { NavigationComponent } from './navigation/navigation.component'; import { ErrorDialogComponent } from './navigation/error-dialog/error-dialog.component'; import { HomeComponent } from './home/home.component'; import { GateComponent } from './gate/gate.component'; -import { ProfileEditorComponent } from './profile/profile-editor/profile-editor.component'; -import { ForumComponent } from './forum/forum.component'; +import { ProfileEditorComponent } from './profile/profile-editor/profile-editor.component'; +import { ForumComponent } from './makeforum/makeforum.component'; +import { GetforumComponent } from './viewforum/viewforum.component'; @NgModule({ declarations: [ @@ -43,7 +44,8 @@ import { ForumComponent } from './forum/forum.component'; HomeComponent, GateComponent, ProfileEditorComponent, - ForumComponent + ForumComponent, + GetforumComponent ], imports: [ BrowserModule, diff --git a/frontend/src/app/forum/forum.component.html b/frontend/src/app/forum/forum.component.html deleted file mode 100644 index 0ca0912..0000000 --- a/frontend/src/app/forum/forum.component.html +++ /dev/null @@ -1 +0,0 @@ -

Welcome to the Forum!

diff --git a/frontend/src/app/forum/forum.component.ts b/frontend/src/app/forum/forum.component.ts deleted file mode 100644 index b2e3e71..0000000 --- a/frontend/src/app/forum/forum.component.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Component } from '@angular/core'; -import { FormBuilder } from '@angular/forms'; -import { PostService} from '../post.service'; -import { Role } from "../role"; -import { HttpErrorResponse } from '@angular/common/http'; - -@Component({ - selector: 'app-forum', - templateUrl: './forum.component.html', - styleUrls: ['./forum.component.css'] -}) -export class ForumComponent { - public static Route = { - path: 'forum', - component: ForumComponent - }; - - form = this.formBuilder.group({ - content: '' - }); - - constructor ( - // private postService: postService, - private formBuilder: FormBuilder - ) {} - - onSubmit(): void { - let form = this.form.value; - if (this.form.value.content?.length == 0) { - window.alert("Please check your input!") - } - - } - -} diff --git a/frontend/src/app/getforum.service.spec.ts b/frontend/src/app/getforum.service.spec.ts new file mode 100644 index 0000000..1b7fd9c --- /dev/null +++ b/frontend/src/app/getforum.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { GetforumService } from './getforum.service'; + +describe('GetforumService', () => { + let service: GetforumService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(GetforumService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/getforum.service.ts b/frontend/src/app/getforum.service.ts new file mode 100644 index 0000000..d1c7ddf --- /dev/null +++ b/frontend/src/app/getforum.service.ts @@ -0,0 +1,12 @@ + +import { Injectable, PLATFORM_ID } from '@angular/core'; +import { map, Observable, throwError } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; //just added this + +@Injectable({ + providedIn: 'root' +}) +export class GetforumService { + + constructor() { } +} diff --git a/frontend/src/app/forum/forum.component.css b/frontend/src/app/makeforum/makeforum.component.css similarity index 100% rename from frontend/src/app/forum/forum.component.css rename to frontend/src/app/makeforum/makeforum.component.css diff --git a/frontend/src/app/makeforum/makeforum.component.html b/frontend/src/app/makeforum/makeforum.component.html new file mode 100644 index 0000000..28ba357 --- /dev/null +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -0,0 +1,12 @@ +

Welcome to the Forum!

+ +

Make a Forum Post With Resources!!

+ +
+
+ + +
+
+ +
diff --git a/frontend/src/app/forum/forum.component.spec.ts b/frontend/src/app/makeforum/makeforum.component.spec.ts similarity index 90% rename from frontend/src/app/forum/forum.component.spec.ts rename to frontend/src/app/makeforum/makeforum.component.spec.ts index df9ae41..cab4c92 100644 --- a/frontend/src/app/forum/forum.component.spec.ts +++ b/frontend/src/app/makeforum/makeforum.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { ForumComponent } from './forum.component'; +import { ForumComponent } from './makeforum.component'; describe('ForumComponent', () => { let component: ForumComponent; diff --git a/frontend/src/app/makeforum/makeforum.component.ts b/frontend/src/app/makeforum/makeforum.component.ts new file mode 100644 index 0000000..1b2d454 --- /dev/null +++ b/frontend/src/app/makeforum/makeforum.component.ts @@ -0,0 +1,72 @@ +import { Component } from '@angular/core'; +import { FormBuilder } from '@angular/forms'; +import { PostService, Post } from '../post.service'; +import { Role } from "../role"; +import { HttpErrorResponse } from '@angular/common/http'; +import { Profile, ProfileService } from '../profile/profile.service'; + +// things we need to do - change the name of forum component and you have to call one: makeforum and one should be seeforum +//also we need to figure out how to create an actual user and not just a dummy one +// also we need to fix onerror +@Component({ + selector: 'app-forum', + templateUrl: './makeforum.component.html', + styleUrls: ['./makeforum.component.css'] +}) +export class ForumComponent { + + public static Route = { + path: 'forum', + component: ForumComponent + }; + + form = this.formBuilder.group({ + content: '' + }); + + constructor ( + private postService: PostService, + private formBuilder: FormBuilder, + private profileService: ProfileService + ) {} + + onSubmit(): void { + let form = this.form.value; + + this.profileService.profile$ + .subscribe({ + next: (profile) => this.onSuccess(profile), + error: (err) => this.onError(err) + }); + + if (this.form.value.content?.length == 0) { + window.alert("Please check your input!") + + } + // we need to define onerror + } + + private onSuccess(profile: Profile | undefined): void { + // this is where we have something in scope of type profile + + if (profile == undefined) { + // handle this case better? + return; + } + + this.postService + .makePost(1, "blah", profile, [], new Date("2022-03-25")) + .subscribe({ + next: (post) => this.onSuccess(profile), + error: (err) => this.onError(err) + }); + + window.alert('Thank you for posting') + + this.form.reset() + } + + private onError(error: Error): void { + + } +} diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts index bba6e31..b7598e8 100644 --- a/frontend/src/app/post.service.ts +++ b/frontend/src/app/post.service.ts @@ -7,7 +7,7 @@ import { Role } from './role'; export interface Post { id: number; content: string; - user: Role; + user: Profile; votes: []; timestamp: Date; } @@ -19,6 +19,7 @@ export interface Post { export class PostService { + constructor(private http: HttpClient) {} posts: Post[] = []; getPost() { @@ -28,7 +29,7 @@ export class PostService { return this.http.get("/api/post"); } - makePost(id: number, content: string, user: Role, votes: [], timestamp: Date): Observable { + makePost(id: number, content: string, user: Profile, votes: [], timestamp: Date): Observable { let post: Post = {id, content, user, votes, timestamp}; return this.http.post("/api/post/", post); } diff --git a/frontend/src/app/viewforum/viewforum.component.css b/frontend/src/app/viewforum/viewforum.component.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/viewforum/viewforum.component.html b/frontend/src/app/viewforum/viewforum.component.html new file mode 100644 index 0000000..e3c4669 --- /dev/null +++ b/frontend/src/app/viewforum/viewforum.component.html @@ -0,0 +1 @@ +

getforum works!

diff --git a/frontend/src/app/viewforum/viewforum.component.spec.ts b/frontend/src/app/viewforum/viewforum.component.spec.ts new file mode 100644 index 0000000..cc6c27d --- /dev/null +++ b/frontend/src/app/viewforum/viewforum.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { GetforumComponent } from './viewforum.component'; + +describe('GetforumComponent', () => { + let component: GetforumComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ GetforumComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(GetforumComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/viewforum/viewforum.component.ts b/frontend/src/app/viewforum/viewforum.component.ts new file mode 100644 index 0000000..00a372d --- /dev/null +++ b/frontend/src/app/viewforum/viewforum.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-getforum', + templateUrl: './getforum.component.html', + styleUrls: ['./getforum.component.css'] +}) +export class GetforumComponent { + +} From fccf7c4b11f7ea790da7d5d13b12a6dea8cf83a1 Mon Sep 17 00:00:00 2001 From: angelinasu57 Date: Wed, 29 Mar 2023 22:08:08 -0400 Subject: [PATCH 3/5] Start working on forwarding form responses to the viewforum component. --- frontend/src/app/app.module.ts | 4 +- .../app/makeforum/makeforum.component.html | 21 +++++++++- .../src/app/makeforum/makeforum.component.ts | 41 ++++++++++--------- frontend/src/app/post.service.ts | 9 ++-- ...vice.spec.ts => viewforum.service.spec.ts} | 8 ++-- ...tforum.service.ts => viewforum.service.ts} | 2 +- .../src/app/viewforum/viewforum.component.ts | 13 ++++-- 7 files changed, 64 insertions(+), 34 deletions(-) rename frontend/src/app/{getforum.service.spec.ts => viewforum.service.spec.ts} (53%) rename frontend/src/app/{getforum.service.ts => viewforum.service.ts} (88%) diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index cb008ed..bdbf879 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -34,7 +34,7 @@ import { HomeComponent } from './home/home.component'; import { GateComponent } from './gate/gate.component'; import { ProfileEditorComponent } from './profile/profile-editor/profile-editor.component'; import { ForumComponent } from './makeforum/makeforum.component'; -import { GetforumComponent } from './viewforum/viewforum.component'; +import { viewforumComponent } from './viewforum/viewforum.component'; @NgModule({ declarations: [ @@ -45,7 +45,7 @@ import { GetforumComponent } from './viewforum/viewforum.component'; GateComponent, ProfileEditorComponent, ForumComponent, - GetforumComponent + viewforumComponent ], imports: [ BrowserModule, diff --git a/frontend/src/app/makeforum/makeforum.component.html b/frontend/src/app/makeforum/makeforum.component.html index 28ba357..c1dd101 100644 --- a/frontend/src/app/makeforum/makeforum.component.html +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -6,7 +6,24 @@

Make a Forum Post With Resources!!

-
+ -
+ + diff --git a/frontend/src/app/makeforum/makeforum.component.ts b/frontend/src/app/makeforum/makeforum.component.ts index 1b2d454..c8b7654 100644 --- a/frontend/src/app/makeforum/makeforum.component.ts +++ b/frontend/src/app/makeforum/makeforum.component.ts @@ -4,6 +4,7 @@ import { PostService, Post } from '../post.service'; import { Role } from "../role"; import { HttpErrorResponse } from '@angular/common/http'; import { Profile, ProfileService } from '../profile/profile.service'; +import { viewforumComponent } from '../viewforum/viewforum.component'; // things we need to do - change the name of forum component and you have to call one: makeforum and one should be seeforum //also we need to figure out how to create an actual user and not just a dummy one @@ -39,34 +40,36 @@ export class ForumComponent { error: (err) => this.onError(err) }); + if (this.form.value.content?.length == 0) { window.alert("Please check your input!") } // we need to define onerror - } - - private onSuccess(profile: Profile | undefined): void { - // this is where we have something in scope of type profile - - if (profile == undefined) { - // handle this case better? - return; - } +} - this.postService - .makePost(1, "blah", profile, [], new Date("2022-03-25")) - .subscribe({ - next: (post) => this.onSuccess(profile), - error: (err) => this.onError(err) - }); +private onSuccess(profile: Profile | undefined): void { + // this is where we have something in scope of type profile + + if (profile == undefined) { + // handle this case better? + return; + } - window.alert('Thank you for posting') - this.form.reset() - } + this.postService + .makePost(1, "blah", profile, [], new Date("2022-03-25")) + .subscribe({ + next: (post) => this.onSuccess(profile), + error: (err) => this.onError(err) + }); + + window.alert('Thank you for posting') + + this.form.reset() +} - private onError(error: Error): void { +private onError(error: Error): void { } } diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts index b7598e8..c6e4bdc 100644 --- a/frontend/src/app/post.service.ts +++ b/frontend/src/app/post.service.ts @@ -21,10 +21,13 @@ export class PostService { constructor(private http: HttpClient) {} + posts: Post[] = []; + getPost() { return this.posts; } + getPosts(): Observable { return this.http.get("/api/post"); } @@ -34,8 +37,8 @@ export class PostService { return this.http.post("/api/post/", post); } - deletePost(id: number) { - return this.http.delete("/api/post/" + id) - } + // deletePost(id: number) { + // return this.http.delete("/api/post/" + id) + // } } diff --git a/frontend/src/app/getforum.service.spec.ts b/frontend/src/app/viewforum.service.spec.ts similarity index 53% rename from frontend/src/app/getforum.service.spec.ts rename to frontend/src/app/viewforum.service.spec.ts index 1b7fd9c..6695f8f 100644 --- a/frontend/src/app/getforum.service.spec.ts +++ b/frontend/src/app/viewforum.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { GetforumService } from './getforum.service'; +import { viewforumService } from './viewforum.service'; -describe('GetforumService', () => { - let service: GetforumService; +describe('makeforumService', () => { + let service: viewforumService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(GetforumService); + service = TestBed.inject(viewforumService); }); it('should be created', () => { diff --git a/frontend/src/app/getforum.service.ts b/frontend/src/app/viewforum.service.ts similarity index 88% rename from frontend/src/app/getforum.service.ts rename to frontend/src/app/viewforum.service.ts index d1c7ddf..cb7acbc 100644 --- a/frontend/src/app/getforum.service.ts +++ b/frontend/src/app/viewforum.service.ts @@ -6,7 +6,7 @@ import { HttpClient } from '@angular/common/http'; //just added this @Injectable({ providedIn: 'root' }) -export class GetforumService { +export class viewforumService { constructor() { } } diff --git a/frontend/src/app/viewforum/viewforum.component.ts b/frontend/src/app/viewforum/viewforum.component.ts index 00a372d..b5c9b48 100644 --- a/frontend/src/app/viewforum/viewforum.component.ts +++ b/frontend/src/app/viewforum/viewforum.component.ts @@ -1,10 +1,17 @@ import { Component } from '@angular/core'; +import { Post, PostService } from '../post.service'; +import { Observable } from 'rxjs'; @Component({ selector: 'app-getforum', - templateUrl: './getforum.component.html', - styleUrls: ['./getforum.component.css'] + templateUrl: './viewforum.component.html', + styleUrls: ['./viewforum.component.css'] }) -export class GetforumComponent { +export class viewforumComponent { + // public post$: Observable; + + // constructor(private postService: PostService) { + // this.post$ = postService.getPosts() + // } } From df2f31de9f48eede0cb6fdf9972d8e93be46ee69 Mon Sep 17 00:00:00 2001 From: angelinasu57 Date: Wed, 29 Mar 2023 22:11:31 -0400 Subject: [PATCH 4/5] Clean up whitespace on makeforum. --- frontend/src/app/makeforum/makeforum.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app/makeforum/makeforum.component.ts b/frontend/src/app/makeforum/makeforum.component.ts index c8b7654..823aed8 100644 --- a/frontend/src/app/makeforum/makeforum.component.ts +++ b/frontend/src/app/makeforum/makeforum.component.ts @@ -56,7 +56,6 @@ private onSuccess(profile: Profile | undefined): void { return; } - this.postService .makePost(1, "blah", profile, [], new Date("2022-03-25")) .subscribe({ From b7dfeeb077d5b41ab901948ad53143e122a3e58d Mon Sep 17 00:00:00 2001 From: angelinasu57 Date: Thu, 30 Mar 2023 12:47:21 -0400 Subject: [PATCH 5/5] Edited onSuccess to include dynamic responses as input comes in. Created VewForm HTML similar to STATS page. --- .../src/app/makeforum/makeforum.component.ts | 19 ++++++++++-------- frontend/src/app/post.service.ts | 20 +++++++++++++++---- .../app/viewforum/viewforum.component.html | 17 ++++++++++++++++ .../app/viewforum/viewforum.component.spec.ts | 10 +++++----- .../src/app/viewforum/viewforum.component.ts | 8 ++++---- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/frontend/src/app/makeforum/makeforum.component.ts b/frontend/src/app/makeforum/makeforum.component.ts index 823aed8..9804cfb 100644 --- a/frontend/src/app/makeforum/makeforum.component.ts +++ b/frontend/src/app/makeforum/makeforum.component.ts @@ -33,10 +33,11 @@ export class ForumComponent { onSubmit(): void { let form = this.form.value; + let formContent = form.content ?? ""; this.profileService.profile$ .subscribe({ - next: (profile) => this.onSuccess(profile), + next: (profile) => this.onSuccess(profile, formContent), error: (err) => this.onError(err) }); @@ -48,20 +49,22 @@ export class ForumComponent { // we need to define onerror } -private onSuccess(profile: Profile | undefined): void { +private onSuccess(profile: Profile | undefined, formContent: string): void { // this is where we have something in scope of type profile + // let current: new Date + let unique = Math.random() // generates unique post id + let date: Date = new Date() // generates date of successful form if (profile == undefined) { // handle this case better? return; } - this.postService - .makePost(1, "blah", profile, [], new Date("2022-03-25")) - .subscribe({ - next: (post) => this.onSuccess(profile), - error: (err) => this.onError(err) - }); + this.postService.makePost(unique, formContent, profile, [], date) + // .subscribe({ + // next: (post) => this.onSuccess(profile, formContent), + // error: (err) => this.onError(err) + // }); window.alert('Thank you for posting') diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts index c6e4bdc..4acfb63 100644 --- a/frontend/src/app/post.service.ts +++ b/frontend/src/app/post.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable, throwError } from 'rxjs'; +import { map, Observable, throwError } from 'rxjs'; import { Profile } from './profile/profile.service'; import { Role } from './role'; @@ -29,16 +29,28 @@ export class PostService { } getPosts(): Observable { - return this.http.get("/api/post"); + // let table: Observable = this.http.get("/api/forum"); // copied from the getCheckIns + + // let new_table = table + // .pipe( + // map((x: Post[])=> { + // x.forEach(new_post => { + // new_post.timestamp = new Date(new_post.timestamp) + // }); + // return x; + // }) + // ) + // return new_table + return this.http.get("/api/forum"); } makePost(id: number, content: string, user: Profile, votes: [], timestamp: Date): Observable { let post: Post = {id, content, user, votes, timestamp}; - return this.http.post("/api/post/", post); + return this.http.post("/api/forum/", post); } // deletePost(id: number) { - // return this.http.delete("/api/post/" + id) + // return this.http.delete("/api/forum/" + id) // } } diff --git a/frontend/src/app/viewforum/viewforum.component.html b/frontend/src/app/viewforum/viewforum.component.html index e3c4669..7aa51d1 100644 --- a/frontend/src/app/viewforum/viewforum.component.html +++ b/frontend/src/app/viewforum/viewforum.component.html @@ -1 +1,18 @@

getforum works!

+ + + + + + + + + + + + + + + + +
ResponseFirst NameLast NameDate
{{ post.content }}{{ post.user.first_name}}{{ post.user.last_name }}{{ post.timestamp | date:'YYYY/MM/dd @ hh:MMaa' }}
\ No newline at end of file diff --git a/frontend/src/app/viewforum/viewforum.component.spec.ts b/frontend/src/app/viewforum/viewforum.component.spec.ts index cc6c27d..3f99005 100644 --- a/frontend/src/app/viewforum/viewforum.component.spec.ts +++ b/frontend/src/app/viewforum/viewforum.component.spec.ts @@ -1,18 +1,18 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { GetforumComponent } from './viewforum.component'; +import { viewforumComponent } from './viewforum.component'; describe('GetforumComponent', () => { - let component: GetforumComponent; - let fixture: ComponentFixture; + let component: viewforumComponent; + let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ GetforumComponent ] + declarations: [ viewforumComponent ] }) .compileComponents(); - fixture = TestBed.createComponent(GetforumComponent); + fixture = TestBed.createComponent(viewforumComponent); component = fixture.componentInstance; fixture.detectChanges(); }); diff --git a/frontend/src/app/viewforum/viewforum.component.ts b/frontend/src/app/viewforum/viewforum.component.ts index b5c9b48..66d9617 100644 --- a/frontend/src/app/viewforum/viewforum.component.ts +++ b/frontend/src/app/viewforum/viewforum.component.ts @@ -8,10 +8,10 @@ import { Observable } from 'rxjs'; styleUrls: ['./viewforum.component.css'] }) export class viewforumComponent { - // public post$: Observable; + public post$: Observable; - // constructor(private postService: PostService) { - // this.post$ = postService.getPosts() - // } + constructor(private postService: PostService) { + this.post$ = postService.getPosts() + } }