From e0ffe1a79bfabbf571a604d377e7a131cbd51ea6 Mon Sep 17 00:00:00 2001
From: cami
Date: Sun, 27 Jun 2021 00:39:28 +0200
Subject: [PATCH 1/2] Added survey to web application with the backend working
---
backend/src/app.py | 13 +++++++-
frontend/src/components/pages/Umfrage.js | 39 ++++++++++++++++--------
2 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/backend/src/app.py b/backend/src/app.py
index 6e76a6c..1c55a4c 100644
--- a/backend/src/app.py
+++ b/backend/src/app.py
@@ -148,7 +148,18 @@ def register():
new_user.username
)}
return ret, 200
-
+
+
+@app.route('/umfrage', methods=['POST'])
+@flask_praetorian.auth_required
+def survey():
+ req = flask.request.get_json(force=True)
+ gender = req.get('gender', None)
+ print(req)
+ ret = {'message': 'Umfrage freigestellt'}
+ return ret, 200
+
+
@app.route('/time')
def get_current_time():
return {'time': time.time()}
diff --git a/frontend/src/components/pages/Umfrage.js b/frontend/src/components/pages/Umfrage.js
index 439eb01..df9e1f7 100644
--- a/frontend/src/components/pages/Umfrage.js
+++ b/frontend/src/components/pages/Umfrage.js
@@ -5,6 +5,7 @@ import "../Input.css";
import Footer from "../../Footer";
import InputField from "../InputField";
import SubmitField from "../SubmitField";
+import { authFetch } from "../../auth/AuthProvider";
export default function Umfrage() {
const [age, setAge] = useState("");
@@ -12,6 +13,8 @@ export default function Umfrage() {
const [education, setEducation] = useState("");
const [skills, setSkills] = useState("");
+ let surveyIsValid = true;
+
const onSubmitClick = (e) => {
e.preventDefault();
let opts = {
@@ -20,20 +23,32 @@ export default function Umfrage() {
education: education,
skills: skills,
};
- console.log(opts);
- /*fetch("/api/login", {
+
+ if (!Number(age)) {
+ console.log("age is not a number");
+ surveyIsValid = false;
+ }
+ if (gender === "DEFAULT" || gender === "") {
+ console.log("choose gender");
+ surveyIsValid = false;
+ }
+ if (education === "DEFAULT" || education === "") {
+ console.log("choose edu");
+ surveyIsValid = false;
+ }
+ if (skills === "DEFAULT" || skills === "") {
+ console.log("choose skills");
+ surveyIsValid = false;
+ }
+
+ if (surveyIsValid === true) {
+ console.log(opts);
+ }
+
+ authFetch("/umfrage", {
method: "post",
body: JSON.stringify(opts),
- })
- .then((r) => r.json())
- .then((token) => {
- if (token.access_token) {
- login(token);
- } else {
- console.log("Please type in the correct username / password");
- }
- });
- */
+ });
};
const handleAgeChange = (e) => {
--
2.45.2
From f4e460123f17bcd28717ad28a385dd8a7e1838a8 Mon Sep 17 00:00:00 2001
From: cami
Date: Sun, 27 Jun 2021 00:41:17 +0200
Subject: [PATCH 2/2] backend will only receive the request (see #62)
This commit will solve the issue #62 so that not every click in the form will trigger a request to the backend
---
frontend/src/components/pages/Umfrage.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/frontend/src/components/pages/Umfrage.js b/frontend/src/components/pages/Umfrage.js
index df9e1f7..e6a581b 100644
--- a/frontend/src/components/pages/Umfrage.js
+++ b/frontend/src/components/pages/Umfrage.js
@@ -86,10 +86,11 @@ export default function Umfrage() {
So kann es für mich beispielsweise relevant sein, wenn sämtliche
Teilnehmenden ein sehr gutes Informatikverständnis haben.
-