Code-dig-ger/Backend

feat: Enrolled Model to store user has enrolled to which lists

Closed this issue · 4 comments

Users can enroll themselves in any public lists and solve the problems from that list and can track their progress.

Enrolled Model

User: Foreign Key
List: Foreign Key

Routes :

  • User can enroll in any Public List/ Self List.
  • User can view all the enrolled lists.

/cib enrolled

can enroll in any Public List

User Authenticate
Public List
(List should be public, user should be authenticated, user should not enrolled before)

User can see his enrolled lists
Authenticated User
GetUserlistSerializer

user = self.request.user
        enroll_list_ids = Enrolled.objects.filter(enroll_user = user).values_list('enroll_list', flat=True)
        List.objects.filter(id__in = enroll_list_ids)
        res_lists = GetUserlistSerializer(lists, many=True).data
        return response.Response({'status': 'OK', 'result': res_lists})

try:
            curr_list = List.objects.get(slug=list)
        except: 
            raise ValidationException(
                "List with the provided slug does not exist")

        if not curr_list.public:
            raise ValidationException("List is not public or doesn't exist")

        Enrolled.objects.get_or_create(enroll_list=curr_list, enroll_user = user)