diff --git a/skii/endpoint/routers/lesson.py b/skii/endpoint/routers/lesson.py index 40dc8bf..d3fbb55 100644 --- a/skii/endpoint/routers/lesson.py +++ b/skii/endpoint/routers/lesson.py @@ -38,7 +38,7 @@ def record_create(request: HttpRequest, payload: RouterSaveContract): @router.get( - path="/read/{pk}/", + path="/fetch/{pk}/", response={ 200: RouterContract, 422: FormInvalidResponseContract, @@ -57,13 +57,7 @@ def record_read(request: HttpRequest, pk: IntStrUUID4): ) def record_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveContract): record_payload = payload.dict() - if "coordinate" in record_payload: - geo_coordinate = record_payload["coordinate"] - del record_payload["coordinate"] - geo_coordinate_obj, created = GeoCoordinate.objects.update_or_create( - geo_coordinate, **geo_coordinate - ) - record_payload["coordinate"] = geo_coordinate_obj + record = get_object_or_404(RouterModel, pk=pk) for attr, value in record_payload.items(): setattr(record, attr, value) @@ -72,7 +66,7 @@ def record_update(request: HttpRequest, pk: IntStrUUID4, payload: RouterSaveCont return 200, record -@router.get( +@router.delete( path="/delete/{pk}/", response={ 200: SkiiMsgContract, @@ -83,7 +77,7 @@ def record_delete(request: HttpRequest, pk: IntStrUUID4): qs = RouterModel.objects.all().filter(pk=pk) if qs.exists(): qs.delete() - return 200, SkiiMsgContract(message="Record deleted") + return 200, SkiiMsgContract(message="OK") @router.get( @@ -95,6 +89,3 @@ def record_delete(request: HttpRequest, pk: IntStrUUID4): ) def record_list(request: HttpRequest): return 200, RouterModel.objects.all() - - -__all__ = [router] diff --git a/skii/platform/factories/factories.py b/skii/platform/factories/factories.py index fea2583..d0bd180 100644 --- a/skii/platform/factories/factories.py +++ b/skii/platform/factories/factories.py @@ -157,21 +157,22 @@ class LessonFactory(factory.django.DjangoModelFactory): class Meta: model = LessonEvent - label = factory.Faker("text") + label = factory.Faker("text", max_nb_chars=80) + description = factory.Faker("text", max_nb_chars=255) teacher = factory.SubFactory(TeacherAgentFactory) start = fuzzy.FuzzyDateTime( start_dt=datetime.now(tz=UTC) - timedelta(hours=2), end_dt=datetime.now(tz=UTC), force_year=2023, force_month=7, - force_day=13, + # force_day=13, ) stop = fuzzy.FuzzyDateTime( start_dt=datetime.now(tz=UTC), end_dt=datetime.now(tz=UTC) + timedelta(hours=4), force_year=2023, force_month=7, - force_day=13, + # force_day=13, ) @factory.post_generation diff --git a/skii/platform/migrations/0003_remove_lessonevent_check_no_overlap_and_more.py b/skii/platform/migrations/0003_remove_lessonevent_check_no_overlap_and_more.py new file mode 100644 index 0000000..75371ea --- /dev/null +++ b/skii/platform/migrations/0003_remove_lessonevent_check_no_overlap_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.6 on 2023-10-05 00:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("platform", "0002_rename_uuid_lessonevent_guid_and_more"), + ] + + operations = [ + migrations.RemoveConstraint( + model_name="lessonevent", + name="check_no_overlap", + ), + migrations.AddConstraint( + model_name="lessonevent", + constraint=models.CheckConstraint( + check=models.Q(("start__lt", models.F("stop"))), name="check_no_overlap" + ), + ), + ] diff --git a/skii/platform/models/event.py b/skii/platform/models/event.py index 67d0212..fc8672b 100644 --- a/skii/platform/models/event.py +++ b/skii/platform/models/event.py @@ -23,12 +23,6 @@ class Meta: CheckConstraint( check=( Q(start__lt=F("stop")) - & ~Q( # Vérifie que start est inférieur à stop - start__range=(F("start"), F("stop")) - ) - & ~Q( # Vérifie qu'il n'y a pas de chevauchement - stop__range=(F("start"), F("stop")) - ) # Vérifie qu'il n'y a pas de chevauchement ), name="check_no_overlap", ), @@ -50,12 +44,12 @@ def gant_config(self): return GanttConfigContract( **{ - "start": self.start.strftime(format="%Y-%m-%d %H:%M"), - "stop": self.stop.strftime(format="%Y-%m-%d %H:%M"), + "startGant": self.start.strftime(format="%Y-%m-%d %H:%M"), + "stopGant": self.stop.strftime(format="%Y-%m-%d %H:%M"), "ganttBarConfig": { - "id": str(self.uuid), + "id": str(self.short_prefix_guid), "hasHandles": True, - "label": self.title, + "label": self.label, "style": { "background": "#e09b69", "color": "black", diff --git a/tests/endpoint/test_api.py b/tests/endpoint/test_api.py index a3c1ec6..e625080 100644 --- a/tests/endpoint/test_api.py +++ b/tests/endpoint/test_api.py @@ -100,4 +100,14 @@ class TestApiLesson(TestApiTeacher): api_save_contract = LessonSaveContract api_route_namespace = "lesson" - fields = [] + fields = [ + 'pk', + 'gant_config', + 'start', + 'stop', + 'teacher', + 'students', + 'label', + 'description' + ] +