19 lines
615 B
Python
19 lines
615 B
Python
from rest_framework.response import Response
|
|
from rest_framework.views import status
|
|
|
|
|
|
def validate_request_data(fn):
|
|
def decorated(*args, **kwargs):
|
|
# args[0] == GenericView Object
|
|
title = args[0].request.data.get("title", "")
|
|
artist = args[0].request.data.get("artist", "")
|
|
if not title and not artist:
|
|
return Response(
|
|
data={
|
|
"message": "Both title and artist are required to add a song"
|
|
},
|
|
status=status.HTTP_400_BAD_REQUEST
|
|
)
|
|
return fn(*args, **kwargs)
|
|
return decorated
|