Repository: tournesol-app/tournesol

Issue:
Refactor rate later endpoint
Refactor rate_later api
TODO

- [x] use users/me/ endpoint

- [x] update POST payload format.
Payload should not be 

```
{
  "video": {
    "video_id": "string",
    "name": "string",
    "description": "string",
    "publication_date": "2021-10-12",
    "views": 2147483647,
    "uploader": "string",
    "language": "aa"
  }
}
```
but
```
{
  "video": {
    "video_id": "string"
  }
}
```

- [x] Swagger should be perfect


Discussion:

Resolving patch:
diff --git a/backend/tournesol/serializers.py b/backend/tournesol/serializers.py
--- a/backend/tournesol/serializers.py
+++ b/backend/tournesol/serializers.py
@@ -17,6 +17,9 @@ class Meta:
         fields = [
             "video_id", "name", "description", "publication_date", "views", "uploader", "language"
             ]
+        read_only_fields = [
+            "name", "description", "publication_date", "views", "uploader", "language"
+        ]
 
 
 class VideoReadOnlySerializer(Serializer):
diff --git a/backend/tournesol/views/video.py b/backend/tournesol/views/video.py
--- a/backend/tournesol/views/video.py
+++ b/backend/tournesol/views/video.py
@@ -17,7 +17,13 @@
 
 
 class VideoViewSet(viewsets.ModelViewSet):
+    # FIXME: this `queryset` is not used by the implementation
+    # Define `filterset_fields` for filtering?
     queryset = Video.objects.all()
+
+    # FIXME: `VideoSerializer` is not the only serializer used by these views.
+    # And the docs do not reflect the actual schema used in the response.
+    # Override `get_serializer_class` and use default pagination?
     serializer_class = VideoSerializer
     permission_classes = []  # To unlock authentication required
 
@@ -94,11 +100,12 @@ def create(self, request, *args, **kwargs):
         """
         Add a video to the db if it does not already exist
         """
-        if not request.data.get("video_id"):
+        video_id = request.data.get("video_id")
+        if not video_id:
             return Response('No video_id given', status=status.HTTP_400_BAD_REQUEST)
-        if len(request.data.get("video_id")) != 11:
-            return Response("video_id given isn't", status=status.HTTP_400_BAD_REQUEST)
-        if Video.objects.filter(video_id=request.data["video_id"]):
+        if len(video_id) != 11:
+            return Response("video_id is not valid", status=status.HTTP_400_BAD_REQUEST)
+        if Video.objects.filter(video_id=video_id):
             Response(
                 "The video with the id : {id} is already registered".format(
                     id=request.data["video_id"]),
@@ -121,8 +128,7 @@ def create(self, request, *args, **kwargs):
             description = str(yt_info["snippet"]["description"])
             uploader = yt_info["snippet"]["channelTitle"]
             language = compute_video_language(uploader, title, description)
-            data = {
-                "video_id": request.data["video_id"],
+            extra_data = {
                 "name": title,
                 "description": description,
                 "publication_date": published_date,
@@ -130,10 +136,10 @@ def create(self, request, *args, **kwargs):
                 "uploader": uploader,
                 "language": language
             }
-            serializer = VideoSerializer(data=data)
         except AssertionError:
-            serializer = VideoSerializer(data=request.data)
+            extra_data = {}
+        serializer = VideoSerializer(data={"video_id": video_id})
         if serializer.is_valid():
-            serializer.save()
+            serializer.save(**extra_data)
             return Response(serializer.data, status=status.HTTP_201_CREATED)
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
diff --git a/backend/tournesol/views/video_rate_later.py b/backend/tournesol/views/video_rate_later.py
--- a/backend/tournesol/views/video_rate_later.py
+++ b/backend/tournesol/views/video_rate_later.py
@@ -8,7 +8,7 @@
 from rest_framework import generics, mixins, status
 from rest_framework.response import Response
 from rest_framework.permissions import IsAuthenticated
-from drf_spectacular.utils import extend_schema_view, extend_schema
+from drf_spectacular.utils import extend_schema_view, extend_schema, OpenApiResponse
 
 from ..models import Video, VideoRateLater
 from ..serializers import VideoRateLaterSerializer
@@ -31,21 +31,21 @@ def get(self, request, *args, **kwargs):
         """API call to return list of rate_later videos"""
         return self.list(request, *args, **kwargs)
 
+    @extend_schema(
+        responses={
+            200: VideoRateLaterSerializer,
+            404: OpenApiResponse(
+                description="Not Found: the video doesn't exist in the database."
+            ),
+            409: OpenApiResponse(
+                description="Conflict: the video is already in the rate later list,"
+                            " or there is an other error with the database query."
+            )
+        }
+    )
     def post(self, request, *args, **kwargs):
         """
         Add an existing video to a user's rate later list.
-
-        Status code:
-
-            403 Forbidden
-                the logged user is not the target user
-
-            404 Not Found
-                the video doesn't exist in the database
-
-            409 Conflict
-                 the video is already in the rate later list
-                 or there is an other error with the database request
         """
         try:
             video = get_object_or_404(Video, video_id=request.data["video"]["video_id"])


Test patch: