Skip to content

metodi-velev/newsservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST-based microservice called Newsservice

REST-based microservice - Newsservice using Spring Boot, Spring Data JPA, Spring Security, Java8, Maven, MapStruct, Lombok, Bean Validation API, JUnit 5, Mockito and H2 in-memory DB.


Requests


1. GET actual news for a single role/accountID


  • Returns all news for single role/account ID back, which are new and have not been read yet. New news are defined as 1 day old news relative to the current time.
  • Input
    • accountId
    • rolles
  • Output
    • news (0 bis x)
GET Request in form: http://localhost:8080/news/account/{accountId}/role/{role}
GET Request Example: http://localhost:8080/news/account/5/role/PUBLISHER

2. Set read status


  • Set the read status for a single news
  • Input
    • accountId
    • newsId
  • Output
    • Ok or error
PUT Request in form: http://localhost:8080/news/{newsId}/account/{accountId}
PUT Request Example: http://localhost:8080/news/61008630-4b61-4b28-8594-a7f1febc2a33/account/5
PUT Request payload:
{ "readDate": "1980-04-09T10:15:30.00Z" }

3. GET picture


  • Returns a picture for a single news
  • Input
    • News id
    • Picture id
    • rolles
  • Output
    • Picture as file
    • Meta data
GET Request in form: http://localhost:8080/news/{newsId}/picture/{pictureId}/role/{role}
GET Request Example:
http://localhost:8080/news/2983ec85-b044-456f-a1c5-d151b2a1879c/picture/dc5e622c-ec31-47d9-87c7-466454fdecdf/role/reader

4. POST i.e. upload a picture


  • Uploads a picture - possible only for users with role PUBLISHER
  • Input
    • Image as MultipartFile request parameter
  • Output
    • Ok or error
POST Request in form: http://localhost:8080/picture/upload
POST Request Example: http://localhost:8080/picture/upload
Content-Type: multipart/form-data
Request parameter: image
Payload: image = Photo.jpg
The payload could be entered as key-value pair Key=image, Value=Photo.jpg in Postman in the body tab under form-data

5. CRUD REST endpoints for News resource


6. CRUD REST endpoints for Role resource


Description of the Roles


  • Admin: He has the right to see all contents and edit and delete all contents

  • Reader: He has the right to read all titles and see all photos in the public area

  • Publisher: he can create news and edit or delete of the contents he had created

Every user has own account, which has an unique ID. Every user has a specific role.
News contains simple text or/and photo.
All of the non-public endpoints are secured using basic authentication i.e. using base64 encoded username:password as Authorization header in the http request. For example for the user lisa: Authorization=Basic bGlzYTpsaXNh

H2-Console available at http://localhost:8080/h2-console, no login required

  • Enter the following sql query to get all usernames with their assigned roles:
SELECT u.username, r.role_name FROM "user" u
    inner join user_role ur
        on u.id = ur.user_id
    inner join role r
        on ur.role_id = r.id;
  • SQL query to retrieve all news articles along with their associated photos, read status information and corresponding usernames:
SELECT n.title, p.photo_name, r.account_id, u.username
    FROM NEWS n
         LEFT JOIN PHOTO p ON n.photo_id = p.id
         LEFT JOIN READ_STATUS r ON n.read_status_id = r.id
         LEFT JOIN "user" u ON r.account_id =u.id;

About

REST-based microservice - Newsservice using Spring Boot, Spring Data JPA, Spring Security, Java8, Maven, MapStruct, Lombok, Bean Validation API, JUnit 5, Mockito and H2 in-memory DB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages