From b99acb025b45fc546ffb5290a7aa6b0cc1d9f07c Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Mon, 21 Oct 2024 13:03:43 +0200 Subject: [PATCH] work on endpoints for user answer --- frontend/src/lib/client/schemas.gen.ts | 25 ++++++++++++ frontend/src/lib/client/services.gen.ts | 37 ++++++++++++++++++ frontend/src/lib/client/types.gen.ts | 28 +++++++++++++ .../src/lib/components/UserDataInput.svelte | 39 ++++++++++++++++++- mondey_backend/openapi.json | 2 +- .../src/mondey_backend/routers/questions.py | 1 + .../src/mondey_backend/routers/users.py | 19 +++------ 7 files changed, 134 insertions(+), 17 deletions(-) diff --git a/frontend/src/lib/client/schemas.gen.ts b/frontend/src/lib/client/schemas.gen.ts index 31d4036e..71d9082a 100644 --- a/frontend/src/lib/client/schemas.gen.ts +++ b/frontend/src/lib/client/schemas.gen.ts @@ -623,6 +623,31 @@ export const MilestoneTextPublicSchema = { title: 'MilestoneTextPublic' } as const; +export const UserAnswerPublicSchema = { + properties: { + id: { + type: 'integer', + title: 'Id' + }, + user_question_id: { + type: 'integer', + title: 'User Question Id' + }, + answer: { + type: 'string', + title: 'Answer' + } + }, + type: 'object', + required: ['id', 'user_question_id', 'answer'], + title: 'UserAnswerPublic', + description: `External data model for UserAnswers + +Parameters +---------- +SQLModel : Pydantic model basic sqlmodel pydantic type` +} as const; + export const UserCreateSchema = { properties: { email: { diff --git a/frontend/src/lib/client/services.gen.ts b/frontend/src/lib/client/services.gen.ts index b307ca6c..4e4ae706 100644 --- a/frontend/src/lib/client/services.gen.ts +++ b/frontend/src/lib/client/services.gen.ts @@ -103,6 +103,11 @@ import type { UpdateMilestoneAnswerData, UpdateMilestoneAnswerError, UpdateMilestoneAnswerResponse, + GetCurrentUserAnswersError, + GetCurrentUserAnswersResponse, + UpdateCurrentUserAnswersData, + UpdateCurrentUserAnswersError, + UpdateCurrentUserAnswersResponse, AuthCookieLoginData, AuthCookieLoginError, AuthCookieLoginResponse, @@ -664,6 +669,38 @@ export const updateMilestoneAnswer = ( }); }; +/** + * Get Current User Answers + */ +export const getCurrentUserAnswers = ( + options?: Options +) => { + return (options?.client ?? client).get< + GetCurrentUserAnswersResponse, + GetCurrentUserAnswersError, + ThrowOnError + >({ + ...options, + url: '/users/user-answers/{user_id}' + }); +}; + +/** + * Update Current User Answers + */ +export const updateCurrentUserAnswers = ( + options: Options +) => { + return (options?.client ?? client).put< + UpdateCurrentUserAnswersResponse, + UpdateCurrentUserAnswersError, + ThrowOnError + >({ + ...options, + url: '/usersuser_answers/{user_id}' + }); +}; + /** * Auth:Cookie.Login */ diff --git a/frontend/src/lib/client/types.gen.ts b/frontend/src/lib/client/types.gen.ts index 5982f122..009e051b 100644 --- a/frontend/src/lib/client/types.gen.ts +++ b/frontend/src/lib/client/types.gen.ts @@ -162,6 +162,19 @@ export type MilestoneTextPublic = { help?: string; }; +/** + * External data model for UserAnswers + * + * Parameters + * ---------- + * SQLModel : Pydantic model basic sqlmodel pydantic type + */ +export type UserAnswerPublic = { + id: number; + user_question_id: number; + answer: string; +}; + export type UserCreate = { email: string; password: string; @@ -514,6 +527,21 @@ export type UpdateMilestoneAnswerResponse = MilestoneAnswerPublic; export type UpdateMilestoneAnswerError = HTTPValidationError; +export type GetCurrentUserAnswersResponse = UserAnswerPublic; + +export type GetCurrentUserAnswersError = unknown; + +export type UpdateCurrentUserAnswersData = { + body: UserAnswerPublic; + query: { + milestone_answer_session_id: number; + }; +}; + +export type UpdateCurrentUserAnswersResponse = unknown; + +export type UpdateCurrentUserAnswersError = HTTPValidationError; + export type AuthCookieLoginData = { body: Body_auth_cookie_login_auth_login_post; }; diff --git a/frontend/src/lib/components/UserDataInput.svelte b/frontend/src/lib/components/UserDataInput.svelte index a794b401..7a00d4e5 100644 --- a/frontend/src/lib/components/UserDataInput.svelte +++ b/frontend/src/lib/components/UserDataInput.svelte @@ -1,10 +1,16 @@