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..bdbf879 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 { viewforumComponent } from './viewforum/viewforum.component'; @NgModule({ declarations: [ @@ -43,7 +44,8 @@ import { ForumComponent } from './forum/forum.component'; HomeComponent, GateComponent, ProfileEditorComponent, - ForumComponent + ForumComponent, + viewforumComponent ], 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 edfd79e..0000000 --- a/frontend/src/app/forum/forum.component.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - selector: 'app-forum', - templateUrl: './forum.component.html', - styleUrls: ['./forum.component.css'] -}) -export class ForumComponent { - public static Route = { - path: 'forum', - component: ForumComponent - }; -} 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..c1dd101 --- /dev/null +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -0,0 +1,29 @@ +

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..9804cfb --- /dev/null +++ b/frontend/src/app/makeforum/makeforum.component.ts @@ -0,0 +1,77 @@ +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'; +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 +// 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; + let formContent = form.content ?? ""; + + this.profileService.profile$ + .subscribe({ + next: (profile) => this.onSuccess(profile, formContent), + 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, 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(unique, formContent, profile, [], date) + // .subscribe({ + // next: (post) => this.onSuccess(profile, formContent), + // 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 new file mode 100644 index 0000000..4acfb63 --- /dev/null +++ b/frontend/src/app/post.service.ts @@ -0,0 +1,56 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { map, Observable, throwError } from 'rxjs'; +import { Profile } from './profile/profile.service'; +import { Role } from './role'; + +export interface Post { + id: number; + content: string; + user: Profile; + 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 { + // 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/forum/", post); + } + + // deletePost(id: number) { + // return this.http.delete("/api/forum/" + id) + // } + +} diff --git a/frontend/src/app/viewforum.service.spec.ts b/frontend/src/app/viewforum.service.spec.ts new file mode 100644 index 0000000..6695f8f --- /dev/null +++ b/frontend/src/app/viewforum.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { viewforumService } from './viewforum.service'; + +describe('makeforumService', () => { + let service: viewforumService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(viewforumService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/viewforum.service.ts b/frontend/src/app/viewforum.service.ts new file mode 100644 index 0000000..cb7acbc --- /dev/null +++ b/frontend/src/app/viewforum.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 viewforumService { + + constructor() { } +} 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..7aa51d1 --- /dev/null +++ b/frontend/src/app/viewforum/viewforum.component.html @@ -0,0 +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 new file mode 100644 index 0000000..3f99005 --- /dev/null +++ b/frontend/src/app/viewforum/viewforum.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { viewforumComponent } from './viewforum.component'; + +describe('GetforumComponent', () => { + let component: viewforumComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ viewforumComponent ] + }) + .compileComponents(); + + fixture = TestBed.createComponent(viewforumComponent); + 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..66d9617 --- /dev/null +++ b/frontend/src/app/viewforum/viewforum.component.ts @@ -0,0 +1,17 @@ +import { Component } from '@angular/core'; +import { Post, PostService } from '../post.service'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'app-getforum', + templateUrl: './viewforum.component.html', + styleUrls: ['./viewforum.component.css'] +}) +export class viewforumComponent { + public post$: Observable; + + constructor(private postService: PostService) { + this.post$ = postService.getPosts() + } + +}