103 lines
2.6 KiB
TypeScript
103 lines
2.6 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Post } from '../../../model/Post';
|
|
import { AuthService } from '../auth/auth.service';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class PostService {
|
|
|
|
constructor(private auth: AuthService) { }
|
|
|
|
examplePosts: Array<Post> = new Array<Post>(
|
|
{
|
|
user: {
|
|
username: "Zámbó Jimmy",
|
|
picture: "assets/placeholder-profile-picture.png",
|
|
followed: true
|
|
},
|
|
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
|
image: "assets/placeholder-profile-picture.png",
|
|
likes: 1,
|
|
liked: true
|
|
},
|
|
{
|
|
user: {
|
|
username: "Zámbó Jimmy",
|
|
picture: "assets/placeholder-profile-picture.png",
|
|
followed: true
|
|
},
|
|
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
|
image: "assets/placeholder-profile-picture.png",
|
|
likes: 1,
|
|
liked: true
|
|
},
|
|
{
|
|
user: {
|
|
username: "Zámbó Jimmy",
|
|
picture: "assets/placeholder-profile-picture.png",
|
|
followed: true
|
|
},
|
|
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
|
image: "assets/placeholder-profile-picture.png",
|
|
likes: 1,
|
|
liked: true
|
|
},
|
|
{
|
|
user: {
|
|
username: "Zámbó Jimmy",
|
|
picture: "assets/placeholder-profile-picture.png",
|
|
followed: true
|
|
},
|
|
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
|
image: "assets/placeholder-profile-picture.png",
|
|
likes: 1,
|
|
liked: true
|
|
},
|
|
);
|
|
|
|
getFeed(length: Number, start: Number): Promise<Array<Post>> {
|
|
return new Promise<Array<Post>>((resolve, reject) => {
|
|
// TODO: fetch feed
|
|
if (this.auth.checkAllowed()) {
|
|
resolve(this.examplePosts)
|
|
} else {
|
|
reject()
|
|
}
|
|
});
|
|
}
|
|
|
|
getPosts(username: String, lenght: Number, start: Number) {
|
|
return new Promise<Array<Post>>((resolve, reject) => {
|
|
// TODO: fetch feed
|
|
if (this.auth.checkAllowed()) {
|
|
resolve(this.examplePosts)
|
|
} else {
|
|
reject()
|
|
}
|
|
});
|
|
}
|
|
|
|
newPost(content: String, image: String) {
|
|
return new Promise<Boolean>((resolve, reject) => {
|
|
// TODO: make post
|
|
if (this.auth.checkAllowed()) {
|
|
this.examplePosts.push({
|
|
user: {
|
|
username: "Zámbó Jimmy",
|
|
picture: "assets/placeholder-profile-picture.png",
|
|
followed: true
|
|
},
|
|
content: content,
|
|
image: image,
|
|
likes: 0,
|
|
liked: false
|
|
});
|
|
resolve(true);
|
|
} else {
|
|
reject();
|
|
}
|
|
});
|
|
}
|
|
}
|