CoinCap Code Challenge is a project developed to address a coding challenge that requires the use of Java 17, Spring Boot 3, an SQL database, and data sourced from CoinCap API.
CoinCap Code Challenge is a Spring Boot application and uses a MySQL database.
The following image shows the Entity Relationship Diagram for the CoinCap Code Challenge application.
Make sure that you have the prerequisites installed on your development machine and then clone this repository with the following command:
git clone git@github.com:EnduranceCode/coincap-challenge.gitLogin into the MySQL server, replace the {LABEL} in the below command as appropriate and then execute it to create the CoinCap Code Challenge database.
CREATE DATABASE {DATABASE_NAME} CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;Label Definition
- {DATABASE_NAME} : The name chosen for the new database;
To create a user for the CoinCap Code Challenge database management, replace the {LABELS} in the below command as appropriate and then execute it.
CREATE USER '{USERNAME}'@'localhost' IDENTIFIED WITH caching_sha2_password BY '{PASSWORD}';Labels Definition
- {USERNAME} : The new account name in the MySQL Server;
- {PASSWORD} : The password of the new account in the MySQL Server.
To grant the necessary privileges to the CoinCap Code Challenge database user, replace the {LABELS} in the below command as appropriate and then execute it.
GRANT ALL PRIVILEGES ON {DATABASE_NAME}.* TO '{USERNAME}'@'localhost';Labels Definition
- {DATABASE_NAME} : The database where the MySQL user will be granted privileges;
- {USERNAME} : The account name in the MySQL Server to whom the privileges will be assigned.
To configure the CoinCap Code Challenge access to the database, take the following steps:
- Copy the file
application-secure-TEMPLATE.yml, located in theresourcesfolder and rename it toapplication-secure.yaml; - Replace the {DATABASE_NAME} placeholder with the CoinCap Code Challenge database name;
- Replace the {DATABASE_USER} placeholder with the CoinCap Code Challenge database user's username;
- Replace the {DATABASE_NAME} placeholder with the CoinCap Code Challengedatabase user's password;
- Delete the comments block, at the top of the file, that contains these instructions;
- Add the comment 'DO NOT COMMIT THIS FILE!' to the first line of the file.
The file DATABASE.md, stored in the folder
src/main/resources/db/, documents the process to manage the CoinCap Code Challenge
database migrations.
To run the CoinCap Code Challenge application, execute the following command:
./mvnw spring-boot:runThe application will start and be accessible at the following URL:
As it is out of scope, the CoinCap Code Challenge application doesn't provide any CRUD operations for the User resource.
The CoinCap Code Challenge application exposes the following endpoints:
- GET
/v1/users/{userId}/wallets/{walletId}: Retrieves the wallet information for the given user with the specified wallet identifier; - POST
/v1/users/{userId}/wallets/{walletId}/assets: Inserts a new asset into the user's wallet; - PUT
/v1/users/{userId}/wallets/{walletId}/assets/{symbol}: Increments the quantity of a specified asset in the user's wallet; - POST
/v1//v1/wallet-evaluation/: Evaluates a wallet's performance based on a list of input tokens and their average buy values
An authentication mechanism is out of scope for this project, so the CoinCap Code Challenge application doesn't provide such mechanism. Nonetheless, the application validates if the given user owns the given wallet.
The application database is pre-populated with the following data:
- User : A user with the identifier
1and the nicknameEnduranceCode; - User : A user with the identifier
2and the nicknameEnduranceTrio; - Wallet : A wallet with the identifier
1owned by the user with the identifier1. - Wallet : A wallet with the identifier
2owned by the user with the identifier2. - Asset : Two assets, one with the symbol
BTCand the other with the symbolETHbelonging to wallet with id1. - Asset : Two assets, one with the symbol
BTCand the other with the symbolETHbelonging to wallet with id2.
The CoinCap Code Challenge application includes a @Scheduled job that automatically updates token prices
at regular intervals. This job fetches the latest prices from the CoinCap API
and updates the database to reflect the current market value.
The update frequency is configurable via the application-secure.yaml file
located at src/main/resources/application.yml. The configuration key
is app.scheduler.token.update-interval, and the value specifies the interval in milliseconds between updates.
The following YAML snippet shows the default configuration that has an update interval of 30 minutes:
app:
scheduler:
token:
update-interval: 1800000The CoinCap Code Challenge application provides a Swagger UI for API documentation and testing. It's available at the following URL:
CoinCap Code Challenge is licensed under the terms of MIT License.
