Commit 5fa2c0af authored by Gautier D's avatar Gautier D
Browse files

feat(backend): create viewset for last updated universities

parent 098a9e51
......@@ -82,6 +82,11 @@ class EssentialModule(BaseModel):
abstract = True
# Implemented in children classes
def get_info_string(self):
return None
#
#
#
......
......@@ -50,6 +50,10 @@ class University(EssentialModule):
return {"lat": self.main_campus_lat, "lon": self.main_campus_lon}
def get_info_string(self):
return f"University xx updated"
class UniversitySerializer(EssentialModuleSerializer):
class Meta:
model = University
......
......@@ -387,6 +387,27 @@ class LastVisitedUniversityViewSet(ViewSet):
)
return Response(status=status.HTTP_201_CREATED)
class LastUpdatedUniversityViewSet(ViewSet):
end_point_route = "lastUpdatedUniversities"
permission_classes = (IsAuthenticated,)
def list(self, request):
sql = """
SELECT
id as university,
updated_on
FROM backend_app_university
GROUP BY id
ORDER BY updated_on DESC
LIMIT 10
"""
with connection.cursor() as cursor:
cursor.execute(sql, [request.user.pk])
rows = cursor.fetchall()
data = [{"university": r[0], "updated on": r[1]} for r in rows]
return Response(data, status=status.HTTP_200_OK)
ALL_API_VIEW_VIEWSETS = [
AppModerationStatusViewSet,
......@@ -398,6 +419,7 @@ ALL_API_VIEW_VIEWSETS = [
RecommendationListChangeFollowerViewSet,
DeleteUserViewSet,
LastVisitedUniversityViewSet,
LastUpdatedUniversityViewSet,
]
ALL_VIEWSETS = ALL_API_VIEWSETS + ALL_API_VIEW_VIEWSETS
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment