articles-backend-app
/
README.MD
180 строк · 6.4 Кб
1# Spring Boot backend app (Test task)
2[![Java CI](https://github.com/andrei-punko/articles-backend-app/actions/workflows/maven.yml/badge.svg)](https://github.com/andrei-punko/articles-backend-app/actions/workflows/maven.yml)
3[![Coverage](.github/badges/jacoco.svg)](https://github.com/andrei-punko/articles-backend-app/actions/workflows/maven.yml)
4[![Branches](.github/badges/branches.svg)](https://github.com/andrei-punko/articles-backend-app/actions/workflows/maven.yml)
5
6This should be purely a REST endpoints backend application without UI, but feel free to attach Swagger UI for convenience.
7
8_Build tool_: Maven
9
10_DB_: Postgres
11
12_Source Control:_ GitHub (public)
13
14_Application name:_ articles-backend-app
15
16Application must be implemented using Spring Data (JPA/Hibernate) layer for communication with DB.
17
18SQL queries should not be used, JPA Repositories and Entities should be used instead.
19
20Application should have no authentication.
21
22Application will allow to create, update and delete Articles.
23
24Application will have " **authors**" entity with the following properties:
25
26- First Name
27- Last Name
28
29**Article** will have the following properties:
30
31Editable properties (updatable via endpoints):
32
33- **Title** , text limited to 100 characters
34- **Summary** , text limited to 255 characters
35- **Text** , text with no specific limit
36- **Author:** relation with the **authors** table **. ONLY** updatable at creation. Should not be updatable after Article has been created
37
38Non-Editable properties, updated automatically by Application:
39
40- Date Created
41- Date Updated
42
43
44Application should expose REST endpoints that allow the following operations:
45
46- Create new Article
47- Update existing Article
48- Only one property at the time should be updatable.
49- Delete existing Article
50- Retrieve all articles in the system sorted by title
51
52The Article JSON Payload returned by endpoint(s) must contain all properties of Article listed above.
53
54Business Logic layer of the Application must enforce the following rules:
55
56- Non-editable properties cannot be updated/set via the create or update endpoints
57- Article cannot be created or update with empty Title or Text or Author Id
58- Article cannot be created with specified author id that does not exist in the **authors** table
59
60Any business logic constraint violation or any runtime error should return a HTTP 500 error with short description.
61(Guys confirmed that 400 errors could be used instead when needed as more appropriate)
62
63The implementation must contain adequate unit tests to cover business requirements and edge cases such as missing arguments etc.
64
65Application must build and produce an executable jar containing all dependencies.
66
67The **authors** table should not be updatable via endpoints. Feel free to populate it with an arbitrary data via SQL.
68
69## Additional functional
70- Operation for getting existing Article
71- Add pagination support for 'Retrieve all articles' operation
72- Operations for getting authors
73
74## Prerequisites
75- Maven 3
76- JDK 21
77
78## Build instructions
79
80#### Build application:
81mvn clean install
82
83#### Build Docker image with application inside:
84docker build ./ -t articles-backend-app
85
86## How to start application
87
88#### Start application using Maven (vs in-memory DB H2):
89mvn spring-boot:run -Dspring-boot.run.arguments="\
90--spring.datasource.url=jdbc:h2:mem:testdb \
91--spring.datasource.username=sa \
92--spring.datasource.password=password \
93--spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect"
94
95Or next way, using `dev` spring profile:
96
97mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=dev
98
99#### Start application by running executable jar (vs in-memory DB H2):
100java -jar target/articles-backend-app-0.0.1-SNAPSHOT.jar \
101--spring.datasource.url=jdbc:h2:mem:testdb \
102--spring.datasource.username=sa \
103--spring.datasource.password=password \
104--spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
105
106Or next way, using `dev` spring profile:
107
108java -jar target/articles-backend-app-0.0.1-SNAPSHOT.jar \
109--spring.profiles.active=dev
110
111#### Start two Docker containers: one with Postgres DB and another with application:
112docker-compose up
113
114## Logs location
115
116#### Check logs when start without Docker:
117less ./logs/spring-boot-logger.log
118
119#### Check logs inside Docker container:
120docker exec -it articles-backend-app sh
121less /logs/spring-boot-logger.log
122
123#### Swagger documentation situated here:
124http://localhost:8099/swagger-ui.html
125
126#### New article addition:
127curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "title": "Some tittle", "text": "Some text", "author": { "id": 1 } }' -X POST http://localhost:8099/api/v1/articles
128
129#### Get existing article:
130curl -i http://localhost:8099/api/v1/articles/1
131
132#### Update existing article:
133curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "title": "Another tittle" }' -X PATCH http://localhost:8099/api/v1/articles/2
134
135#### Get list of all articles:
136curl -i http://localhost:8099/api/v1/articles
137
138#### Get list of articles with pagination support:
139curl -i 'http://localhost:8099/api/v1/articles?size=2&page=4&sort=author.firstName,DESC'
140
141#### Deletion of article:
142curl -i -X DELETE http://localhost:8099/api/v1/articles/1
143
144#### Get existing author:
145curl -i http://localhost:8099/api/v1/authors/4
146
147#### Get list of all authors:
148curl -i http://localhost:8099/api/v1/authors
149
150## To run functional tests:
151
152cd func-test
153./gradlew clean build
154
155Check Spock report at `func-test/build/spock-reports/index.html`
156
157## To run performance tests:
158
159Gradle-based:
160
161cd load-test
162./gradlew clean build
163java -Dlogback.configurationFile=logback-gatling.xml -jar ./build/libs/load-test-fat.jar -s=load.WebAppLoadSimulation -rf=./build/reports/gatling
164
165Or Maven-based:
166
167cd load-test
168mvn clean install
169mvn gatling:test -Dlogback.configurationFile=logback-gatling.xml
170
171Based on https://gatling.io/docs/3.0/extensions/maven_plugin
172
173## To check Web-Sockets functionality:
174
175Just enter in `http://localhost:8099` and click `Connect`.
176Check heartbeat logs in browser developer console.
177
178## To taste ELK stack with logs providing by Filebeat:
179
180Check [ELK README](elk-filebeat/README.MD)
181