This service was built with the goal of implementing a single endpoint (/agggregate
) that is responsible to receive
a POST request with a list of numbers to aggregate, based on the sector and prefix. The prefixes are kept in a text
file. The sector, where the phone is related, is get through an external API. This API accepts GET requests to endpoints
that follow the /sector/:number
pattern where :number
is a phone number. Responses for valid numbers will return a
200
http status, and include the number canonically formatted as well as its sector. They comply with the schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"items": {
"type": "string",
"properties": {
"number": {
"type": "string"
},
"sector": {
"type": "string"
}
}
},
"required": ["number", "sector"]
}
In the topics below, we describe the process, from the moment a request is made:
- For each number on the list:
- Check number is validated (through a regex expression)
- If valid we try to get the prefix, otherwise go back to (1)
- If prefix exists we check if the number is in redis cache, otherwise go back to (1)
- If number is in redis cache we go back to (1), otherwise we request the number sector to the phone sector api
- We aggregate the response based on the prefix with the sectors and number of phones per a sector.
Given a list:
["+1983248", "001382355", "+147 8192", "+4439877"]
The expected result is:
{
"1": {
"Technology": 2,
"Clothing": 1
},
"44": {
"Banking": 1
}
}
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
The application can be packaged using:
./mvnw package
It produces the phone-sector-1.0.0-SNAPSHOT-runner.jar
file in the /target
directory.
The docker environment needs the following steps, to be created:
- Build the package:
mvn package
- Launch the containers:
docker-compose up web