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.
- 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 Example: http://localhost:8080/news/account/5/role/PUBLISHER
- Set the read status for a single news
- Input
- accountId
- newsId
- Output
- Ok or error
PUT Request Example: http://localhost:8080/news/61008630-4b61-4b28-8594-a7f1febc2a33/account/5
PUT Request payload:
{
"readDate": "1980-04-09T10:15:30.00Z"
}
- Returns a picture for a single news
- Input
- News id
- Picture id
- rolles
- Output
- Picture as file
- Meta data
GET Request Example:
http://localhost:8080/news/2983ec85-b044-456f-a1c5-d151b2a1879c/picture/dc5e622c-ec31-47d9-87c7-466454fdecdf/role/reader
- Uploads a picture - possible only for users with role PUBLISHER
- Input
- Image as MultipartFile request parameter
- Output
- Ok or error
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
- 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
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
- Enter the following sql query to get all
usernameswith their assignedroles:
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;