Skip to content
Snippets Groups Projects
Commit 69d582ec authored by Hanna Pelsholen Busterud's avatar Hanna Pelsholen Busterud
Browse files

feat: added user.module and other components.


Co-authored-by: default avatarShirajuki <jonnynl@stud.ntnu.no>
parent 7ea14179
No related branches found
No related tags found
1 merge request!12Resolve "Frontend: Bruker form"
Showing
with 297 additions and 4 deletions
......@@ -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
......@@ -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,
......
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
<p>user-login-form works!</p>
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();
});
});
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 {
}
}
<p>user-profile works!</p>
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();
});
});
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 {
}
}
<p>user-registration-form works!</p>
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();
});
});
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 {
}
}
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 { }
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', () => {
});
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);
}
}
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment