diff --git a/backend/entities/post_entity.py b/backend/entities/post_entity.py index c1223b3..728eba6 100644 --- a/backend/entities/post_entity.py +++ b/backend/entities/post_entity.py @@ -1,7 +1,7 @@ '''User accounts for all registered users in the application.''' -from sqlalchemy import Integer, String, ForeignKey +from sqlalchemy import Integer, String, ForeignKey, Text from sqlalchemy.orm import Mapped, mapped_column, relationship from typing import Self from .entity_base import EntityBase @@ -21,7 +21,8 @@ class PostEntity(EntityBase): __tablename__ = 'posts' id: Mapped[int] = mapped_column(Integer, primary_key=True) - content: Mapped[str] = mapped_column(String(64), nullable=False, default='') + title: Mapped[str] = mapped_column(String(64), nullable = False, default = '') + content: Mapped[str] = mapped_column(Text, nullable=False, default='') user_id: Mapped[int] = mapped_column(ForeignKey('user.id')) user: Mapped[UserEntity] = relationship("UserEntity",back_populates='posts') @@ -35,6 +36,7 @@ def from_model(cls, model: Post, user: UserEntity ) -> Self: #user_svc: UserPostService = Depends() return cls( id=model.id, + title = model.title, content=model.content, user = user, votes= [], @@ -48,6 +50,7 @@ def to_model(self) -> Post: vote_num = [vote.to_model() for vote in self.votes] return Post( id=self.id, + title = self.title, content=self.content, user=self.user.to_model(), votes=vote_num, diff --git a/backend/models/post.py b/backend/models/post.py index 7de30a2..9238965 100644 --- a/backend/models/post.py +++ b/backend/models/post.py @@ -5,6 +5,7 @@ class Post(BaseModel): id: int | None = None + title: str content: str user: User votes: list[User] = [] diff --git a/frontend/src/app/makeforum/makeforum.component.css b/frontend/src/app/makeforum/makeforum.component.css index 765ecf9..d88739d 100644 --- a/frontend/src/app/makeforum/makeforum.component.css +++ b/frontend/src/app/makeforum/makeforum.component.css @@ -1,13 +1,39 @@ .button { - transition-duration: 0.4s; - } - - .button:hover { - background-color: #4CAF50; /* Green */ - color: white; - } + transition-duration: 0.4s; +} +.button:hover { + background-color: #4CAF50; /* Green */ + color: white; +} + +#back:hover { + background-color: #4786C6; /* Green */ + color: white; +} a { - text-decoration: underline; - } \ No newline at end of file + text-decoration: underline; +} + +.form { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + min-width: 150px; + max-width: 900px; + width: 100%; + margin: 0 auto; + background-color: #333; + padding: 20px; +} + +.full-width { + width: 100%; +} + +h1, h3 { + display: flex; + justify-content: center; +} \ No newline at end of file diff --git a/frontend/src/app/makeforum/makeforum.component.html b/frontend/src/app/makeforum/makeforum.component.html index e32ecc7..95c78e7 100644 --- a/frontend/src/app/makeforum/makeforum.component.html +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -2,13 +2,18 @@

Forum

Make a Forum Post With Resources

-
-
- -
- -
+
+ + Title + + -Back + + Content + + + +
+ diff --git a/frontend/src/app/makeforum/makeforum.component.ts b/frontend/src/app/makeforum/makeforum.component.ts index b7ac590..21b6761 100644 --- a/frontend/src/app/makeforum/makeforum.component.ts +++ b/frontend/src/app/makeforum/makeforum.component.ts @@ -22,6 +22,7 @@ export class ForumComponent { }; form = this.formBuilder.group({ + title: '', content: '' }); @@ -33,52 +34,52 @@ export class ForumComponent { onSubmit(): void { let form = this.form.value; + let formTitle = this.form.value.title ?? ""; let formContent = this.form.value.content ?? ""; console.log(form) this.profileService.profile$ .subscribe({ - next: (profile) => this.onSuccess(profile, formContent), + next: (profile) => this.onSuccess(profile, formContent, formTitle), error: (err) => this.onError(err) }); if (this.form.value.content?.length == 0) { window.alert("Please check your input!") + } + } + private onSuccess(profile: Profile | undefined, formContent: string, formTitle: string): void { + // this is where we have something in scope of type profile + // let current: new Date + let unique = Math.floor(Number(Math.random()*1000)) // generates date of successful form + + let new_Date: Date = new Date(); + // Converting date to string + let result: string = new_Date.toLocaleString(); + // Convert the date object to US specific date string + let date = new_Date.toLocaleString("en-US"); + + if (profile == undefined) { + // handle this case better? + return; } - // 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.floor(Number(Math.random()*1000)) // generates date of successful form - - let new_Date: Date = new Date(); - // Converting date to string - let result: string = new_Date.toLocaleString(); - // Convert the date object to US specific date string - let date = new_Date.toLocaleString("en-US"); - - if (profile == undefined) { - // handle this case better? - return; + this.postService.makePost(unique, formTitle, formContent, profile, [], date) + .subscribe({ + next: (post) => this.onSuccessMP(), + error: (err) => this.onError(err) + }); + console.log(profile.pid) } - this.postService.makePost(unique, formContent, profile, [], date) - .subscribe({ - next: (post) => this.onSuccessMP(), - error: (err) => this.onError(err) - }); - console.log(profile.pid) -} -private onError(error: Error): void { - if (error.message) { - window.alert(error.message); - } else { - window.alert("Unknown error: " + JSON.stringify(error)); + private onError(error: Error): void { + if (error.message) { + window.alert(error.message); + } else { + window.alert("Unknown error: " + JSON.stringify(error)); + } } -} private onSuccessMP(){ diff --git a/frontend/src/app/post.service.ts b/frontend/src/app/post.service.ts index 0e5ec6a..b4010db 100644 --- a/frontend/src/app/post.service.ts +++ b/frontend/src/app/post.service.ts @@ -25,6 +25,7 @@ export interface User{ export interface Post { id: number; + title: string; content: string; user: User; votes: User[]; @@ -61,10 +62,10 @@ export class PostService { return this.http.get("/api/post"); } - makePost(id: number, content: string, user: Profile, votes: [], timestamp: string): Observable { + makePost(id: number, title: string, content: string, user: Profile, votes: [], timestamp: string): Observable { if(user.id && user.first_name && user.last_name && user.email && user.pronouns){ let u: User = {id: user.id, pid:user.pid, onyen: user.onyen, first_name:user.first_name, last_name:user.last_name, email:user.email, pronouns:user.pronouns, permissions: user.permissions}; - let post: Post = {id:id, content: content, user: u, votes: votes, timestamp:timestamp}; + let post: Post = {id: id, title: title, content: content, user: u, votes: votes, timestamp:timestamp}; console.log("Made it to api call") console.log(JSON.stringify(post)) try{ diff --git a/frontend/src/app/viewforum/viewforum.component.html b/frontend/src/app/viewforum/viewforum.component.html index bf3e777..24a4866 100644 --- a/frontend/src/app/viewforum/viewforum.component.html +++ b/frontend/src/app/viewforum/viewforum.component.html @@ -2,6 +2,7 @@

Forum

+ @@ -9,6 +10,7 @@

Forum

+
Title Response First Name Last Name
{{ post.title }} {{ post.content }} {{ post.user.first_name}} {{ post.user.last_name}}