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
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. |
fasting |
StrictInt | None
|
Target fasting duration in seconds. |
water_ml |
StrictFloat | None
|
Target daily water intake in milliliters. |
poop_count |
StrictInt | None
|
Target daily bowel movement count. |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
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
46 47 48 49 50 51 52 53 54 55 56 | |
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
59 60 61 62 63 64 65 | |
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 |
|---|---|
HealthTargetsRead
|
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
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 | |
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 |
|---|---|
HealthTargetsRead
|
The updated HealthTargetsRead schema. |
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
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
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 |
|---|---|
HealthTargetsRead | None
|
The HealthTargetsRead schema if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
500 error if database query fails. |
Source code in backend/app/health/health_targets/crud.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |