Record Aggregation Service is a micro-service to address some functionality which is useful to derive simplified summary statistics (mean, min, max) on a dataset.
- Add a new record to the dataset.
- Delete a new record from the dataset.
- fetch Summary Statistics(min, max, mean) for salary
- Entire dataset
- GroupBy department
- GroupBy department and subGroup by subDepartment
- Install docker on windows or mac or linux
Windows : https://docs.docker.com/desktop/install/windows-install/
Mac : https://docs.docker.com/desktop/install/mac-install/
Ubuntu : https://docs.docker.com/engine/install/ubuntu/
- Start docker engine
Steps to build a Docker image:
- Unzip zip file or clone repo
unzip aman-agrawal.zip
git clone https://github.com/amanagrawal3/record-aggregation-service.git
- Go to record-aggregation-service and build the image
docker build -t record-service .
This will take a few minutes.
- Run the image's default command, which should start everything up. The -p option forwards the container's port 8080 on the host. (Note that the host will actually be a guest if you are using boot2docker, so you may need to re-forward the port in VirtualBox.)
docker run -d -p 8080:8080 record-service
- Check if tomcat process is started/running
C:\Users\91800\Documents\projects\microservice> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a67896a970b record-service "java -jar app.jar -…" 46 seconds ago Up 45 seconds 0.0.0.0:8080->8080/tcp laughing_shannon
- Tail logs for debugging
docker logs 9a67896a970b(<container-id>) --follow
- Kill process
docker kill 9a67896a970b(<container-id>)
- Restart process
docker restart 9a67896a970b(<container-id>)
- Install Java17 on local system and set JAVA_HOME variable
- Install intellij or run throuh command line
Multiple steps:
- Execute the main method in the com.aman.Application class from your IDE.
- Alternatively you can use the Spring Boot Maven plugin like so:
mvn spring-boot:run
This API is used to register a new user who have admin access to perform CRUD on records.
curl --location --request POST 'http://localhost:8080/api/users/register' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "amantest",
"password": "test",
"device": "web",
"email": "[email protected]"
}'
{
"id": 12,
"username": "amantest",
"password": "$2a$10$.3hGrCtMxe5r1uTvzvqjIOG3ahT6gAOH.4tAGXNc2bpxv8doL9K1m",
"email": "[email protected]",
"lastPasswordReset": "2022-11-01T08:39:39.107+00:00",
"authorities": "ADMIN"
}
This API is used to fetch a valid token for a user to perform API operations. The response token need to be passed in X-AUTH-TOKEN header for all subsequent API's
curl --location --request POST 'http://localhost:8080/api/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "aman",
"password": "test",
"device": "web"
}
200 OK
{
"token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbWFuIiwiYXVkaWVuY2UiOiJ3ZWIiLCJjcmVhdGVkIjoxNjY3MjMzMjc2NTEzLCJleHAiOjE2Njc4MzgwNzZ9.-cfLvPrbDK1sxpJRCwQP0mk3LccZR4d6GY32FnvKhGvnHxsU4Kbg6iy42Idui68ywwdtnIHaz240a2EScwcJbA"
}
This API is used to add a new record in the system.
Fetch token for valid user mentioned above
curl --location --request POST 'http://localhost:8080/api/v1/records' \
--header 'X-AUTH-TOKEN: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbWFuIiwiYXVkaWVuY2UiOiJ3ZWIiLCJjcmVhdGVkIjoxNjY3MjMzMjc2NTEzLCJleHAiOjE2Njc4MzgwNzZ9.-cfLvPrbDK1sxpJRCwQP0mk3LccZR4d6GY32FnvKhGvnHxsU4Kbg6iy42Idui68ywwdtnIHaz240a2EScwcJbA' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "aman",
"salary": "12300",
"currency": "USD",
"department": "ENGINEERING",
"sub_department": "PLATFORM"
}'
201 Created
{
"id": 12,
"name": "aman",
"salary": "12300",
"currency": null,
"department": "ENGINEERING",
"subDepartment": "PLATFORM"
}
This API is used to delete a record from the system.
Fetch token for valid user mentioned above
curl --location --request DELETE 'http://localhost:8080/api/v1/records/8' \
--header 'X-AUTH-TOKEN: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbWFuIiwiYXVkaWVuY2UiOiJ3ZWIiLCJjcmVhdGVkIjoxNjY3MjQxMTc3MDU2LCJleHAiOjE2Njc4NDU5Nzd9.30YS8K0BysfiL3Ww4JetALDCOZIfDpkRHfrnQcsssEvxo0naxzyUPi54YLybjca03bGouLmk9VV-LMpyKaigAg' \
--data-raw ''
200 OK
This set of API's is used to fetch summary statistics of records.
Fetch token for valid user mentioned above
-
This API return summary statistics for all records
curl --location --request GET 'http://localhost:8080/api/v1/records/summary' \
--header 'X-AUTH-TOKEN: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbWFuIiwiYXVkaWVuY2UiOiJ3ZWIiLCJjcmVhdGVkIjoxNjY3MjMzMjc2NTEzLCJleHAiOjE2Njc4MzgwNzZ9.-cfLvPrbDK1sxpJRCwQP0mk3LccZR4d6GY32FnvKhGvnHxsU4Kbg6iy42Idui68ywwdtnIHaz240a2EScwcJbA'
200 OK
{
"summaryStatistics": [
{
"department": "ALL",
"subDepartment": "ALL",
"min": 30,
"max": 200000000,
"mean": 20066739,
"totalElements": 10
}
]
}
-
This API return summary statistics for all records group by department
curl --location --request GET 'http://localhost:8080/api/v1/records/summary/dept' \
--header 'X-AUTH-TOKEN: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbWFuIiwiYXVkaWVuY2UiOiJ3ZWIiLCJjcmVhdGVkIjoxNjY3MjMzMjc2NTEzLCJleHAiOjE2Njc4MzgwNzZ9.-cfLvPrbDK1sxpJRCwQP0mk3LccZR4d6GY32FnvKhGvnHxsU4Kbg6iy42Idui68ywwdtnIHaz240a2EScwcJbA'
200 OK
{{
"summaryStatistics": [
{
"department": "OPERATIONS",
"subDepartment": "ALL",
"min": 30,
"max": 70000,
"mean": 35015,
"totalElements": 2
},
{
"department": "ENGINEERING",
"subDepartment": "ALL",
"min": 30,
"max": 200000000,
"mean": 40053466,
"totalElements": 5
},
{
"department": "ADMINISTRATION",
"subDepartment": "ALL",
"min": 30,
"max": 30,
"mean": 30,
"totalElements": 1
},
{
"department": "BANKING",
"subDepartment": "ALL",
"min": 90000,
"max": 240000,
"mean": 165000,
"totalElements": 2
}
]
}
-
This API return summary statistics for all records group by department and subgroup by subDepartment
curl --location --request GET 'http://localhost:8080/api/v1/records/summary/deptSubdept' \
--header 'X-AUTH-TOKEN: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhbWFuIiwiYXVkaWVuY2UiOiJ3ZWIiLCJjcmVhdGVkIjoxNjY3MjMzMjc2NTEzLCJleHAiOjE2Njc4MzgwNzZ9.-cfLvPrbDK1sxpJRCwQP0mk3LccZR4d6GY32FnvKhGvnHxsU4Kbg6iy42Idui68ywwdtnIHaz240a2EScwcJbA'
200 OK
{
"summaryStatistics": [
{
"department": "OPERATIONS",
"subDepartment": "CUSTOMER_ONBOARDING",
"min": 30,
"max": 70000,
"mean": 35015,
"totalElements": 2
},
{
"department": "ENGINEERING",
"subDepartment": "PLATFORM",
"min": 30,
"max": 200000000,
"mean": 40053466,
"totalElements": 5
},
{
"department": "ADMINISTRATION",
"subDepartment": "AGRICULTURE",
"min": 30,
"max": 30,
"mean": 30,
"totalElements": 1
},
{
"department": "BANKING",
"subDepartment": "LOAN",
"min": 90000,
"max": 90000,
"mean": 90000,
"totalElements": 1
},
{
"department": "BANKING",
"subDepartment": "PLATFORM",
"min": 240000,
"max": 240000,
"mean": 240000,
"totalElements": 1
}
]
}