The Objective of this assignment is to understand routing and security implements in an angular application
By the end of the assignment you should be able to understand
- Forms
- Authentication and Security
- Routing and Guards
- Fork this boilerplate repository
- Clone the boilerplate repository and cd into it
- Install dependencies
npm install
- Run the backend
npm run serve
which shall run on port:3000 - Run the frontend
npm run start
which shall run on port:4200
- The NEWS API should be used as data source
- To get trending news use the following endpoint. [Top Headlines endpoint] (https://newsapi.org/v2/top-headlines?country=in&apikey=<<api_key>>&page=1)
- To register for an API key, follow these steps:
- You need to signup to [NEWSAPI] (https://newsapi.org/register).
- After registration, API key is generated for you.
- On running npm run serve, following apis would be available for your use:
- To authenticate user - POST - http://localhost:3000/auth/v1 - expecting data - { username, password }
- To check if user is authenticated - POST - http://localhost:3000/auth/v1/isAuthenticated - expecting header - { 'Authorization', Bearer ${token} }
- To get news - GET - http://localhost:3000/api/v1/news - expecting header - { 'Authorization', Bearer ${token} }
- To add a news - POST - http://localhost:3000/api/v1/news - expecting header - { 'Authorization', Bearer ${token} } and data - { news }
The primary objective of this assignment is to implement Routing, and security through JWT Authentication and Route Guard In continuation, to the requirements stated in Level-1 assignment, below are the broad requirements for this assignment:
- Application should launch with login page
- Upon sign-in, user should be navigated to dashboard that displays trending news stories
- Each news story item can be bookmarked for later read by clicking on 'Read Later' button
- The header should provide link to navigate to news-reader view and display the bookmarked news items
- Header should contain link to logout
- Without login no page should be navigated to and if attempted, user should be redirected to login page
-
Fork and clone the boilerplate
-
Install all the dependencies using
npm install
command -
The boilerplate code contains code files for 9 Components
- app
- header
- login
- dashboard
- news-stories
- news-story-card
- news-reader
- news-reader-card
- footer
-
The
app
component should be the bootstrap component and load the header, footer components and provide router outlet for login and dashboard components -
The
header
Component, in addition to handling the requirements stated in assignment-level-1, also handles below requirements:5.a Bootstrap navbar component contains
face
mat-icon, which when clicked allows user to logout5.b The
favorite
mat-icon when clicked will navigate to news-reader page that displays bookmarked news5.c The
home
mat-icon when clicked will navigate to news-stories page that displays trending news stories -
The
login
component should be loaded whenever an unauthenticated user accesses the application6.a This component is expected to use Angular Reactive Forms with two form controls
username
andpassword
with classesusername
andpassword
respectively and a button with text Submit to submit the form6.b This component is expected to have an element with class name
error-message
to display any server error messages6.c It should have a
loginSubmit()
method called when form is submitted which shall validate the user credentials with server, if validation is successful, user is redirected to dashboard and his token is saved in local storage6.d The component class should contain
submitMessage
property that is assigned with error message, whenever login fails. The value of this property should be displayed on the component in element with class nameerror-message
6.e The input elements for
username
andpassword
are mandatory fields and should display error messages, if the user submits the form with blank fields -
The
dashboard
component provides router-outlet for enabling navigation to trending news stories and bookmarked news -
The
news-stories
component is responsible for fetching the trending news details from news api and load the details through news-story-card component8.a Should contain
newsList
property which stores the Array of type News fetched for trending news throughgetTrendingNews()
method of NewsService8.b Should contain
errorMessage
string property which stores the error messageUnable to access news server to fetch news
for Resource Not Found (404) error8.c For each element in
newsList
, dashboard component loads NewsStoryCard component with the news item details passed tonewsItem
property of this component8.d Should contain
errorMessage
string property which stores the error messageUnauthorized Access !!!
for Unauthorized access (403) error8.e For any other error the
errorMessage
string property should be assigned the error messageInternal Server Error, Please Try Again Later
-
The
news-story-card
component should display each news item assigned to it's input propertynewsItem
9.a This Component uses angular material
card
component to display newsItem.9.b Card contains image element for displaying news item image
9.c Card will display news item title inside it's mat-card-content section.
9.d The mat-card-actions section should contain button with
Read Later
text9.e When the
Read Later
button is clicked for a specific news item,addNews()
method of NewsService should be called and the value ofnewsItem
property should get saved to the db.json file located in server running at port 3000.9.f The
card
component should containconfirmationMessage
string property to display the messageThis News Article is Bookmarked
when the news item is stored successfully to db.json file9.g
card
component should containerrorMessage
string to display the error messages as mentioned below:Unable to access news server to add this news item
in event of error with status code 404Unauthorized Access !!!
in event of error with status code 403Internal Server Error, Please Try Again Later
in event of any other error
-
The
news-reader
component is responsible for fetching the bookmarked news details from db.json and load the details through NewsReaderCard component10.a Should contain
newsList
property which stores the Array of type News fetched for trending news throughgetBookmarkedNews()
method of NewsService10.b Should contain
errorMessage
string property which stores the error messageUnable to access news server to fetch news
for Resource Not Found (404) error andUnauthorized Access !!!
for Unauthorized access (403) error10.c For each element in
newsList
, dashboard component loadsnews-reader-card
component with the news item details passed tonewsItem
property of this component -
The
news-reader-card
component should display each news item assigned to it's input propertynewsItem
11.a This component displays image, description details of newsItem and link with news url
11.b News image is displayed using image element within div element defined with class name
.news-image
11.c News description is displayed using div element defined with class name
.news-description
11.d News URL is displayed using div element defined with class name
.news-url
11.e When the news url link is clicked the news page should open in new tab
-
The boilerplate code also contains code files for following Angular Services:
- NewsService
- AuthenticationService
- RouteService
-
NewsService
should manage the operations for news data through methods as listed below:13.a getTrendingNews() : fetches trending news using newsapi
13.b addNews(news:News) : accepts News type data and persists it to the server
13.c getBookmarkedNews() : fetches bookmarked news from server
-
AuthenticationService
talks to the server for user authentication and shall include methods -14.a authenticateUser() to get the user authenticated - accepts { username, password } and returns server response
14.b setBearerToken() to save user token in local storage with key bearerToken - accepts the token string
14.c getBearerToken() to fetch user token from local storage
14.d isUserAuthenticated() to validate authenticity of a user - accepts the token string and returns Promise of authenticated status of user
-
RouterService
to navigate user to available routes -15.a toDashboard() to navigate to dashboard route
15.b toLogin() to navigate to login route
-
The solution should contain 'can-activate` route guard to protect the routes to dashboard and its child components
-
The
footer
component should display the Copyright information and social media link icons (not functional) -
The news data should be modelled using
News
class as done with level-1 assignment -
Ensure following commands succeed in your local machine before submitting your code for Preliminary automated review as described below:
npm install
npm run build
npm run lint
npm run test
npm run e2e
- Open
https://hobbes-ust.stackroute.in/#/
and login into the platform - Under
Assignment repository
selectangular-news-level-2-assignment
, and branchmaster
- Under
Your solution repository
select your own repository and branch - Press
Submit
- Press
click here
for the feedback - Evaluation will take around 5-10 mins to complete after which you need to refresh your browser and get the updated status
- Watch out for your total score and detailed status on each test and eslint errors in the coloured blocks on the screen
- Fix failing test cases as well as eslint errors and re-submit your solution (you may skip any eslint errors reported in the provided spec files)