The recommended timeline for the whole module is 2 weeks.
- Migrate your solution prepared in Architecture advanced module to Spring.
- Support CRUD operations for Author as well.
You are provided with the basic interfaces for repository
, service
and controller
layers:
com.mjc.school.repository.model.BaseEntity
com.mjc.school.repository.BaseRepository
com.mjc.school.service.BaseService
com.mjc.school.controller.BaseController
Use them as base point for your solution. Do not change or delete them.
Domain objects are represented by the following diagram
and have the following requirements:
- All fields for News (except
authorId
) and Author are required. - Id fields should be auto generated.
- News title field should have length from 5 to 30.
- News content field should have length from 5 to 255.
- News and Author createdDate, lastUpdatedDate fields should be in ISO 8601 format. Example: 2018-08-29T06:12:15.156. More discussion here: stackoverflow: how to get iso 8601 .
- News authorId field should be mapped to the author datasource.
- Author name field should have length from 3 to 15.
As well as in the Architecture advanced module data source should be generated automatically at runtime and saved in
array datasource by reading files from the resources
folder in the repository module (database emulation).
For example: author.txt
, content.txt
which should contain the required data.
The system should expose CRUD operations for News and Author from the main module in the root project:
-
Create News - fill only title, content, authorId and return created news.
-
Create Author - fill only name and return created author.
-
Get All News – return list of news.
-
Get All Authors – return list of authors.
-
Get News by id – return news by provided id.
-
Get Author by id – return author by provided id.
-
Update News – update only title, content, authorId by provided news id and return updated news.
-
Update Author – update only name by provided author id and return updated author.
-
Delete News – delete news by provided news id and return boolean value.
-
Delete Author – delete author by provided author id and return boolean value. When deleting author you could choose 2 options:
- set
authorId
field for corresponding news tonull
. - remove corresponding news.
Think of declarative way of choosing appropriate option instead of imperative way:
Imperative way: in
delete author
method load all news related to that author and either set theirauthorId
field tonull
or remove them.Declarative way: use custom annotation (e.g.
@OnDelete
) with its handler (could be implemented via Aspects). - set
As well as in the Architecture advanced module all returned and received data should be like DTO type.
The mapping between the dto
and the model (domain object)
should be done at the service layer using any library. For
example: Mapstruct, Modelmapper.
Validate all the input according to the rules described in DataSource. It can be done by directly implementing all validations in business logic code or declaratively, e.g. via custom annotations.
To support your custom annotations and perform validation outside of business logic code you can use e.g. Aspects.
- Use Command pattern to call operations
- Instead of direct call module-web from module-main organize communication between module-web and module-main by custom annotations @CommandHandler, @CommandBody and @CommandParam placed in controllers
- Cover service layer with JUnit tests.
- Code should be clean and should not contain any “developer-purpose” constructions.
- App should be designed and written with respect to OOD and SOLID principles.
- Clear layered structure should be used with responsibilities of each application layer defined.
- All business logic should be written in the module-service: mapping
model
todto
and vice versa, validation, etc. - All the news and author data should be generated automatically in the module-repository with the amount of 20 and
stored in array (database emulation) when the application is running. Reading default data for news and author
generation should be from files in
resources
package, e.g.author.txt
,content.txt
andnews.txt
. - Module-web and module-service should accept and return
dto
objects. - Module-repository should accept and return
model
objects. - Convenient error/exception should be implemented: all errors should be meaningful. Errors should
contain
errorMessage
anderrorCode
, whereerrorCode
is your custom code. - Application should be tested and pass all tests suites.
- Java 17 should be used.
- Gradle. Multi-module project. Spring.
- Application packages root:
com.mjc.school
. - Java Code Convention is mandatory.
If you have finished task and would like to see the original solution of it written by our experts, write in #stage-3 channel about it. Access will be provided.