diff --git a/backend/api-docs.txt b/backend/api-docs.txt index bb38c4c..7af4ae6 100644 --- a/backend/api-docs.txt +++ b/backend/api-docs.txt @@ -24,7 +24,52 @@ Login:- 403 Forbidden:- Content Type:- text/plain Note:- user_name or password is wrong, can display the response data to user. - Data:- What is wrong will be mentioned + Data:- What is wrong will be mentioned, text that can be displayed on the screen. + + Example:- + formData = new FormData(); + formData.append('name', 'John'); + formData.append('password', 'John123'); + fetch( + "/login", + { + body: formData, + method: "post" + } + ); + + This will give a response status 200 with no data if login is done. + This will return a 403 if the user gave wrong name or password. +_____________________ + + +_____________________ +Add User:- + URL:- /add_user + + Method:- POST + + Data Type:- Form Data + + Data content:- { + user_name: "", + password: "" + } + + Response:- + 200 OK:- + Data:- No + Note:- Assume success. + + 400 Bad Request:- + Content Type:- text/plain + Note:- user_name or password not given a Form Data. + Data:- What is missing will be mentioned. + + 403 Forbidden:- + Content Type:- text/plain + Note:- user_name is exists, can display the response data to user. + Data:- Text that can be displayed on the screen. Example:- formData = new FormData(); diff --git a/backend/rest_api.py b/backend/rest_api.py index 1187cf9..2dbd4a1 100644 --- a/backend/rest_api.py +++ b/backend/rest_api.py @@ -68,3 +68,34 @@ class QueryHandler: ) return Response(status=200) + + @staticmethod + @app.post("/add_user") + def add_user() -> Response: + """ + Adds a new user + """ + data: ImmutableMultiDict[str, str] = request.form + if "user_name" not in data: + return Response( + "user_name not given", + 400, + content_type="text/plain" + ) + if "password" not in data: + return Response( + "password is not given", + 400, + content_type="text/plain" + ) + + try: + DataHandler.create_user(data["user_name"], data["password"]) + except ValueError as value_error: + return Response( + str(value_error), + 403, + content_type="text/plain" + ) + + return Response(status=200)