From 862fa58b54aba571ff4340d7fac2586868f26e2d Mon Sep 17 00:00:00 2001 From: tormodny <tormodny@stud.ntnu.no> Date: Thu, 11 Feb 2021 15:27:09 +0100 Subject: [PATCH] Issue: Added Shared module (#3) --- client/src/app/app.module.ts | 2 ++ .../posts/post-form/post-form.component.html | 4 ++- .../post-form/post-form.component.spec.ts | 2 +- .../posts/post-form/post-form.component.ts | 4 +-- client/src/app/posts/post.module.ts | 4 ++- client/src/app/posts/post.service.ts | 4 +-- client/src/app/shared/shared.module.ts | 14 +++++++++++ .../text-input/text-input.component.html | 1 + .../text-input/text-input.component.scss | 3 +++ .../text-input/text-input.component.spec.ts | 25 +++++++++++++++++++ .../shared/text-input/text-input.component.ts | 15 +++++++++++ server/package.json | 2 +- 12 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 client/src/app/shared/shared.module.ts create mode 100644 client/src/app/shared/text-input/text-input.component.html create mode 100644 client/src/app/shared/text-input/text-input.component.scss create mode 100644 client/src/app/shared/text-input/text-input.component.spec.ts create mode 100644 client/src/app/shared/text-input/text-input.component.ts diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index fc70334..fb29b91 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -5,6 +5,7 @@ import { HttpClientModule } from '@angular/common/http'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { PostModule } from './posts/post.module'; +import { SharedModule } from './shared/shared.module'; @NgModule({ declarations: [ @@ -14,6 +15,7 @@ import { PostModule } from './posts/post.module'; BrowserModule, AppRoutingModule, PostModule, + SharedModule, HttpClientModule ], providers: [], diff --git a/client/src/app/posts/post-form/post-form.component.html b/client/src/app/posts/post-form/post-form.component.html index d3731fb..51f1e96 100644 --- a/client/src/app/posts/post-form/post-form.component.html +++ b/client/src/app/posts/post-form/post-form.component.html @@ -3,4 +3,6 @@ <p>Title: {{displayPost.getTitle}}</p> <p>Description: {{displayPost.getDescription}}</p> <p>Timestamp: {{displayPost.getTimestamp}}</p> -<p>Owner: {{displayPost.getOwner}}</p> \ No newline at end of file +<p>Owner: {{displayPost.getOwner}}</p> + +<app-text-input></app-text-input> \ No newline at end of file diff --git a/client/src/app/posts/post-form/post-form.component.spec.ts b/client/src/app/posts/post-form/post-form.component.spec.ts index ed44eee..e648ca9 100644 --- a/client/src/app/posts/post-form/post-form.component.spec.ts +++ b/client/src/app/posts/post-form/post-form.component.spec.ts @@ -36,6 +36,6 @@ describe('PostFormComponent', () => { }) it('should deserialize Post', () => { - expect(component.deserializedPost.getUser).toEqual("Admin"); + expect(component.deserializedPost.getOwner).toEqual("Admin"); }) }); diff --git a/client/src/app/posts/post-form/post-form.component.ts b/client/src/app/posts/post-form/post-form.component.ts index c56ea19..212b515 100644 --- a/client/src/app/posts/post-form/post-form.component.ts +++ b/client/src/app/posts/post-form/post-form.component.ts @@ -21,14 +21,14 @@ export class PostFormComponent implements OnInit { title: "TestAnnonse", description: "Beskrivelse", timestamp: 1612952332000, - user: "Admin", + owner: "Admin", imageUrl: "url" }); this.serializedPost = post.serialize(); this.deserializedPost.deserialize(post.serialize()); - this.postService.getPost(0) + this.postService.getPost(1) .then((gettedPost: Post) => { this.displayPost = gettedPost; }).catch((err: any) => { diff --git a/client/src/app/posts/post.module.ts b/client/src/app/posts/post.module.ts index 80a6a34..6abbc81 100644 --- a/client/src/app/posts/post.module.ts +++ b/client/src/app/posts/post.module.ts @@ -1,6 +1,7 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { PostFormComponent } from './post-form/post-form.component'; +import { SharedModule } from '../shared/shared.module'; @@ -9,7 +10,8 @@ import { PostFormComponent } from './post-form/post-form.component'; PostFormComponent ], imports: [ - CommonModule + CommonModule, + SharedModule ] }) export class PostModule { } diff --git a/client/src/app/posts/post.service.ts b/client/src/app/posts/post.service.ts index 2314d5d..312369b 100644 --- a/client/src/app/posts/post.service.ts +++ b/client/src/app/posts/post.service.ts @@ -30,7 +30,7 @@ export class PostService { ); } - get_post(id: number) { + private get_post(id: number) { return this.http.get(this.postUrl + id); } @@ -48,7 +48,7 @@ export class PostService { ); } - add_post(post: Post) { + private add_post(post: Post) { return this.http.post(this.postUrl, post.serialize()); } } diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts new file mode 100644 index 0000000..cfbb9db --- /dev/null +++ b/client/src/app/shared/shared.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { TextInputComponent } from './text-input/text-input.component'; + + + +@NgModule({ + declarations: [TextInputComponent], + exports: [TextInputComponent], + imports: [ + CommonModule + ] +}) +export class SharedModule { } diff --git a/client/src/app/shared/text-input/text-input.component.html b/client/src/app/shared/text-input/text-input.component.html new file mode 100644 index 0000000..45be20b --- /dev/null +++ b/client/src/app/shared/text-input/text-input.component.html @@ -0,0 +1 @@ +<input type="text" id="textField"> \ No newline at end of file diff --git a/client/src/app/shared/text-input/text-input.component.scss b/client/src/app/shared/text-input/text-input.component.scss new file mode 100644 index 0000000..e8b11aa --- /dev/null +++ b/client/src/app/shared/text-input/text-input.component.scss @@ -0,0 +1,3 @@ +#textField{ + padding: 5px; +} \ No newline at end of file diff --git a/client/src/app/shared/text-input/text-input.component.spec.ts b/client/src/app/shared/text-input/text-input.component.spec.ts new file mode 100644 index 0000000..f895776 --- /dev/null +++ b/client/src/app/shared/text-input/text-input.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { TextInputComponent } from './text-input.component'; + +describe('TextInputComponent', () => { + let component: TextInputComponent; + let fixture: ComponentFixture<TextInputComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ TextInputComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(TextInputComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/shared/text-input/text-input.component.ts b/client/src/app/shared/text-input/text-input.component.ts new file mode 100644 index 0000000..a739874 --- /dev/null +++ b/client/src/app/shared/text-input/text-input.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-text-input', + templateUrl: './text-input.component.html', + styleUrls: ['./text-input.component.scss'] +}) +export class TextInputComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/server/package.json b/server/package.json index 6a225ce..d3e68d2 100644 --- a/server/package.json +++ b/server/package.json @@ -4,7 +4,7 @@ "description": "REST API with MySQL", "main": "src/index.ts", "scripts": { - "start": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", + "start": "nodemon --watch 'src/**/*.ts' --exec \"ts-node\" src/index.ts", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", -- GitLab