Created and activated the booking integrity ExecPlan, then implemented staff availability, overlap prevention, and duration validation with backend tests.
Added a staff availability model and migration, a booking validation service, and serializer enforcement.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from rest_framework import serializers
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from apps.bookings.models import Booking
|
||||
from apps.bookings.services import validate_booking_request
|
||||
from apps.salons.models import Service, StaffProfile
|
||||
|
||||
|
||||
@@ -42,12 +41,12 @@ class BookingCreateSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Booking
|
||||
fields = ["service", "staff", "start_time", "end_time", "notes"]
|
||||
extra_kwargs = {"staff": {"required": True}}
|
||||
|
||||
def validate(self, attrs):
|
||||
service: Service = attrs["service"]
|
||||
staff = attrs.get("staff")
|
||||
if staff and staff.salon_id != service.salon_id:
|
||||
raise serializers.ValidationError(_("Selected staff does not belong to this salon"))
|
||||
validate_booking_request(service, staff, attrs["start_time"], attrs["end_time"])
|
||||
return attrs
|
||||
|
||||
def create(self, validated_data):
|
||||
|
||||
Reference in New Issue
Block a user