basic post and user services
This commit is contained in:
parent
bc8c7a3a07
commit
154bcca1a3
@ -1,56 +1,20 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Post } from '../../model/Post';
|
||||
import { PostService } from '../services/data/post.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-feed',
|
||||
templateUrl: './feed.component.html',
|
||||
styleUrl: './feed.component.scss'
|
||||
})
|
||||
export class FeedComponent {
|
||||
posts: 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
|
||||
},
|
||||
);
|
||||
export class FeedComponent implements OnInit {
|
||||
posts: Array<Post> | undefined;
|
||||
|
||||
constructor(private postService: PostService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.postService.getFeed(10, 0)
|
||||
.then(posts => { this.posts = posts; })
|
||||
.catch(()=> { alert('failed to fetch feed'); });
|
||||
}
|
||||
}
|
||||
|
16
src/app/services/data/post.service.spec.ts
Normal file
16
src/app/services/data/post.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PostService } from './post.service';
|
||||
|
||||
describe('PostService', () => {
|
||||
let service: PostService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(PostService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
80
src/app/services/data/post.service.ts
Normal file
80
src/app/services/data/post.service.ts
Normal file
@ -0,0 +1,80 @@
|
||||
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
|
||||
this.auth.getToken()
|
||||
.then( (token)=> {
|
||||
resolve(this.examplePosts);
|
||||
})
|
||||
.catch( ()=> { reject() });
|
||||
});
|
||||
}
|
||||
|
||||
getPosts(username: String, lenght: Number, start: Number) {
|
||||
return new Promise<Array<Post>>((resolve, reject) => {
|
||||
// TODO: fetch feed
|
||||
this.auth.getToken()
|
||||
.then( (token)=> {
|
||||
resolve(this.examplePosts);
|
||||
})
|
||||
.catch( ()=> { reject() });
|
||||
});
|
||||
}
|
||||
}
|
16
src/app/services/data/user.service.spec.ts
Normal file
16
src/app/services/data/user.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UserService } from './user.service';
|
||||
|
||||
describe('UserService', () => {
|
||||
let service: UserService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(UserService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
28
src/app/services/data/user.service.ts
Normal file
28
src/app/services/data/user.service.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { User } from '../../../model/User';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserService {
|
||||
|
||||
exampleUser: User = {
|
||||
username: "Zámbó Jimmy",
|
||||
picture: "assets/placeholder-profile-picture.png",
|
||||
followed: true
|
||||
}
|
||||
|
||||
constructor(private auth: AuthService) { }
|
||||
|
||||
getUser(username: String): Promise<User> {
|
||||
return new Promise<User>((resolve, reject) => {
|
||||
// TODO: get user
|
||||
this.auth.getToken()
|
||||
.then((token) => {
|
||||
resolve(this.exampleUser);
|
||||
})
|
||||
.catch(() => { reject() });
|
||||
});
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<app-top-menu></app-top-menu>
|
||||
<app-side-menu></app-side-menu>
|
||||
<div id="main">
|
||||
<app-large-user [user]="exampleUser"></app-large-user>
|
||||
<app-large-user [user]="user"></app-large-user>
|
||||
<app-post *ngFor="let post of posts" [post]="post"></app-post>
|
||||
</div>
|
||||
|
@ -1,47 +1,28 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Post } from '../../model/Post';
|
||||
import { User } from '../../model/User';
|
||||
import { PostService } from '../services/data/post.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { UserService } from '../services/data/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
templateUrl: './user.component.html',
|
||||
styleUrl: './user.component.scss'
|
||||
})
|
||||
export class UserComponent {
|
||||
exampleUser: User = {
|
||||
username: "Zámbó Jimmy",
|
||||
picture: "assets/placeholder-profile-picture.png",
|
||||
followed: true
|
||||
}
|
||||
export class UserComponent implements OnInit{
|
||||
user: User | undefined;
|
||||
posts: Array<Post> | undefined;
|
||||
|
||||
posts: Array<Post> = new Array<Post>(
|
||||
{
|
||||
user: this.exampleUser,
|
||||
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
||||
image: "assets/placeholder-profile-picture.png",
|
||||
likes: 1,
|
||||
liked: true
|
||||
},
|
||||
{
|
||||
user: this.exampleUser,
|
||||
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
||||
image: "assets/placeholder-profile-picture.png",
|
||||
likes: 1,
|
||||
liked: true
|
||||
},
|
||||
{
|
||||
user: this.exampleUser,
|
||||
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
||||
image: "assets/placeholder-profile-picture.png",
|
||||
likes: 1,
|
||||
liked: true
|
||||
},
|
||||
{
|
||||
user: this.exampleUser,
|
||||
content: "Bukott diák vagyok én, nem bírom el a szenvedést.",
|
||||
image: "assets/placeholder-profile-picture.png",
|
||||
likes: 1,
|
||||
liked: true
|
||||
},
|
||||
);
|
||||
constructor(private postService: PostService, private userService: UserService, private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.userService.getUser(this.route.snapshot.params['username'])
|
||||
.then(user => { this.user = user })
|
||||
.catch(() => alert('failed to get user'));
|
||||
|
||||
this.postService.getPosts(this.route.snapshot.params['username'], 10, 0)
|
||||
.then(posts => { this.posts = posts; })
|
||||
.catch(()=> { alert('failed to fetch feed'); });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user