elixir 1.10.0
erlang 22.2.4
phoenix 1.4.12
postgresql 11.6
- How to install erlang with asdf asdf erlang
- How to install elixir with asdf asdf elixir
- How to install Phoenix documentation
# for development/demonstratoin purpose only!
psql user: rocker_user
psql password: rocker
user must be allowed to create databases and tables
$ git clone [email protected]:lyo5ha/rocker_assignment.git
$ mix deps.get
$ mix ecto.create
$ mix ecto.migrate
$ mix phx.start
Server will be available on localhost:4000/
For demonstration purpose assumed that "amount" field is always in integer format and represents loan amount in cents.
Content-Type: application/json
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "loan",
"amount": 3056,
"status": "NEW",
"user": {
"name": "Jhon Jhonson",
"phone": "+3827777777",
"email": "[email protected]"
}
}
}
HTTP/1.1 200 OK
Content-Type: application/json
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "loan",
"id": "101",
"status": "ACCEPTED",
"rate": 5.5
}
}
HTTP/1.1 200 OK
Content-Type: application/json
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "loan",
"id": "101",
"status": "REJECTED",
"rate": null
}
}
HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json
{
"jsonapi": {
"version": "1.0"
},
"errors": [
{
"status": "422",
"source": "/api/v1/loan/new",
"title": "Invalid Attribute",
"detail": "Invalid email address"
}
]
}
HTTP/1.1 200 OK
Content-Type: application/json
{
"jsonapi": {
"version": "1.0"
},
"data": [
{
"type": "loan",
"amount": "3056",
"id": "101",
"user": {
"name": "Jhon Jhonson",
"phone": "+3827777777",
"email": "[email protected]"
},
"status": "ACCEPTED",
"rate": 5.5
},
{
"type": "loan",
"amount": "4057",
"id": "102",
"user": {
"name": "Jack Jackson",
"phone": "+3829999999",
"email": "[email protected]"
},
"status": "ACCEPTED",
"rate": 5.3
},
{
"type": "loan",
"amount": "5059",
"id": "103",
"user": {
"name": "Bill Billson",
"phone": "+38233333333",
"email": "[email protected]"
},
"status": "REJECTED"
}
]
}
Fields should be present and be in correct format:
- name
- phone
One email should be connected with one name.
There is a implementation of Solovay–Strassen primality test, which is probabilistic. Chance of wrong answer with 30 iterations will be 1 of 1073741824, which could be considered as sufficient. Running time will be O(k·log^3 n), k=30.
Highest loan amount form all requests keeps in Genserver in-memory. When application restarts, this highest amount resets to 0. Then first loan amount writes as highest.
FooBank, a fictional financial services company, based in Athens, Greece, earns its money by offering loans to people who need to finance expensive purchases.
Their most recent product is a mobile app where people can apply for loans. Unfortunately the agency brought in completely forgot to build a back-end for the service and for this reason you have been asked to build one.
Please email a link to a code repository or send a .zip/.tar file with the code to [email protected] when you feel you have a good solution.
Creating loan applications
Customer's will apply by sending an HTTP request containing;
- The requested loan amount
- The name of the person applying for the loan
- Their phone number
- Their email
As a response the app receives a status indicating if the application was rejected or accepted and the rate if the application was accepted
{ "status": "REJECTED|ACCEPTED", "rate": 5.5 }
To the decide if a loan is to be accepted or rejected the bank's credit regulation is applied.
-
If a loan application has a lower “Requested loan amount” than any of the previous loan applications, then the loan is rejected.
-
If a loan application has a Requested loan amount which is a prime number, then a loan offer is granted with interest rate of 9.99%
-
Otherwise, a loan is offered with random interest rate between 4% and 12%.
Listing loan applications
Calling this endpoint should return a list of all loans, their statuses and the interest rate offered (if any).