Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Children to backend #114

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions frontend/src/lib/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export const Body_reset_reset_password_auth_reset_password_postSchema = {
title: 'Body_reset_reset_password_auth_reset_password_post'
} as const;

export const Body_upload_child_image_users_children_images__child_id__putSchema = {
properties: {
file: {
type: 'string',
format: 'binary',
title: 'File'
}
},
type: 'object',
required: ['file'],
title: 'Body_upload_child_image_users_children_images__child_id__put'
} as const;

export const Body_upload_milestone_group_image_admin_milestone_group_images__milestone_group_id__putSchema =
{
properties: {
Expand Down Expand Up @@ -136,6 +149,60 @@ export const Body_verify_verify_auth_verify_postSchema = {
title: 'Body_verify_verify_auth_verify_post'
} as const;

export const ChildCreateSchema = {
properties: {
name: {
type: 'string',
title: 'Name',
default: ''
},
birth_year: {
type: 'integer',
title: 'Birth Year'
},
birth_month: {
type: 'integer',
title: 'Birth Month'
},
has_image: {
type: 'boolean',
title: 'Has Image'
}
},
type: 'object',
required: ['birth_year', 'birth_month', 'has_image'],
title: 'ChildCreate'
} as const;

export const ChildPublicSchema = {
properties: {
name: {
type: 'string',
title: 'Name',
default: ''
},
birth_year: {
type: 'integer',
title: 'Birth Year'
},
birth_month: {
type: 'integer',
title: 'Birth Month'
},
has_image: {
type: 'boolean',
title: 'Has Image'
},
id: {
type: 'integer',
title: 'Id'
}
},
type: 'object',
required: ['birth_year', 'birth_month', 'has_image', 'id'],
title: 'ChildPublic'
} as const;

export const ErrorModelSchema = {
properties: {
detail: {
Expand Down
98 changes: 98 additions & 0 deletions frontend/src/lib/client/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ import type {
UsersDeleteUserData,
UsersDeleteUserError,
UsersDeleteUserResponse,
GetChildrenError,
GetChildrenResponse,
CreateChildData,
CreateChildError,
CreateChildResponse,
UpdateChildData,
UpdateChildError,
UpdateChildResponse,
DeleteChildData,
DeleteChildError,
DeleteChildResponse,
GetChildImageData,
GetChildImageError,
GetChildImageResponse,
UploadChildImageData,
UploadChildImageError,
UploadChildImageResponse,
AuthCookieLoginData,
AuthCookieLoginError,
AuthCookieLoginResponse,
Expand Down Expand Up @@ -528,6 +545,87 @@ export const usersDeleteUser = <ThrowOnError extends boolean = false>(
});
};

/**
* Get Children
*/
export const getChildren = <ThrowOnError extends boolean = false>(
options?: Options<unknown, ThrowOnError>
) => {
return (options?.client ?? client).get<GetChildrenResponse, GetChildrenError, ThrowOnError>({
...options,
url: '/users/children/'
});
};

/**
* Create Child
*/
export const createChild = <ThrowOnError extends boolean = false>(
options: Options<CreateChildData, ThrowOnError>
) => {
return (options?.client ?? client).post<CreateChildResponse, CreateChildError, ThrowOnError>({
...options,
url: '/users/children/'
});
};

/**
* Update Child
*/
export const updateChild = <ThrowOnError extends boolean = false>(
options: Options<UpdateChildData, ThrowOnError>
) => {
return (options?.client ?? client).put<UpdateChildResponse, UpdateChildError, ThrowOnError>({
...options,
url: '/users/children'
});
};

/**
* Delete Child
*/
export const deleteChild = <ThrowOnError extends boolean = false>(
options: Options<DeleteChildData, ThrowOnError>
) => {
return (options?.client ?? client).delete<DeleteChildResponse, DeleteChildError, ThrowOnError>({
...options,
url: '/users/children/{child_id}'
});
};

/**
* Get Child Image
*/
export const getChildImage = <ThrowOnError extends boolean = false>(
options: Options<GetChildImageData, ThrowOnError>
) => {
return (options?.client ?? client).get<GetChildImageResponse, GetChildImageError, ThrowOnError>({
...options,
url: '/users/children-images/{child_id}'
});
};

/**
* Upload Child Image
*/
export const uploadChildImage = <ThrowOnError extends boolean = false>(
options: Options<UploadChildImageData, ThrowOnError>
) => {
return (options?.client ?? client).put<
UploadChildImageResponse,
UploadChildImageError,
ThrowOnError
>({
...options,
...formDataBodySerializer,
headers: {
'Content-Type': null,
...options?.headers
},
url: '/users/children-images/{child_id}'
});
};

/**
* Auth:Cookie.Login
*/
Expand Down
70 changes: 70 additions & 0 deletions frontend/src/lib/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export type Body_reset_reset_password_auth_reset_password_post = {
password: string;
};

export type Body_upload_child_image_users_children_images__child_id__put = {
file: Blob | File;
};

export type Body_upload_milestone_group_image_admin_milestone_group_images__milestone_group_id__put =
{
file: Blob | File;
Expand All @@ -35,6 +39,21 @@ export type Body_verify_verify_auth_verify_post = {
token: string;
};

export type ChildCreate = {
name?: string;
birth_year: number;
birth_month: number;
has_image: boolean;
};

export type ChildPublic = {
name?: string;
birth_year: number;
birth_month: number;
has_image: boolean;
id: number;
};

export type ErrorModel = {
detail:
| string
Expand Down Expand Up @@ -411,6 +430,57 @@ export type UsersDeleteUserResponse = void;

export type UsersDeleteUserError = unknown | HTTPValidationError;

export type GetChildrenResponse = Array<ChildPublic>;

export type GetChildrenError = unknown;

export type CreateChildData = {
body: ChildCreate;
};

export type CreateChildResponse = ChildPublic;

export type CreateChildError = HTTPValidationError;

export type UpdateChildData = {
body: ChildPublic;
};

export type UpdateChildResponse = ChildPublic;

export type UpdateChildError = HTTPValidationError;

export type DeleteChildData = {
path: {
child_id: number;
};
};

export type DeleteChildResponse = unknown;

export type DeleteChildError = HTTPValidationError;

export type GetChildImageData = {
path: {
child_id: number;
};
};

export type GetChildImageResponse = unknown;

export type GetChildImageError = HTTPValidationError;

export type UploadChildImageData = {
body: Body_upload_child_image_users_children_images__child_id__put;
path: {
child_id: number;
};
};

export type UploadChildImageResponse = unknown;

export type UploadChildImageError = HTTPValidationError;

export type AuthCookieLoginData = {
body: Body_auth_cookie_login_auth_login_post;
};
Expand Down
2 changes: 1 addition & 1 deletion mondey_backend/openapi.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions mondey_backend/src/mondey_backend/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def current_active_researcher(

ResearchDep = Depends(current_active_researcher)

CurrentActiveResearchDep = Annotated[User, Depends(current_active_user)]

current_active_superuser = fastapi_users.current_user(active=True, superuser=True)

AdminDep = Depends(current_active_superuser)
2 changes: 1 addition & 1 deletion mondey_backend/src/mondey_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from .routers import admin
from .routers import auth
from .routers import milestones
from .routers import research
from .routers import questions
from .routers import research
from .routers import users
from .settings import app_settings

Expand Down
24 changes: 24 additions & 0 deletions mondey_backend/src/mondey_backend/models/children.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

from sqlmodel import Field
from sqlmodel import SQLModel


class ChildBase(SQLModel):
name: str = ""
birth_year: int
birth_month: int
has_image: bool


class Child(ChildBase, table=True):
id: int | None = Field(default=None, primary_key=True)
user_id: int


class ChildCreate(ChildBase):
pass


class ChildPublic(ChildBase):
id: int
12 changes: 0 additions & 12 deletions mondey_backend/src/mondey_backend/models/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,3 @@ class MilestoneImage(SQLModel, table=True):
class MilestoneImagePublic(SQLModel):
filename: str
approved: bool


## MilestoneAnswer


# class MilestoneAnswer(SQLModel, table=True):
# milestone_id: int | None = Field(default=None, foreign_key="milestone.id")
# user_id: int | None = Field(default=None, foreign_key="user.id")
# created_at: datetime.datetime = Field(
# default_factory=datetime.datetime.now,
# )
# answer: int
4 changes: 3 additions & 1 deletion mondey_backend/src/mondey_backend/routers/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from fastapi import APIRouter

from ..dependencies import CurrentActiveResearchDep
from ..dependencies import ResearchDep


Expand All @@ -11,7 +12,8 @@ def create_router() -> APIRouter:
)

@router.get("/auth/")
def auth():
def auth(current_active_researcher: CurrentActiveResearchDep):
print(current_active_researcher.id)
return {"ok": True}

return router
Loading