Skip to content

Commit

Permalink
Added some information about /you endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Feb 27, 2017
1 parent faf28a5 commit 6e114bf
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/restapi/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Endpoints
campaigns
loanrequests
users
you
6 changes: 6 additions & 0 deletions docs/restapi/you.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
===
You
===

.. automodule:: market.restapi.you_endpoint
:members:
2 changes: 1 addition & 1 deletion market/restapi/users_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(self, market_community, pub_key):

def render_GET(self, request):
"""
.. http:get:: /user/(string: user_id)
.. http:get:: /user/(string: user_id)/profile
A GET request to this endpoint returns information about a profile of a user.
Expand Down
81 changes: 81 additions & 0 deletions market/restapi/you_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ def __init__(self, market_community):
self.market_community = market_community

def render_GET(self, request):
"""
.. http:get:: /user/(string: user_id)/profile
A GET request to this endpoint returns information about your profile. Returns 404 if no profile is created.
**Example request**:
.. sourcecode:: none
curl -X GET http://localhost:8085/you/profile
**Example response**:
.. sourcecode:: javascript
{
"profile": {
"type": "investor",
"first_name": "Piet",
"last_name": "Tester",
"email": "piettester@gmail.com",
"iban": "NL90RABO0759395830",
"phone_number": "06685985936"
}
}
"""
you = self.market_community.data_manager.you

if not you.profile:
Expand All @@ -48,6 +74,35 @@ def render_GET(self, request):
return json.dumps({"profile": you.profile.to_dictionary()})

def render_PUT(self, request):
"""
.. http:put:: /you/profile
A PUT request to this endpoint will create a profile. Various parameters are required:
- role: the role of the user, can be BORROWER or INVESTOR
- first_name: the first name of the user
- last_name: the last name of the user
- email: the email address of the user
- iban: the iban number of the user
- phone_number: the phone number of the user
If the user is a borrower, additional information is required:
- current_postal_code: the postal code of the current address of the borrower
- current_house_number: the house number of the current address of the borrower
- current_address: the current address of the borrower
- document_list: an array with base64-encoded files
**Example request**:
.. sourcecode:: none
curl -X PUT http://localhost:8085/you/profile --data "role=BORROWER&first_name=..."
**Example response**:
.. sourcecode:: javascript
{"success": True}
"""
parameters = http.parse_qs(request.content.read(), 1)
if not get_param(parameters, 'role'):
request.setResponseCode(http.BAD_REQUEST)
Expand Down Expand Up @@ -101,6 +156,32 @@ def __init__(self, market_community):
self.market_community = market_community

def render_GET(self, request):
"""
.. http:get:: /you/investments
A GET request to this endpoint returns a list of investments that you have made.
**Example request**:
.. sourcecode:: none
curl -X GET http://localhost:8085/you/investments
**Example response**:
.. sourcecode:: javascript
{
"investments": [{
"investor_id": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
"amount": 9000,
"duration": 24,
"interest_rate": 4.9,
"mortgage_id": "8593AB_89",
"status": "ACCEPTED"
}, ...]
}
"""
you = self.market_community.data_manager.you
if not you.role == Role.INVESTOR:
request.setResponseCode(http.BAD_REQUEST)
Expand Down

0 comments on commit 6e114bf

Please sign in to comment.