Add Django backend, 1C integration, deploy config and API docs
Backend (Django 4.2 + DRF): - accounts: phone OTP login, JWT, profile, addresses - catalog: categories, products, images, filters, search, hits/new/related - orders: creation with Idempotency-Key, stock reservation, status history, cancel - loyalty: bonus accounts, promo codes, gift certificates - payments: payment records and YooKassa webhook handling - content: static pages, banners, site settings - integration: 1C exchange (catalog sync, order push via outbox, statuses, bonuses) - common: error envelope, pagination, request-id, integration auth, admin dashboard Infrastructure: Dockerfile, docker-compose (Postgres, Redis, Celery worker/beat, Nginx), requirements split by environment, OpenAPI contracts for site and 1C, architecture doc. Tests: 22 pytest cases covering catalog, orders, idempotency, OTP, integration.
This commit is contained in:
1 parent
5f8d37357d
commit
756f40353b
130 files changed
+10066
No files matched your search
@@ -0,0 +1,100 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.common.models import TimeStampedModel
|
||||
|
||||
from .managers import UserManager
|
||||
|
||||
|
||||
class User(AbstractBaseUser, PermissionsMixin):
|
||||
"""Store customer. Phone is the primary login identifier."""
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
phone = models.CharField("телефон", max_length=20, unique=True)
|
||||
email = models.EmailField("email", blank=True, null=True, unique=True)
|
||||
first_name = models.CharField("имя", max_length=150, blank=True)
|
||||
last_name = models.CharField("фамилия", max_length=150, blank=True)
|
||||
middle_name = models.CharField("отчество", max_length=150, blank=True)
|
||||
is_active = models.BooleanField("активен", default=True)
|
||||
is_staff = models.BooleanField("сотрудник", default=False)
|
||||
date_joined = models.DateTimeField("дата регистрации", default=timezone.now)
|
||||
|
||||
objects = UserManager()
|
||||
|
||||
USERNAME_FIELD = "phone"
|
||||
REQUIRED_FIELDS: list[str] = []
|
||||
|
||||
class Meta:
|
||||
db_table = "accounts_user"
|
||||
verbose_name = "пользователь"
|
||||
verbose_name_plural = "пользователи"
|
||||
ordering = ["-date_joined"]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.phone
|
||||
|
||||
@property
|
||||
def full_name(self) -> str:
|
||||
parts = [self.last_name, self.first_name, self.middle_name]
|
||||
return " ".join(part for part in parts if part).strip()
|
||||
|
||||
|
||||
class OtpCode(TimeStampedModel):
|
||||
"""One-time password for phone login."""
|
||||
|
||||
class Purpose(models.TextChoices):
|
||||
LOGIN = "login", "Вход"
|
||||
PHONE_CHANGE = "phone_change", "Смена телефона"
|
||||
|
||||
phone = models.CharField(max_length=20, db_index=True)
|
||||
code_hash = models.CharField(max_length=128)
|
||||
purpose = models.CharField(
|
||||
max_length=20, choices=Purpose.choices, default=Purpose.LOGIN
|
||||
)
|
||||
expires_at = models.DateTimeField()
|
||||
attempts = models.PositiveSmallIntegerField(default=0)
|
||||
is_used = models.BooleanField(default=False)
|
||||
|
||||
class Meta:
|
||||
db_table = "accounts_otp_code"
|
||||
verbose_name = "OTP-код"
|
||||
verbose_name_plural = "OTP-коды"
|
||||
indexes = [
|
||||
models.Index(fields=["phone", "purpose", "is_used"]),
|
||||
]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.phone} ({self.purpose})"
|
||||
|
||||
def is_expired(self) -> bool:
|
||||
return timezone.now() >= self.expires_at
|
||||
|
||||
|
||||
class Address(TimeStampedModel):
|
||||
"""Customer delivery address."""
|
||||
|
||||
user = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, related_name="addresses"
|
||||
)
|
||||
title = models.CharField("название", max_length=64, default="Дом")
|
||||
city = models.CharField("город", max_length=128)
|
||||
street = models.CharField("улица", max_length=255)
|
||||
house = models.CharField("дом", max_length=32)
|
||||
apartment = models.CharField("квартира/офис", max_length=32, blank=True)
|
||||
postal_code = models.CharField("индекс", max_length=16, blank=True)
|
||||
entrance = models.CharField("подъезд", max_length=16, blank=True)
|
||||
floor = models.CharField("этаж", max_length=16, blank=True)
|
||||
intercom = models.CharField("домофон", max_length=32, blank=True)
|
||||
is_default = models.BooleanField("по умолчанию", default=False)
|
||||
|
||||
class Meta:
|
||||
db_table = "accounts_address"
|
||||
verbose_name = "адрес доставки"
|
||||
verbose_name_plural = "адреса доставки"
|
||||
ordering = ["-is_default", "-created_at"]
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.title}: {self.city}, {self.street}, {self.house}"
|
||||
Reference in new issue
Block a user