-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from renantee/course-project
Blog Application with Angular and Node JS (Updated)
- Loading branch information
Showing
32 changed files
with
436 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './auth.guard'; | ||
export * from './error.interceptor'; | ||
export * from './jwt.interceptor'; | ||
export * from './fake-backend'; | ||
export * from './fake-backend'; | ||
export * from './jwt.interceptor'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './alert'; | ||
export * from './post'; | ||
export * from './role'; | ||
export * from './user'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export class Post { | ||
id: string; | ||
author: string; | ||
title: string; | ||
content: string; | ||
date: Date; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum Role { | ||
User = 'User', | ||
Admin = 'Admin' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
export class User { | ||
import { Role } from "./role"; | ||
|
||
export class User { | ||
_id: string; | ||
id: string; | ||
username: string; | ||
password: string; | ||
firstName: string; | ||
lastName: string; | ||
token: string; | ||
role: Role; | ||
token?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './account.service'; | ||
export * from './alert.service'; | ||
export * from './post.service'; | ||
export * from './post.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="card mt-4"> | ||
<h4 class="card-header">Admin</h4> | ||
<div class="card-body"> | ||
<p>This page can be accessed <u>only by administrators</u>.</p> | ||
<p class="mb-1">All users from secure (admin only) api end point:</p> | ||
<div *ngIf="loading" class="spinner-border spinner-border-sm"></div> | ||
<ul *ngIf="users"> | ||
<li *ngFor="let user of users">{{user.firstName}} {{user.lastName}}</li> | ||
</ul> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { first } from 'rxjs/operators'; | ||
|
||
import { User } from '@app/_models'; | ||
import { AccountService } from '@app/_services'; | ||
|
||
@Component({ templateUrl: 'admin.component.html' }) | ||
export class AdminComponent implements OnInit { | ||
loading = false; | ||
users: User[] = []; | ||
|
||
constructor(private accountService: AccountService) { } | ||
|
||
ngOnInit() { | ||
this.loading = true; | ||
this.accountService.getAll().pipe(first()).subscribe(users => { | ||
this.loading = false; | ||
this.users = users; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './admin.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
<div class="p-4"> | ||
<div class="container"> | ||
<h1>Hi {{user.firstName}}!</h1> | ||
<p>You're logged in with Angular 10!!</p> | ||
<p><a routerLink="/users">Manage Users</a></p> | ||
<div class="card mt-4"> | ||
<h4 class="card-header">Home</h4> | ||
<div class="card-body"> | ||
<p>You're logged in with Angular 10 & JWT!!</p> | ||
<p>Your role is: <strong>{{user.role}}</strong>.</p> | ||
<p>This page can be accessed by <u>all authenticated users</u>.</p> | ||
<p class="mb-1">Current user from secure api end point:</p> | ||
<div *ngIf="loading" class="spinner-border spinner-border-sm"></div> | ||
<ul *ngIf="userFromApi"> | ||
<li>{{userFromApi.firstName}} {{userFromApi.lastName}}</li> | ||
</ul> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
import { Component } from '@angular/core'; | ||
import { first } from 'rxjs/operators'; | ||
|
||
import { User } from '@app/_models'; | ||
import { AccountService } from '@app/_services'; | ||
|
||
@Component({ templateUrl: 'home.component.html' }) | ||
export class HomeComponent { | ||
loading = false; | ||
user: User; | ||
userFromApi: User; | ||
|
||
constructor(private accountService: AccountService) { | ||
constructor( | ||
private accountService: AccountService | ||
) { | ||
this.user = this.accountService.userValue; | ||
} | ||
|
||
ngOnInit() { | ||
this.loading = true; | ||
this.accountService.getById(this.user.id).pipe(first()).subscribe(user => { | ||
this.loading = false; | ||
this.userFromApi = user; | ||
}); | ||
} | ||
} |
Oops, something went wrong.