Skip to content

Commit

Permalink
Merge pull request #102 from edly-io/manan/EDLY-7103
Browse files Browse the repository at this point in the history
Added program title duplicate check on update
  • Loading branch information
manan-memon authored Jan 24, 2025
2 parents 8e574d9 + 2fd545a commit d38476b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions course_discovery/apps/api/v1/views/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def create(self, request, *args, **kwargs):
"""
data = request.data.copy()
context = {}
if Program.objects.filter(title=data.get('title')).exists():
if Program.objects.filter(title=data.get('title'), partner=request.site.partner).exists():
return Response(
{"error": f"Program with title '{data.get('title')}' already exists."},
{"title": f"Program with title '{data.get('title')}' already exists."},
status=status.HTTP_400_BAD_REQUEST
)

Expand Down Expand Up @@ -113,6 +113,17 @@ def update(self, request, *args, **kwargs):
status=status.HTTP_404_NOT_FOUND
)

if data.get('title') and (data.get('title') != instance.title):
duplicate_exists = Program.objects.filter(
partner=request.site.partner,
title=data.get('title')
).exclude(uuid=instance.uuid).exists()
if duplicate_exists:
return Response(
{"title": f"Program with title '{data.get('title')}' already exists."},
status=status.HTTP_400_BAD_REQUEST
)

self.prepare_and_set_read_only_data(data, context)

context['request'] = request
Expand Down

0 comments on commit d38476b

Please sign in to comment.