Description
It's time to plan the architecture of our service. A good plan is 50% of the result. To begin with, we will determine the functions of our service, group them, and plan the appropriate endpoints following the principles of the REST API:
- Authentication
POST api/auth/signupallows the user to register on the service;POST api/auth/changepasschanges a user password.
- Business functionality
GET api/empl/paymentgives access to the employee's payrolls;POST api/acct/paymentsuploads payrolls;PUT api/acct/paymentsupdates payment information.
- Service functionality
PUT api/admin/user/rolechanges user roles;DELETE api/admin/userdeletes a user;GET api/admin/userdisplays information about all users.
To ensure the security of our service, we will also plan the distribution of roles:
| Anonymous | User | Accountant | Administrator | |
POST api/auth/signup |
+ | + | + | + |
POST api/auth/changepass |
+ | + | + | |
GET api/empl/payment |
- | + | + | - |
POST api/acct/payments |
- | - | + | - |
PUT api/acct/payments |
- | - | + | - |
GET api/admin/user |
- | - | - | + |
DELETE api/admin/user |
- | - | - | + |
PUT api/admin/user/role |
- | - | - | + |
Later, we will reveal the purpose of the roles.
Objectives
In this stage, our goal is to run a SpringBoot web application for our service and test it with one endpoint.
Create and run a SpringBoot application on the 28852 port;
Create the POST api/auth/signup endpoint that accepts data in the JSON format:
{
"name": "<String value, not empty>",
"lastname": "<String value, not empty>",
"email": "<String value, not empty>",
"password": "<String value, not empty>"
}
It should return a response in the JSON format (without the password field):
{
"name": "<String value>",
"lastname": "<String value>",
"email": "<String value>"
}
If the status is HTTP OK (200), then all fields are correct. If it's HTTP Bad Request (400), then something is wrong. Our service must accept only corporate emails that end with @acme.com. In this stage, we do not check the authentication, so the password field may contain anything (but not empty).
Examples
Example 1: a POST request for api/auth/signup
Request body:
{
"name": "John",
"lastname": "Doe",
"email": "[email protected]",
"password": "secret"
}
Response: 200 OK
Response body:
{
"name": "John",
"lastname": "Doe",
"email": "[email protected]",
}
Example 2: a POST request for api/auth/signup
Request body:
{
"lastname": "Doe",
"email": "[email protected]",
"password": "secret"
}
Response: 400 Bad Request
Response body:
{
"timestamp": "<date>",
"status": 400,
"error": "Bad Request",
"path": "/api/auth/signup"
}
Example 3: a POST request for api/auth/signup
Request body:
{
"name": "John",
"lastname": "Doe",
"email": "[email protected]",
"password": "secret"
}
Response: 400 Bad Request
Response body:
{
"timestamp": "<date>",
"status": 400,
"error": "Bad Request",
"path": "/api/auth/signup"
}