Skip to content

pramodaya/Article-List

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARTICLE LIST

SPRING | REST-API | SPRING-SECURITY | POSTGRESQL

QUESTION

Create a secured restful API to create and list articles. To create an article the user should provide a title, author, content and the date published. All the properties are mandatory. The title should not exceed 100 characters and the publishing date should be provided in ISO 8601 format. The endpoint for the article list should return paginated results.

Additionally, you are required to develop an endpoint for statistics that would be accessible only by admins. The endpoint should return the count of published articles on daily bases for the last 7 days.

ANSWER

1 APIs are restricted with the spring security.

2 Authorized user's can create Articles.

- Postgress database table 'article'

Screenshot 2022-12-28 at 01 11 35

This application contains 3 api's

Use the following credentials to log in ( 2 roles | Only the user role 'ADMIN' can access '/statistic' end point) Check application.properties file

User

  • username: "pramodaya"
  • password: "password"

Admin

  • username: "john"
  • password: "password"

- Get article list - Paginated

Method - GET http://localhost:8080/api/v1/article This will return follwowing result with success code 200.

Screenshot 2023-01-08 at 20 08 58

- Add article

Method - POST http://localhost:8080/api/v1/article/add This will return following status code 200 if succeeded.

Screenshot 2022-12-31 at 01 16 46

- Get statistics

Method - GET http://localhost:8080/api/v1/article/statistic This will return following result if the user is not an admin:

Screenshot 2022-12-28 at 01 01 32

If the validation is succeeded with spring security it'll give following result:

Screenshot 2022-12-28 at 01 29 45

Screenshot 2022-12-31 at 01 17 11

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages