• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gcivil-nyu-org / team2-wed-spring25 / 859

23 Apr 2025 01:52PM UTC coverage: 87.903% (-3.0%) from 90.945%
859

Pull #360

travis-pro

web-flow
Merge 1161be77f into 804524f90
Pull Request #360: Develop yd debug

45 of 134 new or added lines in 7 files covered. (33.58%)

29 existing lines in 2 files now uncovered.

3001 of 3414 relevant lines covered (87.9%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.69
/backend/nightwalkers/notifications/views.py
1
# notifications/views.py
2
from django.http import JsonResponse
1✔
3
from django.views.decorators.csrf import csrf_exempt
1✔
4
from notifications import notification_service
1✔
5
import json
1✔
6

7

8
@csrf_exempt
1✔
9
def send_notification(request):
1✔
NEW
10
    if request.method == "POST":
×
NEW
11
        try:
×
NEW
12
            data = json.loads(request.body)
×
NEW
13
            user_id = data.get("user_id")
×
NEW
14
            title = data.get("title")
×
NEW
15
            body = data.get("body")
×
NEW
16
            extra_data = data.get("data", {})
×
NEW
17
            print(f"Received data: {data}")  # Debugging line
×
NEW
18
            if not all([user_id, title, body]):
×
NEW
19
                print("Missing required fields")  # Debugging line
×
NEW
20
                return JsonResponse(
×
21
                    {"error": "Missing required fields (user_id, title, body)"},
22
                    status=400,
23
                )
NEW
24
            print(f"Sending notification to user {user_id}")  # Debugging line
×
NEW
25
            success = notification_service.send_to_user(
×
26
                user_id=user_id, title=title, body=body, data=extra_data
27
            )
NEW
28
            print(f"Notification sent: {success}")  # Debugging line
×
29

NEW
30
            if success:
×
NEW
31
                return JsonResponse({"status": "Notification sent successfully"})
×
32

NEW
33
            return JsonResponse({"error": "Failed to send notification"}, status=400)
×
34

NEW
35
        except json.JSONDecodeError:
×
NEW
36
            return JsonResponse({"error": "Invalid JSON payload"}, status=400)
×
NEW
37
        except Exception as e:
×
NEW
38
            print(f"Server error: {str(e)}")
×
NEW
39
            return JsonResponse({"error": f"Server error: {str(e)}"}, status=500)
×
40

NEW
41
    return JsonResponse({"error": "Only POST requests are allowed"}, status=405)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc