diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index 498abb33f3b3e938c1e3b78f45a9d964f42b35d2..fb537c449cfef0869fef975766f58a14f5876598 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -3,15 +3,22 @@ import { RouterModule, Routes } from '@angular/router'; import { PostDetailsComponent } from './posts/post-details/post-details.component'; import { PostFormComponent } from './posts/post-form/post-form.component'; import { PostListComponent } from './posts/post-list/post-list.component'; +import { UserRegistrationFormComponent } from './users/user-registration-form/user-registration-form.component'; +import { UserLoginFormComponent } from './users/user-login-form/user-login-form.component'; +import { UserProfileComponent } from './users/user-profile/user-profile.component'; const routes: Routes = [ { path: 'annonse/ny', component: PostFormComponent }, { path: 'annonse', component: PostListComponent }, - { path: 'annonse/:id', component: PostDetailsComponent } + { path: 'annonse/:id', component: PostDetailsComponent }, + + { path: 'profile', component: UserProfileComponent }, + { path: 'register', component: UserRegistrationFormComponent }, + { path: 'login', component: UserLoginFormComponent } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) -export class AppRoutingModule { } +export class AppRoutingModule { } \ No newline at end of file diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index fb29b9167c4d5cdd2f077f9fba26de35f258c19a..28a13e79acd31f0b55aecb2588037c178e72002e 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -5,14 +5,18 @@ import { HttpClientModule } from '@angular/common/http'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { PostModule } from './posts/post.module'; +import { UserModule } from './users/user.module'; import { SharedModule } from './shared/shared.module'; + @NgModule({ declarations: [ - AppComponent, + AppComponent ], imports: [ BrowserModule, + UserModule, + AppRoutingModule, PostModule, SharedModule, diff --git a/client/src/app/models/user.model.ts b/client/src/app/models/user.model.ts new file mode 100644 index 0000000000000000000000000000000000000000..7c391c96165f0f5c8e58c01040e0010d3ef55d97 --- /dev/null +++ b/client/src/app/models/user.model.ts @@ -0,0 +1,78 @@ +import { Deserializable } from "./deserializable.model"; +import { Serializable } from "./serializable.model"; + +export class User implements Deserializable, Serializable { + private userid: number; + private username: string; + private email: string; + private password: string; + private create_time: Date; + + constructor(input: any = null) { + if (input) { + this.deserialize(input); + } else { + this.userid = 0; + this.username = null; + this.email = null; + this.password = null; + this.create_time = new Date(); + } + } + + deserialize(input: Object): this { + Object.assign(this, input); + return this; + } + + serialize(): Object { + return { + userid: this.userid, + username: this.username, + email: this.email, + password: this.password, + create_time: this.create_time + }; + } + + get getUserId() { + return this.userid; + } + + set setUserId(userid: number) { + this.userid = userid; + } + + get getUsername() { + return this.username; + } + + set setUsername(username: string) { + this.username = username; + } + + get getEmail() { + return this.email; + } + + set setEmail(email: string) { + this.email = email; + } + + get getPassword() { + return this.password; + } + + set setPassword(password: string) { + this.password = password; + } + + get getCreateTime() { + return this.create_time; + } + + set setCreateTime(create_time: Date) { + this.create_time = create_time; + } + +} \ No newline at end of file diff --git a/client/src/app/users/user-login-form/user-login-form.component.html b/client/src/app/users/user-login-form/user-login-form.component.html new file mode 100644 index 0000000000000000000000000000000000000000..0df1f07d864ecd0c6172b5fa0a3762fad6d49887 --- /dev/null +++ b/client/src/app/users/user-login-form/user-login-form.component.html @@ -0,0 +1 @@ +<p>user-login-form works!</p> diff --git a/client/src/app/users/user-login-form/user-login-form.component.scss b/client/src/app/users/user-login-form/user-login-form.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/client/src/app/users/user-login-form/user-login-form.component.spec.ts b/client/src/app/users/user-login-form/user-login-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..1e5bb79f2b6a8740c5ac7d47f366eb95a493a309 --- /dev/null +++ b/client/src/app/users/user-login-form/user-login-form.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UserLoginFormComponent } from './user-login-form.component'; + +describe('UserLoginFormComponent', () => { + let component: UserLoginFormComponent; + let fixture: ComponentFixture<UserLoginFormComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ UserLoginFormComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(UserLoginFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/users/user-login-form/user-login-form.component.ts b/client/src/app/users/user-login-form/user-login-form.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..11765575e887e7fea94cc0cf18095a747e51ff98 --- /dev/null +++ b/client/src/app/users/user-login-form/user-login-form.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-user-login-form', + templateUrl: './user-login-form.component.html', + styleUrls: ['./user-login-form.component.scss'] +}) +export class UserLoginFormComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/client/src/app/users/user-profile/user-profile.component.html b/client/src/app/users/user-profile/user-profile.component.html new file mode 100644 index 0000000000000000000000000000000000000000..fedcb8b611d8a4673ac53b4298a0877c86b35a42 --- /dev/null +++ b/client/src/app/users/user-profile/user-profile.component.html @@ -0,0 +1 @@ +<p>user-profile works!</p> diff --git a/client/src/app/users/user-profile/user-profile.component.scss b/client/src/app/users/user-profile/user-profile.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/client/src/app/users/user-profile/user-profile.component.spec.ts b/client/src/app/users/user-profile/user-profile.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..f0c36edb69f01b01f0236a8681070a3c8dce4027 --- /dev/null +++ b/client/src/app/users/user-profile/user-profile.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UserProfileComponent } from './user-profile.component'; + +describe('UserProfileComponent', () => { + let component: UserProfileComponent; + let fixture: ComponentFixture<UserProfileComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ UserProfileComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(UserProfileComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/users/user-profile/user-profile.component.ts b/client/src/app/users/user-profile/user-profile.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..d7ff7744471c65e7b4e010e463f08f46b0f96d4a --- /dev/null +++ b/client/src/app/users/user-profile/user-profile.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-user-profile', + templateUrl: './user-profile.component.html', + styleUrls: ['./user-profile.component.scss'] +}) +export class UserProfileComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/client/src/app/users/user-registration-form/user-registration-form.component.html b/client/src/app/users/user-registration-form/user-registration-form.component.html new file mode 100644 index 0000000000000000000000000000000000000000..e32d6dfe20a5eb138c6d277097e1eac66da5a6c4 --- /dev/null +++ b/client/src/app/users/user-registration-form/user-registration-form.component.html @@ -0,0 +1 @@ +<p>user-registration-form works!</p> diff --git a/client/src/app/users/user-registration-form/user-registration-form.component.scss b/client/src/app/users/user-registration-form/user-registration-form.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/client/src/app/users/user-registration-form/user-registration-form.component.spec.ts b/client/src/app/users/user-registration-form/user-registration-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..142dcbf5fcb915aba5b1c810ba4afd43b6a71d8d --- /dev/null +++ b/client/src/app/users/user-registration-form/user-registration-form.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UserRegistrationFormComponent } from './user-registration-form.component'; + +describe('UserRegistrationFormComponent', () => { + let component: UserRegistrationFormComponent; + let fixture: ComponentFixture<UserRegistrationFormComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ UserRegistrationFormComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(UserRegistrationFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/users/user-registration-form/user-registration-form.component.ts b/client/src/app/users/user-registration-form/user-registration-form.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..7d164b8dbc7cd8cbb7f4d175aa2f45d47571af02 --- /dev/null +++ b/client/src/app/users/user-registration-form/user-registration-form.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-user-registration-form', + templateUrl: './user-registration-form.component.html', + styleUrls: ['./user-registration-form.component.scss'] +}) +export class UserRegistrationFormComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/client/src/app/users/user.module.ts b/client/src/app/users/user.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..3356ea2ac1b5d462dcfcf612be61cfd9899ba0bf --- /dev/null +++ b/client/src/app/users/user.module.ts @@ -0,0 +1,24 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { SharedModule } from '../shared/shared.module'; +import { FormsModule } from '@angular/forms'; +import { UserRegistrationFormComponent } from './user-registration-form/user-registration-form.component'; +import { UserProfileComponent } from './user-profile/user-profile.component'; +import { UserLoginFormComponent } from './user-login-form/user-login-form.component'; + + + +@NgModule({ + declarations: [ + UserRegistrationFormComponent, + UserProfileComponent, + UserLoginFormComponent + ], + imports: [ + CommonModule, + SharedModule, + FormsModule + ] +}) + +export class UserModule { } diff --git a/client/src/app/users/user.service.spec.ts b/client/src/app/users/user.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..73647c8daffefe1f89df75de6fa91c49be513c38 --- /dev/null +++ b/client/src/app/users/user.service.spec.ts @@ -0,0 +1,10 @@ +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { TestBed } from '@angular/core/testing'; +import { User } from '../models/user.model'; + +import { UserService } from './user.service'; + +describe('UserService', () => { + +}); + diff --git a/client/src/app/users/user.service.ts b/client/src/app/users/user.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..3521b5f3e96bcb46f22613401c7521b575795838 --- /dev/null +++ b/client/src/app/users/user.service.ts @@ -0,0 +1,47 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { User } from '../models/user.model'; + +@Injectable({ + providedIn: 'root' +}) +export class UserService { + + userUrl = "api/post/" + + constructor(private http: HttpClient) { } + + /** + * Get all users from database. + */ + getAllUsers(): Promise<Array<User>> { + return new Promise<Array<User>>( + (resolve, reject) => { + this.get_all_users().subscribe((data: any) => { + try { + let outputUsers = []; // array of users + for (let user of data.data) { + outputUsers.push(new User(user)); + + if (user.getId == 0) { + reject("Could not deserialize User"); + return; + } + } + resolve(outputUsers); + } catch (err: any) { + reject(err); + } + }, + (err: any) => { + console.log(err.message); + reject(err); + }); + } + ); + } + + private get_all_users() { + return this.http.get(this.userUrl); + } +} diff --git a/server/src/controllers/postController/index.ts b/server/src/controllers/postController/index.ts index ed5a95f2e7c0d5568a7b6d1854194d7fe8210f9c..7fcf43dcf493d33699e30fc07507c4336037e1bd 100644 --- a/server/src/controllers/postController/index.ts +++ b/server/src/controllers/postController/index.ts @@ -25,7 +25,7 @@ router.route("/").post(async (request: Request, response: Response) => { description: description, timestamp: timestamp, owner: owner, - category: category, + categoryid: category, imageUrl: imageUrl, }; if (Object.values(post).filter((p) => p == undefined).length > 0)