Skip to content

Commit

Permalink
(#15) - Update the home page to include some useful info on the REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
braboj committed Aug 11, 2024
1 parent 0155763 commit 925f593
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,35 @@

@api_view(http_method_names=["GET"])
def home(request):
return HttpResponse("Hello, world!")

html = """<html>
<head>
<title>Profiles</title>
</head>
<body>
<h1>Profiles</h1>
<p>Author: Branimir Georgiev</p>
<p>
This is a simple API that allows you to manage profiles and
calculate costs for each profile.
</p>
<p>Endpoints:</p>
<ul>
<li>GET /profiles/overview/</li>
<li>GET /profiles/overview/{day_id}/</li>
<li>GET /profiles/{profile_id}/overview/{day_id}/</li>
<li>GET /profiles/{profile_id}/days/{day_id}/</li>
<li>GET /profiles/logs/</li>
<li>GET /profiles/config/</li>
</ul>
"""

return HttpResponse(html)


@api_view(http_method_names=["GET"])
Expand All @@ -30,7 +58,7 @@ def get_overall_overview(request):

# Something went wrong
except Exception as e:
return HttpResponse(status=404, content=str(e))
return HttpResponse(status=500, content=str(e))

# Everything went well
else:
Expand Down Expand Up @@ -60,7 +88,7 @@ def get_day_overview(request, day_id):

# Something went wrong
except Exception as e:
return HttpResponse(status=404, content=str(e))
return HttpResponse(status=500, content=str(e))

# Everything went well
else:
Expand Down Expand Up @@ -93,7 +121,7 @@ def get_profile_overview(request, profile_id, day_id):

# Something went wrong
except Exception as e:
return HttpResponse(status=404, content=str(e))
return HttpResponse(status=500, content=str(e))

# Everything went well
else:
Expand Down Expand Up @@ -126,7 +154,7 @@ def get_day_data(request, profile_id, day_id):

# Something went wrong
except Exception as e:
return HttpResponse(status=404, content=str(e))
return HttpResponse(status=500, content=str(e))

# Everything went well
else:
Expand All @@ -146,11 +174,18 @@ def get_logs(request):
# Get the app
app = apps.get_app_config("profiles")

# Get the logs from the manager
logs = app.manager.get_logs()
try:
# Get the logs from the manager
logs = app.manager.get_logs()

# Something went wrong
except Exception as e:
return HttpResponse(status=500, content=str(e))

# Return the logs
return JsonResponse(logs)
# Everything went well
else:
# Return the logs
return JsonResponse(logs)


@api_view(http_method_names=["POST", "GET"])
Expand Down Expand Up @@ -182,7 +217,7 @@ def handle_config(request):
app.config.set_params(request.data)

# Get the new configuration data
data = app.config.get_params()
data = {"status": "success"}

# Something went wrong
except Exception as e:
Expand Down

0 comments on commit 925f593

Please sign in to comment.