API Reference
Health targets module for managing user health goals.
This module provides CRUD operations and data models for user health targets including weight, steps, and sleep goals.
Exports
- CRUD: get_health_targets_by_user_id, create_health_targets, edit_health_target
- Schemas: HealthTargetsBase, HealthTargetsUpdate, HealthTargetsRead
- Models: HealthTargets (ORM model)
HealthTargetsBase
Bases: BaseModel
Base schema for health targets with shared fields.
Attributes:
| Name | Type | Description |
|---|---|---|
weight |
StrictFloat | None
|
Target weight in kg. |
steps |
StrictInt | None
|
Target daily steps count. |
sleep |
StrictInt | None
|
Target sleep duration in seconds. |
Source code in backend/app/health/health_targets/schema.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
HealthTargetsModel
Bases: Base
User health targets configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Mapped[int]
|
Primary key. |
user_id |
Mapped[int]
|
Foreign key to users table (unique). |
weight |
Mapped[Decimal | None]
|
Target weight in kg. |
steps |
Mapped[int | None]
|
Target daily steps count. |
sleep |
Mapped[int | None]
|
Target sleep duration in seconds. |
user |
Mapped[int | None]
|
Relationship to Users model. |
Source code in backend/app/health/health_targets/models.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
HealthTargetsRead
Bases: HealthTargetsBase
Schema for reading health targets.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
StrictInt
|
Unique identifier for the health target record. |
user_id |
StrictInt
|
Foreign key reference to the user. |
Source code in backend/app/health/health_targets/schema.py
31 32 33 34 35 36 37 38 39 40 41 | |
HealthTargetsUpdate
Bases: HealthTargetsRead
Schema for updating health targets.
Inherits all validation from HealthTargetsRead. All fields are optional for partial updates.
Source code in backend/app/health/health_targets/schema.py
44 45 46 47 48 49 50 | |
create_health_targets
create_health_targets(user_id, db)
Create new health targets for a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to create targets for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargets
|
The created HealthTargetsRead schema. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
409 error if targets already exist. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/health/health_targets/crud.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
edit_health_target
edit_health_target(health_target, user_id, db)
Update health targets for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
health_target
|
HealthTargetsUpdate
|
Schema with fields to update. |
required |
user_id
|
int
|
The ID of the user to update targets for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargets
|
The updated HealthTargets model. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 error if targets not found. |
HTTPException
|
500 error if database operation fails. |
Source code in backend/app/health/health_targets/crud.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
get_health_targets_by_user_id
get_health_targets_by_user_id(user_id, db)
Retrieve health targets for a specific user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
int
|
The ID of the user to fetch targets for. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
| Type | Description |
|---|---|
HealthTargets | None
|
The HealthTargets model if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/health/health_targets/crud.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |