remove alert class setup swagger

This commit is contained in:
Léo 2025-01-09 15:01:47 +01:00
parent 039ad74e94
commit edd9b25545
5 changed files with 28 additions and 20 deletions

View File

@ -9,14 +9,13 @@ class Product(models.Model):
creation_date = models.DateTimeField(auto_now_add=True)
modification_date = models.DateTimeField(auto_now=True)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="products")
stock_limit = models.IntegerField(null=True, blank=True)
alert_enabled = models.BooleanField(default=False)
alert_message = models.CharField(max_length=200, null=True, blank=True,help_text="Message d'alerte")
@property
def is_stock_low(self):
return self.alert_enabled and self.stock_limit is not None and self.quantity < self.stock_limit
def __str__(self):
return self.name
class Alerte(models.Model):
product = models.ForeignKey("Product", on_delete=models.CASCADE, related_name="alert")
stock_limit = models.IntegerField(null=False, blank=False)
message = models.CharField(max_length=200, null=True, blank=True)
creation_date = models.DateTimeField(auto_now_add=True)
modification_date = models.DateTimeField(auto_now=True)
return self.name

View File

@ -25,15 +25,8 @@ class UserSerializer(serializers.ModelSerializer):
class ProductSerializer(serializers.ModelSerializer):
user = serializers.PrimaryKeyRelatedField(read_only=True)
is_stock_low = serializers.BooleanField(read_only=True)
class Meta:
model = Product
fields = ["id", "name", "description", "quantity", "creation_date", "modification_date", "user"]
class AlerteSerializer(serializers.ModelSerializer):
product = ProductSerializer
class Meta:
model = Alerte
fields = ["id", "product", "stock_limit", "message", "creation_date", "modification_date"]
fields = ["id", "name", "description", "quantity", "creation_date", "modification_date", "user","stock_limit","alert_enabled","alert_message","is_stock_low"]

View File

@ -38,6 +38,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'StockSeeker',
'rest_framework',
'drf_spectacular',
'corsheaders',
]
MIDDLEWARE = [
@ -48,6 +50,8 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]
ROOT_URLCONF = 'StockSeeker.urls'
@ -104,6 +108,7 @@ AUTH_PASSWORD_VALIDATORS = [
]
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
@ -131,3 +136,12 @@ STATIC_URL = 'static/'
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
SPECTACULAR_SETTINGS = {
'TITLE': 'StockSeeker API',
'DESCRIPTION': 'Doc de lAPI pour StockSeeker',
'VERSION': '1.0.0',
}
CORS_ALLOWED_ORIGINS = [
"http://localhost:5173", # Remplace par l'URL de ton front-end
]

View File

@ -4,6 +4,7 @@ from rest_framework import routers
from .views import *
from . import views
from rest_framework_simplejwt.views import *
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
##juge pas les noms d'acces OK ?##
@ -16,5 +17,5 @@ urlpatterns = [
path('api/users', CreateUser.as_view(), name="create-user"),
path('api/users/me/', UserInfo.as_view(), name="user-info"),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh', TokenRefreshView.as_view(), name="token_refresh")
]
path('api/token/refresh', TokenRefreshView.as_view(), name="token_refresh"),
path('api/schema/', SpectacularAPIView.as_view(), name='schema')]

View File

@ -57,3 +57,4 @@ class ProductView(viewsets.ModelViewSet):
def get_queryset(self):
return Product.objects.filter(user_id=self.request.user)