Added food api endpoints prep for mcp
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import MinValueValidator
|
||||
@@ -22,6 +24,7 @@ class MealType(models.TextChoices):
|
||||
|
||||
|
||||
class FoodProduct(models.Model):
|
||||
api_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
|
||||
class Source(models.TextChoices):
|
||||
OPEN_FOOD_FACTS = 'openfoodfacts', 'Open Food Facts'
|
||||
MANUAL = 'manual', 'Manual'
|
||||
@@ -58,6 +61,7 @@ class FoodProduct(models.Model):
|
||||
|
||||
|
||||
class FoodLogEntry(models.Model):
|
||||
api_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='food_log_entries')
|
||||
date = models.DateField(db_index=True)
|
||||
time = models.TimeField(null=True, blank=True)
|
||||
@@ -77,6 +81,7 @@ class FoodLogEntry(models.Model):
|
||||
sugars_g = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, validators=NON_NEGATIVE)
|
||||
salt_g = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, validators=NON_NEGATIVE)
|
||||
source = models.CharField(max_length=16, choices=FoodProduct.Source.choices, default=FoodProduct.Source.MANUAL)
|
||||
created_via = models.CharField(max_length=16, default='web')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
@@ -156,6 +161,7 @@ class InventoryCategory(models.Model):
|
||||
|
||||
|
||||
class KitchenInventoryItem(models.Model):
|
||||
api_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='kitchen_inventory')
|
||||
product = models.ForeignKey(FoodProduct, on_delete=models.PROTECT, related_name='inventory_items')
|
||||
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(1)])
|
||||
@@ -176,3 +182,37 @@ class KitchenInventoryItem(models.Model):
|
||||
raise ValidationError({'location': 'Choose one of your own locations.'})
|
||||
if self.user_id and self.category_id and self.category.user_id != self.user_id:
|
||||
raise ValidationError({'category': 'Choose one of your own categories.'})
|
||||
|
||||
|
||||
class PersonalAccessToken(models.Model):
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='personal_access_tokens')
|
||||
name = models.CharField(max_length=100)
|
||||
prefix = models.CharField(max_length=20, unique=True)
|
||||
token_hash = models.CharField(max_length=64)
|
||||
scopes = models.JSONField(default=list)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
last_used_at = models.DateTimeField(null=True, blank=True)
|
||||
expires_at = models.DateTimeField(null=True, blank=True)
|
||||
revoked_at = models.DateTimeField(null=True, blank=True)
|
||||
|
||||
|
||||
class FoodLogAttachment(models.Model):
|
||||
api_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
|
||||
log_entry = models.ForeignKey(FoodLogEntry, on_delete=models.CASCADE, related_name='attachments')
|
||||
image = models.ImageField(upload_to='food-attachments/%Y/%m/')
|
||||
original_filename = models.CharField(max_length=255)
|
||||
content_type = models.CharField(max_length=50)
|
||||
file_size = models.PositiveIntegerField()
|
||||
caption = models.CharField(max_length=255, blank=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class ApiIdempotencyRecord(models.Model):
|
||||
token = models.ForeignKey(PersonalAccessToken, on_delete=models.CASCADE)
|
||||
key = models.CharField(max_length=128)
|
||||
request_hash = models.CharField(max_length=64)
|
||||
response = models.JSONField()
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=('token', 'key'), name='food_unique_api_idempotency_key')]
|
||||
|
||||
Reference in New Issue
Block a user