Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data model #3 #7

Merged
merged 16 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ platforms/
plugins/
plugins/android.json
plugins/ios.json
www/
www/*
!www/mock-api
$RECYCLE.BIN/

.DS_Store
Expand Down
8 changes: 7 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {SplashScreen} from "@ionic-native/splash-screen";
import {StanizerService} from "../services/stanizer.service";
import {StoryDetailsPage} from "../pages/storydetails/storydetails";
import {PrismaService} from "../services/back-end/prisma-api.service";
import {UserService} from "../services/back-end/user.service";
import {HttpModule} from "@angular/http";
import {StoryService} from "../services/back-end/story.service";

@NgModule({
declarations: [
Expand All @@ -23,7 +26,8 @@ import {PrismaService} from "../services/back-end/prisma-api.service";
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
IonicModule.forRoot(MyApp),
HttpModule
],
bootstrap: [IonicApp],
entryComponents: [
Expand All @@ -38,6 +42,8 @@ import {PrismaService} from "../services/back-end/prisma-api.service";
SplashScreen,
StanizerService,
PrismaService,
StoryService,
UserService,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
Expand Down
29 changes: 29 additions & 0 deletions src/dto/abstract-story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { StoryType } from './enum/story-type';
import {Category} from "./category";

export abstract class AbstractStory {
id: string;
type: StoryType;
source: string;
title: string;
description: string;
dateAdded: Date;
dateHappened: Date;
likes: string[]; // userId's
comments: Comment[];
categories: Category[];


constructor(json?){
this.id = json.id;
this.type = json.type;
this.source = json.source;
this.title = json.title;
this.description = json.description;
this.dateAdded = json.dateAdded;
this.dateHappened = json.dateHappened;
this.likes = json.likes;
this.comments = json.comments;
this.categories = json.categories;
}
}
33 changes: 33 additions & 0 deletions src/dto/abstract-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export abstract class AbstractUser {

// personal info
id: string;
firstName: string;
lastName: string;
dateOfBirth: Date;
birthLocation: string;

// profile picture
profilePicture: string;

constructor(json?) {
if (json) {
this.firstName = json.firstName;
this.lastName = json.lastName;
this.dateOfBirth = new Date(json.dateOfBirth);
this.birthLocation = json.birthLocation;
this.profilePicture = json.profilePicture;
}
}

getThumbnail(): string {
return this.profilePicture; // TODO: derive thumbnail link
}

/** Gets the age of the user */
getAge(): number {
// this can be derived from the dateOfBirth
return 1; // TODO: with moment.js
}

}
8 changes: 8 additions & 0 deletions src/dto/album.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { UserStory } from './user-story';

export class Album {
id: string;
title: string;
description: string;
stories: UserStory[];
}
4 changes: 4 additions & 0 deletions src/dto/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class Category {
id: string;
name: string;
}
6 changes: 6 additions & 0 deletions src/dto/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class Comment {
id: string;
storyId: string;
userId: string;
comment: string;
}
6 changes: 6 additions & 0 deletions src/dto/enum/story-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum StoryType {
TEXT = 0,
AUDIO = 1,
IMAGE = 2,
VIDEO = 3,
}
Empty file added src/dto/enum/user-story.ts
Empty file.
5 changes: 5 additions & 0 deletions src/dto/heritage-story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { AbstractStory } from './abstract-story';

export class HeritageStory extends AbstractStory {
// TODO: specific heritage properties
}
8 changes: 8 additions & 0 deletions src/dto/life-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class LifeEvent {
id: string;
userId: string;
withUser: string;
name: string;
date: Date;
storyId: string;
}
13 changes: 13 additions & 0 deletions src/dto/patient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AbstractUser } from './abstract-user';
import { WorkPlace } from './work-place';
import { LifeEvent } from './life-event';
import { Relation } from './relation';
import {Category} from "./category";

export class Patient extends AbstractUser {
careHouse: string;
workPlaces: WorkPlace[];
lifeEvents: LifeEvent[];
relations: Relation[];
interests: Category[];
}
11 changes: 11 additions & 0 deletions src/dto/relation-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** relation suggestions */
export const relationTypes = {
"father": "father",
"mother": "mother",
"nurse": "nurse",
"son": "son",
"daughter": "daughter",
"grandson": "grandson",
"granddaughter": "granddaughter",
"friend": "friend"
}
17 changes: 17 additions & 0 deletions src/dto/relation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export class Relation {

id: string;
type: string;
patientId: string;
userId: string;

constructor(json?) {
if (json) {
this.type = json.type;

// this.id = json.id;
// this.patientId = json.patientId;
this.userId = json.userId;
}
}
}
13 changes: 13 additions & 0 deletions src/dto/user-story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AbstractStory } from './abstract-story';

export class UserStory extends AbstractStory {
albumId: string;
originId: string; // heritage origin story


constructor(json?) {
super(json);
this.albumId = json.albumId;
this.originId = json.originId;
}
}
25 changes: 25 additions & 0 deletions src/dto/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AbstractUser } from './abstract-user';
import { Relation } from './relation';

