Skip to content

Commit

Permalink
add checkdone functionality to frontend data input, define model for …
Browse files Browse the repository at this point in the history
…observer.
  • Loading branch information
MaHaWo committed Oct 18, 2024
1 parent d0349d0 commit facc9dc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
1 change: 0 additions & 1 deletion frontend/src/lib/components/DataInput/DataInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
$: valid = evalValid(value);
$: highlight = !valid && properties.required === true;
$: showTextField = checkShowTextfield(value);
$: console.log('value in datainput: ', value);
</script>

{#if label}
Expand Down
31 changes: 25 additions & 6 deletions frontend/src/lib/components/UserDataInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,41 @@
import {} from '$lib/client/services.gen';
// TODO: As researcher, you don´t have to provide these data. Researchers have another component that is all there own and does not yet exist. Hence, the userlandingpage should not have this component
// TODO: not sure this is good.... seems like a lot of logic and work to do here...
function checkDataFilled(values: any[]) {
console.log('checkfilled: ', values);
let allFilled = true;
for (const element of values) {
console.log(' element: ', element);
allFilled = allFilled && element !== null && element !== '' && element !== undefined;
}
console.log('all done: ', allFilled);
return allFilled;
}
async function submitData() {
try {
// TODO: call the respective API function here to update the data
// TODO: add button icon and ok message
done = true;
} catch (error) {
const error: Error | null = null;
// TODO: call the respective API function here to update the data
done = true;
if (error) {
showAlert = true;
alertMessage = $_('userData.alertMessageError') + ': ' + error.detail;
}
}
// this can, but does not have to, come from a database later.
// TODO: this needs to load data from the backend
export let data: any[];
let showAlert: boolean = false;
let done: boolean = false;
let done: boolean = checkDataFilled(
data.map((element) => {
return element.value;
})
);
let alertMessage = $_('userData.alertMessageMissing');
</script>

Expand Down
1 change: 0 additions & 1 deletion mondey_backend/db/README.md

This file was deleted.

23 changes: 23 additions & 0 deletions mondey_backend/src/mondey_backend/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import declared_attr
from sqlalchemy.orm import mapped_column
from sqlmodel import Field
from sqlmodel import SQLModel


class Base(DeclarativeBase):
pass


class User(SQLAlchemyBaseUserTable[int], Base):
__tablename__ = "user"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
is_researcher: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)

Expand All @@ -39,3 +42,23 @@ def user_id(cls) -> Mapped[int]:
return mapped_column(
Integer, ForeignKey("user.id", ondelete="cascade"), nullable=False
)


class Observer(SQLModel, table=True):
user_id: int = Field(default=None, primary_key=True)
year_of_birth: str = Field(max_length=255, nullable=False)
gender: str = Field(max_length=255, nullable=False)
education: str = Field(max_length=255, nullable=False)
working_hours: str = Field(max_length=255, nullable=False)
income_per_year: str = Field(max_length=255, nullable=False)
profession: str = Field(max_length=255, nullable=False)


# class Observer(SQLModel, table=True):
# id: int | None = Field(default=None, primary_key=True)
# yearOfBirth: str
# gender: str
# education: str
# workingHours: str
# incomePerYear: str
# profession: str
17 changes: 17 additions & 0 deletions mondey_backend/src/mondey_backend/routers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..models.milestones import MilestoneAnswerPublic
from ..models.milestones import MilestoneAnswerSession
from ..models.milestones import MilestoneAnswerSessionPublic
from ..models.users import Observer
from ..models.users import UserRead
from ..models.users import UserUpdate
from ..settings import app_settings
Expand All @@ -32,6 +33,22 @@ 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=Observer)
def get_observer(session: SessionDep, current_active_user: CurrentActiveUserDep):
pass

@router.put("/data/", response_model=Observer)
def update_observer(
session: SessionDep,
current_active_user: CurrentActiveUserDep,
observerData: Observer,
):
pass

@router.put("/data/", response_model=Observer)
def create_observer(session: SessionDep, current_active_user: CurrentActiveUserDep):
pass

@router.get("/children/", response_model=list[ChildPublic])
def get_children(session: SessionDep, current_active_user: CurrentActiveUserDep):
return [
Expand Down

0 comments on commit facc9dc

Please sign in to comment.