This is a microservice for managing users in a clean, modular architecture. It includes basic CRUD functionality for users, along with testing that achieves a 98% coverage.
- Docker
- Docker Compose
To get started, first clone the repository and install the necessary dependencies.
git clone https://github.com/your-repo/user-service.git
cd user-serviceStart the application using Docker Compose:
docker-compose up --buildThis will build and start the services defined in docker-compose.yml. The service will be available at http://localhost:3000.
Once the service is running, you can interact with the API via curl, Postman, or any other HTTP client.
Example of creating a user:
curl -X POST http://localhost:3000/api/v1/users \
-H "Content-Type: application/json" \
-d '{
"user": {
"email": "test@example.com",
"password": "password123",
"role": "client",
"name": "John",
"lastname": "Doe",
"phone": "1234567890"
}
}'Request:
{
"user": {
"email": "test@example.com",
"password": "password123",
"role": "client",
"name": "John",
"lastname": "Doe",
"phone": "1234567890"
}
}Response:
- 201 Created: Returns the newly created user.
- 422 Unprocessable Entity: Returns validation errors if the request is invalid.
Retrieves the details of a user by ID.
Response:
- 200 OK: Returns the user details.
- 404 Not Found: If the user does not exist.
Updates an existing user.
Request:
{
"user": {
"name": "Jane"
}
}Response:
- 200 OK: Returns the updated user.
- 404 Not Found: If the user does not exist.
- 422 Unprocessable Entity: Returns validation errors if the request is invalid.
Deletes a user by ID.
Response:
- 204 No Content: If the user was successfully deleted.
- 404 Not Found: If the user does not exist.
Retrieves the details of a user by ID.
Response:
- 200 OK: Returns the users.
The project includes unit tests for services, repositories, and controllers. The test coverage is currently at 98%.
To run the tests, use the following command:
docker-compose run app bundle exec rspecThe project follows a clean architecture, with separate layers for controllers, services, repositories, and models.
app/
├── controllers/
│ └── api/
│ └── v1/
│ └── users_controller.rb
├── models/
│ └── user.rb
├── repositories/
│ └── users/
│ └── user_repository.rb
├── services/
│ └── users/
│ ├── create_user.rb
│ ├── update_user.rb
│ ├── show_user.rb
│ ├── destroy_user.rb
│ └── list_users.rb
└── serializers/
└── user_serializer.rb
Each component is responsible for a specific part of the application logic, ensuring that the project remains scalable and easy to maintain.
This project is open-source and available under the [MIT License](LICENSE).