Skip to content

Commit ca0658b

Browse files
committed
Best practise: models are now modules
1 parent a67b328 commit ca0658b

File tree

16 files changed

+2885
-130692
lines changed

16 files changed

+2885
-130692
lines changed
Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Component } from '@angular/core';
22
import { Http } from '@angular/http';
3+
import { ResultJson } from "../../models/ResultJson";
4+
import { Book } from "../../models/Book";
35

46
@Component({
57
selector: 'books',
@@ -22,7 +24,7 @@ export class BooksComponent {
2224
loading: boolean;
2325
baseApiUrl: string;
2426
searchString = '';
25-
books: Book[];
27+
books: IBook[];
2628

2729
// public functions
2830
getDwBook: () => void;
@@ -32,9 +34,9 @@ export class BooksComponent {
3234
var route = `${this.baseApiUrl}${this.searchString}`;
3335
this.loading = true;
3436
this.http.get(route).subscribe((result) => {
35-
var resultJson = result.json() as ResultJson;
37+
var resultJson = result.json() as IResultJson;
3638
if(resultJson.success) {
37-
this.books = new Array<Book>();
39+
this.books = new Array<IBook>();
3840
result.json().result.forEach(element => {
3941
this.books.push(new Book(element.bookName, element.bookIsbn10,
4042
element.bookIsbn13, element.bookDescription,
@@ -45,36 +47,4 @@ export class BooksComponent {
4547
});
4648
}
4749
}
48-
}
49-
50-
interface ResultJson{
51-
success: boolean;
52-
result: string;
53-
}
54-
55-
class Book implements IBook {
56-
constructor(bookName: string, bookIsbn10: string, bookIsbn13:
57-
string, bookDescription: string, bookCoverImageUrl: string){
58-
this.bookName = bookName;
59-
this.bookIsbn10 = bookIsbn10;
60-
this.bookIsbn13 = bookIsbn13;
61-
this.bookDescription = bookDescription;
62-
this.bookCoverImageUrl = bookCoverImageUrl;
63-
}
64-
65-
bookName: string;
66-
bookIsbn10: string;
67-
bookIsbn13: string;
68-
bookDescription: string;
69-
bookCoverImageUrl: string;
70-
71-
72-
}
73-
74-
interface IBook {
75-
bookName: string;
76-
bookIsbn10: string;
77-
bookIsbn13: string;
78-
bookDescription: string;
79-
bookCoverImageUrl: string;
8050
}
Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Component } from '@angular/core';
22
import { Http } from '@angular/http';
3+
import { ResultJson } from "../../models/ResultJson";
4+
import { Character } from "../../models/Character";
35

46
@Component({
57
selector: 'characters',
@@ -32,7 +34,7 @@ export class CharacterComponent {
3234
this.success = false;
3335
var route = `${this.baseApiUrl}${this.searchString}`;
3436
this.http.get(route).subscribe((result) => {
35-
var resultJson = result.json() as ResultJson;
37+
var resultJson = result.json() as IResultJson;
3638
if(resultJson.success) {
3739
this.success = true;
3840
this.characters = new Array<ICharacter>();
@@ -43,32 +45,4 @@ export class CharacterComponent {
4345
});
4446
}
4547
}
46-
}
47-
48-
interface ResultJson{
49-
success: boolean;
50-
result: string;
51-
}
52-
53-
class Character implements ICharacter {
54-
constructor(characterName: string, books: string[]){
55-
this.characterName = characterName;
56-
this.books = books;
57-
58-
this.booksAsString = (): string =>{
59-
return books.map(b => b).join(', ');
60-
}
61-
}
62-
characterName: string;
63-
books: string[];
64-
booksAsString: () => string;
65-
66-
67-
}
68-
69-
interface ICharacter {
70-
characterName: string;
71-
books: string[];
72-
73-
booksAsString:() => string;
7448
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface IBook {
2+
bookName: string;
3+
bookIsbn10: string;
4+
bookIsbn13: string;
5+
bookDescription: string;
6+
bookCoverImageUrl: string;
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface ICharacter {
2+
characterName: string;
3+
books: string[];
4+
5+
booksAsString:() => string;
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface IResultJson{
2+
success: boolean;
3+
result: string;
4+
}

Angular2/ClientApp/app/models/Book.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export class Book implements IBook {
2+
constructor(bookName: string, bookIsbn10: string, bookIsbn13:
3+
string, bookDescription: string, bookCoverImageUrl: string){
4+
this.bookName = bookName;
5+
this.bookIsbn10 = bookIsbn10;
6+
this.bookIsbn13 = bookIsbn13;
7+
this.bookDescription = bookDescription;
8+
this.bookCoverImageUrl = bookCoverImageUrl;
9+
}
10+
11+
bookName: string;
12+
bookIsbn10: string;
13+
bookIsbn13: string;
14+
bookDescription: string;
15+
bookCoverImageUrl: string;
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class Character implements ICharacter {
2+
constructor(characterName: string, books: string[]){
3+
this.characterName = characterName;
4+
this.books = books;
5+
6+
this.booksAsString = (): string =>{
7+
return books.map(b => b).join(', ');
8+
}
9+
}
10+
characterName: string;
11+
books: string[];
12+
booksAsString: () => string;
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class ResultJson{
2+
success: boolean;
3+
result: string;
4+
}

0 commit comments

Comments
 (0)