From 287b4e3739187908a2dd0f91d1a3a9866ed8521f Mon Sep 17 00:00:00 2001 From: Will Astilla <77816687+wastilla@users.noreply.github.com> Date: Tue, 11 Apr 2023 15:41:06 -0400 Subject: [PATCH 1/6] Add all functionality to implement post titles in backend (#41) --- backend/entities/post_entity.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/entities/post_entity.py b/backend/entities/post_entity.py index c1223b3..80913a7 100644 --- a/backend/entities/post_entity.py +++ b/backend/entities/post_entity.py @@ -21,6 +21,7 @@ class PostEntity(EntityBase): __tablename__ = 'posts' id: Mapped[int] = mapped_column(Integer, primary_key=True) + title: Mapped[str] = mapped_column(String(64), nullable = False, default = '') content: Mapped[str] = mapped_column(String(64), nullable=False, default='') user_id: Mapped[int] = mapped_column(ForeignKey('user.id')) @@ -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, From 05b2267a41ffc150738ff93c97e32984825f96a0 Mon Sep 17 00:00:00 2001 From: Angelina Su <77803745+angelinasu57@users.noreply.github.com> Date: Tue, 11 Apr 2023 15:42:29 -0400 Subject: [PATCH 2/6] Add title into the viewForum HTML; can see title in the forum. (#42) --- frontend/src/app/post.service.ts | 5 +++-- frontend/src/app/viewforum/viewforum.component.html | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) 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

+ From 6afd523d23d84aeea7a78e7e2937440f8a9d057e Mon Sep 17 00:00:00 2001 From: Warren Quadland <59710771+wquadland@users.noreply.github.com> Date: Tue, 11 Apr 2023 15:53:31 -0400 Subject: [PATCH 3/6] 36 sol post title make forum (#43) * Add angular components and update service for title * add formTitle to makePost call --- .../src/app/makeforum/makeforum.component.css | 44 ++++++++++--- .../app/makeforum/makeforum.component.html | 20 +++--- .../src/app/makeforum/makeforum.component.ts | 61 ++++++++++--------- 3 files changed, 78 insertions(+), 47 deletions(-) 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..13c1327 100644 --- a/frontend/src/app/makeforum/makeforum.component.html +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -2,13 +2,17 @@

Forum

Make a Forum Post With Resources

- -
- -
- - - -Back + + + Title + + + + Content + + + + + \ No newline at end of file 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(){ From 908f37a5d7673890cca42e939bc59824e629d9ff Mon Sep 17 00:00:00 2001 From: wastilla Date: Tue, 11 Apr 2023 16:27:45 -0400 Subject: [PATCH 4/6] Adding changes that failed in previous push --- backend/models/post.py | 1 + frontend/src/app/makeforum/makeforum.component.html | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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.html b/frontend/src/app/makeforum/makeforum.component.html index 13c1327..7d75b35 100644 --- a/frontend/src/app/makeforum/makeforum.component.html +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -10,9 +10,10 @@

Make a Forum Post With Resources

Content - + - \ No newline at end of file + +Back From a6f32b2df4b665b2cc9ec210c90bc1d1d16c7f1d Mon Sep 17 00:00:00 2001 From: wastilla Date: Tue, 11 Apr 2023 16:42:09 -0400 Subject: [PATCH 5/6] Add functionality for variable length text in post content --- backend/entities/post_entity.py | 4 ++-- frontend/src/app/makeforum/makeforum.component.html | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/entities/post_entity.py b/backend/entities/post_entity.py index 80913a7..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 @@ -22,7 +22,7 @@ class PostEntity(EntityBase): id: Mapped[int] = mapped_column(Integer, primary_key=True) title: Mapped[str] = mapped_column(String(64), nullable = False, default = '') - content: 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') diff --git a/frontend/src/app/makeforum/makeforum.component.html b/frontend/src/app/makeforum/makeforum.component.html index 7d75b35..91debe2 100644 --- a/frontend/src/app/makeforum/makeforum.component.html +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -5,15 +5,15 @@

Make a Forum Post With Resources

Title - + Content - + -Back + From fb28e618c7e9de5b25e8ab1ba0080ee3d569d689 Mon Sep 17 00:00:00 2001 From: wquadland <59710771+wquadland@users.noreply.github.com> Date: Tue, 11 Apr 2023 16:51:38 -0400 Subject: [PATCH 6/6] Remove id tag in input for title --- frontend/src/app/makeforum/makeforum.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/makeforum/makeforum.component.html b/frontend/src/app/makeforum/makeforum.component.html index 91debe2..95c78e7 100644 --- a/frontend/src/app/makeforum/makeforum.component.html +++ b/frontend/src/app/makeforum/makeforum.component.html @@ -5,7 +5,7 @@

Make a Forum Post With Resources

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