Technical challenge to Engineering Backend position
-
Ruby version:
2.6.3
-
Rails version:
5.2.4.2
-
Database:
Postgres
-
username:
postgres
-
password:
postgres
-
Obs.: This credentials can be changend in
config/database.yml
-
- Clone the repository
- Run
bundle
- Run
rails db:create db:migrate db:seed
- Run
rspec ./spec
- Run
rails server
- Open
http://localhost:3000/api-docs/index.html
- Run
rails server
- Read API Documentation
-
Open new bank account:
- Create new client account:
POST /clients
- Log in with client account:
POST /auth/login
- Open bank account:
POST /bank_account
- Create new client account:
-
Update bank account data:
- Log in with client account:
POST /auth/login
- Update bank account:
POST /bank_account
- Log in with client account:
-
Listing all guests:
- Log in with client account:
POST /auth/login
- Listing yours guests:
GET /clients/my_indications
- Log in with client account:
- Rack Cors
- Rack Attack
- JWT
- Symmetric Encryption
- Rails Credentials
-
Why use only Client Table instead of new Bank Account Table with has_one association?
- Because is less code.
- It results in fewer SQL statements.
- It executes faster the SELECT queries.
- It avoids.
- If necessary that Client has many account, this association will be refactored
-
Create Model Bank Account Not-ActiveRecord
- Because business layer responsibilities are better isolated.
- Using ActiveModel::Model module to use some good resources of Rails, as validation.
-
Proposal and purpose: Services objects aim to minimize high coupling. Just extract important use cases from Rails models. You are more free to model your use cases according to the context.
-
Basic funcionality:
Every service must have 4 basic implementations: (based in a book: Confident Ruby - Avdi Grimm)
- Collecting and validate input
- Performing works
- Delivering output
- Handling failures
- Details:
-
Collecting and validate input:
-
I implemented the module to be used as a mixin called Validable. This module will perform a class contract validation after the initialization of each service.
-
Class Contract Validation must be created with same name of the use case, but in
service_contracts
directory. -
To implement Class Contract Validation, you must be use the gem DryValidation. It is a excelent gem to validate yours classes.
-
-
Performing works:
-
All services contains the
call
method. It a responsable to execute business validations and all logic of the use case. -
Business Validation: read about Specification Pattern
-
Use Cases: read about Use Case
-
It will be necessary implement 2 private methods used in
call
:- #execute_specifications
- #execute_use_case
-
-
Delivering output
- Implement
#use_case_response
private methods - Used to format response of the use case
- Implement
-
Handling failures
- Dry Validation helps to handle errors
- Don't forget to handle exceptions
-
Exceptions
- It was created a new directory to save all exceptions class
- Using I18n to tranlate messages
- Use
:around_action
in ApiController to handle with all exceptions of the API
-
Types
- It was created a new directory to save all custom types.
- Used in ActiveRecord API
-
Custom Validation
- It was created a new directory to save all custom validations
- Created CPFValidator and EmailValidator