From c79c449fbe19276bfe987e9e4537ce1809dd9a4d Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Fri, 18 Oct 2024 14:46:07 +0200 Subject: [PATCH] work on frontend userdatainput behavior --- .../src/lib/components/UserDataInput.svelte | 52 +++++++++++-------- frontend/src/locales/de.json | 2 + .../src/mondey_backend/models/users.py | 15 ------ .../src/mondey_backend/routers/users.py | 24 --------- 4 files changed, 32 insertions(+), 61 deletions(-) diff --git a/frontend/src/lib/components/UserDataInput.svelte b/frontend/src/lib/components/UserDataInput.svelte index cdbd6092..7a722d8b 100644 --- a/frontend/src/lib/components/UserDataInput.svelte +++ b/frontend/src/lib/components/UserDataInput.svelte @@ -1,41 +1,37 @@ {#if showAlert} { showAlert = false; }} @@ -61,21 +57,33 @@ properties={element.props} textTrigger={element.props.textTrigger} eventHandlers={{ - 'on:change': element.onchange, + 'on:change': () => { + done = false; + element?.onchange(); + }, 'on:blur': element.onblur, 'on:click': element.onclick }} additionalEventHandlers={{ - 'on:change': element.onchange, + 'on:change': () => { + done = false; + }, 'on:blur': element.onblur, 'on:click': element.onclick }} /> {/each} + {#if done} +
+ + {$_('userData.submitSuccessMessage')} +
+ {:else} + + {/if} - diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index ce48b752..c8774d32 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -79,7 +79,9 @@ "heading": "Benutzerdaten eingeben", "alertMessageTitle": "Fehler", "alertMessageMissing": "Bitte füllen Sie die benötigten Felder (hervorgehoben) aus.", + "alertMessageError": "Ein Fehler ist aufgetreten", "submitButtonLabel": "Abschließen", + "submitSuccessMessage": "Vielen Dank!", "yearOfBirth": { "label": "Geburtsjahr", "placeholder": "Bitte auswählen" diff --git a/mondey_backend/src/mondey_backend/models/users.py b/mondey_backend/src/mondey_backend/models/users.py index 2d3cf4d2..dbccc141 100644 --- a/mondey_backend/src/mondey_backend/models/users.py +++ b/mondey_backend/src/mondey_backend/models/users.py @@ -6,7 +6,6 @@ from sqlalchemy import Boolean from sqlalchemy import ForeignKey from sqlalchemy import Integer -from sqlalchemy import String from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped from sqlalchemy.orm import declared_attr @@ -40,17 +39,3 @@ def user_id(cls) -> Mapped[int]: return mapped_column( Integer, ForeignKey("user.id", ondelete="cascade"), nullable=False ) - - -class ObserverData(Base): - id: Mapped[int] = mapped_column(Integer, primary_key=True) - birthYear: Mapped[int] = mapped_column(Integer, nullable=False) - gender: Mapped[str] = mapped_column(String(255), nullable=False) - education: Mapped[str] = mapped_column(String(255), nullable=False) - workingHours: Mapped[str] = mapped_column(String(255), nullable=False) - incomePerYear: Mapped[str] = mapped_column(String(255), nullable=False) - profession: Mapped[str] = mapped_column(String(255), nullable=False) - langid: Mapped[int] = mapped_column(Integer, nullable=False) - userid: Mapped[int] = mapped_column( - Integer, ForeignKey("user.id", ondelete="cascade"), nullable=False - ) diff --git a/mondey_backend/src/mondey_backend/routers/users.py b/mondey_backend/src/mondey_backend/routers/users.py index 02d0d972..2ca45acd 100644 --- a/mondey_backend/src/mondey_backend/routers/users.py +++ b/mondey_backend/src/mondey_backend/routers/users.py @@ -6,8 +6,6 @@ from fastapi import HTTPException from fastapi import UploadFile from fastapi.responses import FileResponse -from sqlmodel import col -from sqlmodel import select from ..dependencies import CurrentActiveUserDep from ..dependencies import SessionDep @@ -18,7 +16,6 @@ from ..models.milestones import MilestoneAnswerPublic from ..models.milestones import MilestoneAnswerSession from ..models.milestones import MilestoneAnswerSessionPublic -from ..models.users import ObserverData from ..models.users import UserRead from ..models.users import UserUpdate from ..settings import app_settings @@ -33,27 +30,6 @@ def create_router() -> APIRouter: router = APIRouter(prefix="/users", tags=["users"]) router.include_router(fastapi_users.get_users_router(UserRead, UserUpdate)) - @router.get("/data/", response_model=ObserverData) - def get_userdata(session: SessionDep, current_active_user: CurrentActiveUserDep): - return ObserverData() - - @router.post("/data/", response_model=ObserverData) - def create_userdata(session: SessionDep, current_active_user: CurrentActiveUserDep): - return ObserverData() - - @router.put("/data/", response_model=ObserverData) - def update_userdata(session: SessionDep, current_active_user: CurrentActiveUserDep): - return ObserverData() - - @router.get("/children/", response_model=list[ChildPublic]) - def get_children(session: SessionDep, current_active_user: CurrentActiveUserDep): - return [ - child - for child in session.exec( - select(Child).where(col(Child.user_id) == current_active_user.id) - ).all() - ] - @router.post("/children/", response_model=ChildPublic) def create_child( session: SessionDep,