export class User extends AbstractUser {

email: string;
password: string;
relations: Relation[];

constructor(json?) {
super(json);
if (json) {
this.email = json.email;
this.password = json.password;
this.relations = [];
json.relations.forEach(relation => {
relation.id = relation.id ? relation.id : this.id;
console.log("1");
this.relations.push(new Relation(relation));
}
);
}
}

}
5 changes: 5 additions & 0 deletions src/dto/work-place.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class WorkPlace {
function: string;
location: string;
period: Date;
}
2 changes: 1 addition & 1 deletion src/pages/stories/stories.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<ion-header>
<ion-navbar>
<ion-title>
Mijn verhalen
Mijn verhalen - TEST: <div *ngIf="user"> {{user.firstName}}</div>
</ion-title>
</ion-navbar>
</ion-header>
Expand Down
19 changes: 16 additions & 3 deletions src/pages/stories/stories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component } from '@angular/core';
import {Component, OnInit} from '@angular/core';
import { NavController } from 'ionic-angular';
import { StanizerService } from '../../services/stanizer.service';
import {StoryDetailsPage} from "../storydetails/storydetails";
import {UserService} from "../../services/back-end/user.service";
import {User} from "../../dto/user";

/**
* More info on the slides management : https://ionicframework.com/docs/api/components/slides/Slides/
Expand All @@ -10,7 +12,7 @@ import {StoryDetailsPage} from "../storydetails/storydetails";
selector: 'page-stories',
templateUrl: 'stories.html'
})
export class StoriesPage {
export class StoriesPage implements OnInit {

public youtubeUrl:string = "www.youtube.com/embed/ERD4CbBDNI0?rel=0&amp;showinfo=0";
public stanizedYoutubeUrl:any;
Expand Down Expand Up @@ -45,10 +47,21 @@ export class StoriesPage {
{name:"Relevant vandaag",data:this.album4Data},
];

constructor(public navCtrl: NavController,private stanizerService: StanizerService) {
user: User;

constructor(public navCtrl: NavController, private stanizerService: StanizerService,
private userService: UserService) {
this.stanizedYoutubeUrl = this.stanizerService.sanitize(this.youtubeUrl);
}

ngOnInit(): void {
this.userService.getUser("12345").toPromise().then(user => {

this.user = user
console.log("Final user : " + JSON.stringify(this.user));
});
}


showDetails(dataAlbum:Array<any>,dataIndex:number) {
this.navCtrl.push(StoryDetailsPage, {
Expand Down
13 changes: 10 additions & 3 deletions src/services/back-end/prisma-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Injectable, OnInit} from "@angular/core";
import {Http } from "@angular/http";
import {Observable} from "rxjs/Observable";
import 'rxjs/add/observable/of';
import {API_URL, env} from "../../app/environment";
import {Http, RequestOptions} from "@angular/http";
import {NavController} from "ionic-angular";
/**
* Created by Jean on 10-07-17.
*
Expand All @@ -12,8 +13,10 @@ import {NavController} from "ionic-angular";
export class PrismaService implements OnInit {
protected _urlToApi: string = API_URL;
protected _head: Headers = new Headers({'Content-Type': 'application/json; charset=UTF-8'});
_http: Http;

constructor(protected _http: Http, public navCtrl: NavController) {
constructor(_httpSer: Http) {
this._http = _httpSer;
// this._head.set('Accept', 'application/json,application/pdf,application/plain; charset=UTF-8');
// Domain you wish to allow
this._head.set('Access-Control-Allow-Origin', API_URL);
Expand All @@ -35,4 +38,8 @@ export class PrismaService implements OnInit {
this._head.delete('Authorization');
}

public handleError(error: Response | any) {
console.log("Error ! " + JSON.stringify(error));
return Observable.of(error) as Observable<any>;
}
}
27 changes: 27 additions & 0 deletions src/services/back-end/story.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PrismaService } from "./prisma-api.service";
import { Observable } from "rxjs/Observable";
import { User } from "../../dto/user";
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/Rx';
import {Subscription} from 'rxjs/Subscription';
import { Injectable } from "@angular/core";
import {UserStory} from "../../dto/user-story";

@Injectable()
export class StoryService extends PrismaService {


getUserStories(userId: string): Observable<UserStory[]> {
return this._http.get("/mock-api/stories.json").map(res => {
console.log("look here 2" + JSON.stringify(res.json()));
let userStories:UserStory[] = [];
res.json().forEach(story =>
{
userStories.push(new UserStory(story));
})
return userStories;
})
.catch(error => this.handleError(error));
}
}
21 changes: 21 additions & 0 deletions src/services/back-end/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { PrismaService } from "./prisma-api.service";
import { Observable } from "rxjs/Observable";
import { User } from "../../dto/user";
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/Rx';
import {Subscription} from 'rxjs/Subscription';
import { Injectable } from "@angular/core";

@Injectable()
export class UserService extends PrismaService {


getUser(id: string): Observable<User> {
return this._http.get("/mock-api/users_id.json").map(res => {
console.log("look here " + JSON.stringify(res.json()));
return new User(res.json());
})
.catch(error => this.handleError(error));
}
}
Loading