articles-backend-app

Форк
0
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

6
This 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

16
Application must be implemented using Spring Data (JPA/Hibernate) layer for communication with DB.
17

18
SQL queries should not be used, JPA Repositories and Entities should be used instead.
19

20
Application should have no authentication.
21

22
Application will allow to create, update and delete Articles.
23

24
Application will have " **authors**" entity with the following properties:
25

26
- First Name
27
- Last Name
28

29
**Article** will have the following properties:
30

31
Editable 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

38
Non-Editable properties, updated automatically by Application:
39

40
- Date Created
41
- Date Updated
42

43

44
Application 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

52
The Article JSON Payload returned by endpoint(s) must contain all properties of Article listed above.
53

54
 Business 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

60
Any 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

63
The implementation must contain adequate unit tests to cover business requirements and edge cases such as missing arguments etc.
64

65
Application must build and produce an executable jar containing all dependencies.
66

67
The **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:
81
    mvn clean install
82

83
#### Build Docker image with application inside:
84
    docker build ./ -t articles-backend-app
85

86
## How to start application
87

88
#### Start application using Maven (vs in-memory DB H2):
89
    mvn 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

95
Or next way, using `dev` spring profile:
96

97
    mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=dev
98

99
#### Start application by running executable jar (vs in-memory DB H2):
100
    java -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

106
Or next way, using `dev` spring profile:
107

108
    java -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:
112
    docker-compose up
113

114
## Logs location
115

116
#### Check logs when start without Docker:
117
    less ./logs/spring-boot-logger.log
118

119
#### Check logs inside Docker container:
120
    docker exec -it articles-backend-app sh
121
    less /logs/spring-boot-logger.log
122

123
#### Swagger documentation situated here:
124
    http://localhost:8099/swagger-ui.html
125

126
#### New article addition:
127
    curl -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:
130
    curl -i http://localhost:8099/api/v1/articles/1
131

132
#### Update existing article:
133
    curl -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:
136
    curl -i http://localhost:8099/api/v1/articles
137

138
#### Get list of articles with pagination support:
139
    curl -i 'http://localhost:8099/api/v1/articles?size=2&page=4&sort=author.firstName,DESC'
140

141
#### Deletion of article:
142
    curl -i -X DELETE http://localhost:8099/api/v1/articles/1
143

144
#### Get existing author:
145
    curl -i http://localhost:8099/api/v1/authors/4
146

147
#### Get list of all authors:
148
    curl -i http://localhost:8099/api/v1/authors
149

150
## To run functional tests:
151

152
    cd func-test
153
    ./gradlew clean build
154

155
Check Spock report at `func-test/build/spock-reports/index.html`
156

157
## To run performance tests:
158

159
Gradle-based:
160

161
    cd load-test
162
    ./gradlew clean build
163
    java -Dlogback.configurationFile=logback-gatling.xml -jar ./build/libs/load-test-fat.jar -s=load.WebAppLoadSimulation -rf=./build/reports/gatling
164

165
Or Maven-based:
166

167
    cd load-test
168
    mvn clean install
169
    mvn gatling:test -Dlogback.configurationFile=logback-gatling.xml
170

171
Based on https://gatling.io/docs/3.0/extensions/maven_plugin
172

173
## To check Web-Sockets functionality:
174

175
Just enter in `http://localhost:8099` and click `Connect`.  
176
Check heartbeat logs in browser developer console.
177

178
## To taste ELK stack with logs providing by Filebeat:
179

180
Check [ELK README](elk-filebeat/README.MD)
181

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.