mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 10:26:16 +00:00
bugs and push notification for create task
This commit is contained in:
@ -75,7 +75,11 @@ ERROR_CODE = {
|
||||
"2042": "Article Card with given id doesn't exist.",
|
||||
"2043": "Article Survey with given id doesn't exist.",
|
||||
"2044": "Task does not exist",
|
||||
"2045": "Invalid guardian"
|
||||
"2045": "Invalid guardian",
|
||||
"2046": "Due date must be future date",
|
||||
"2047": "Invalid Junior ID ",
|
||||
"2048": "Choose right file for image",
|
||||
"2049": "This task is already requested "
|
||||
}
|
||||
"""Success message code"""
|
||||
SUCCESS_CODE = {
|
||||
|
BIN
celerybeat-schedule
Normal file
BIN
celerybeat-schedule
Normal file
Binary file not shown.
@ -169,6 +169,14 @@ class TaskSerializer(serializers.ModelSerializer):
|
||||
"""Meta info"""
|
||||
model = JuniorTask
|
||||
fields = ['id', 'task_name','task_description','points', 'due_date', 'junior', 'default_image']
|
||||
|
||||
def validate_due_date(self, value):
|
||||
"""validation on due date"""
|
||||
if value < datetime.today().date():
|
||||
raise serializers.ValidationError({"details": ERROR_CODE['2046'],
|
||||
"code": 400, "status": "failed",
|
||||
})
|
||||
return value
|
||||
def create(self, validated_data):
|
||||
"""create default task image data"""
|
||||
validated_data['guardian'] = Guardian.objects.filter(user=self.context['user']).last()
|
||||
|
@ -30,7 +30,7 @@ from account.utils import custom_response, custom_error_response
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import NUMBER
|
||||
from .utils import upload_image_to_alibaba
|
||||
from notifications.constants import REGISTRATION
|
||||
from notifications.constants import REGISTRATION, TASK_CREATED
|
||||
from notifications.utils import send_notification
|
||||
|
||||
""" Define APIs """
|
||||
@ -119,6 +119,7 @@ class TaskListAPIView(viewsets.ModelViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
pagination_class = PageNumberPagination
|
||||
queryset = JuniorTask.objects.all()
|
||||
http_method_names = ('get',)
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""Create guardian profile"""
|
||||
@ -146,9 +147,17 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
"""create task for junior"""
|
||||
serializer_class = TaskSerializer
|
||||
queryset = JuniorTask.objects.all()
|
||||
http_method_names = ('post', )
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
image = request.data['default_image']
|
||||
junior = request.data['junior']
|
||||
allowed_extensions = ['.jpg', '.jpeg', '.png']
|
||||
if not any(extension in str(image) for extension in allowed_extensions):
|
||||
return custom_error_response(ERROR_CODE['2048'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
if not junior.isnumeric():
|
||||
"""junior value must be integer"""
|
||||
return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
data = request.data
|
||||
if 'https' in str(image):
|
||||
image_data = image
|
||||
@ -164,6 +173,8 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||
if serializer.is_valid():
|
||||
# save serializer
|
||||
serializer.save()
|
||||
junior_id = Junior.objects.filter(id=junior).last()
|
||||
send_notification.delay(TASK_CREATED, None, junior_id.auth.id, {})
|
||||
return custom_response(SUCCESS_CODE['3018'], serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -172,7 +183,6 @@ class SearchTaskListAPIView(viewsets.ModelViewSet):
|
||||
serializer_class = TaskDetailsSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
pagination_class = PageNumberPagination
|
||||
queryset = JuniorTask.objects.all()
|
||||
|
||||
def get_queryset(self):
|
||||
"""Get the queryset for the view"""
|
||||
|
@ -256,7 +256,10 @@ class CompleteJuniorTaskAPIView(views.APIView):
|
||||
# fetch junior query
|
||||
task_queryset = JuniorTask.objects.filter(id=task_id, junior__auth__email=self.request.user).last()
|
||||
if task_queryset:
|
||||
# use RemoveJuniorSerializer serializer
|
||||
# use CompleteTaskSerializer serializer
|
||||
if task_queryset.task_status in ['4', '5']:
|
||||
"""Already request send """
|
||||
return custom_error_response(ERROR_CODE['2049'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
serializer = CompleteTaskSerializer(task_queryset, data={'image': image_url}, partial=True)
|
||||
if serializer.is_valid():
|
||||
# save serializer
|
||||
|
@ -2,6 +2,7 @@
|
||||
notification constants file
|
||||
"""
|
||||
REGISTRATION = 1
|
||||
TASK_CREATED = 2
|
||||
TEST_NOTIFICATION = 99
|
||||
|
||||
NOTIFICATION_DICT = {
|
||||
@ -9,6 +10,10 @@ NOTIFICATION_DICT = {
|
||||
"title": "Successfully registered!",
|
||||
"body": "You have registered successfully. Now login and complete your profile."
|
||||
},
|
||||
TASK_CREATED: {
|
||||
"title": "Task created!",
|
||||
"body": "Task created successfully."
|
||||
},
|
||||
TEST_NOTIFICATION: {
|
||||
"title": "Test Notification",
|
||||
"body": "This notification is for testing purpose"
|
||||
|
Reference in New Issue
Block a user