mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-20 06:24:07 +01:00
Merge branch 'main' into feature/signup
This commit is contained in:
commit
9c9df18b28
@ -52,6 +52,7 @@ INSTALLED_APPS = [
|
|||||||
'tasks',
|
'tasks',
|
||||||
'users',
|
'users',
|
||||||
'authentications',
|
'authentications',
|
||||||
|
'dashboard',
|
||||||
|
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
'drf_spectacular',
|
'drf_spectacular',
|
||||||
|
|||||||
@ -27,4 +27,5 @@ urlpatterns = [
|
|||||||
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
|
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
|
||||||
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
||||||
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
||||||
|
path('api/', include('dashboard.urls')),
|
||||||
]
|
]
|
||||||
0
backend/dashboard/__init__.py
Normal file
0
backend/dashboard/__init__.py
Normal file
3
backend/dashboard/admin.py
Normal file
3
backend/dashboard/admin.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
6
backend/dashboard/apps.py
Normal file
6
backend/dashboard/apps.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class DashboardConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'dashboard'
|
||||||
0
backend/dashboard/migrations/__init__.py
Normal file
0
backend/dashboard/migrations/__init__.py
Normal file
7
backend/dashboard/serializers.py
Normal file
7
backend/dashboard/serializers.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
from .models import UserStats
|
||||||
|
|
||||||
|
class UserStatsSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = UserStats
|
||||||
|
fields = ['health', 'gold', 'experience', 'strength', 'intelligence', 'endurance', 'perception', 'luck', 'level']
|
||||||
3
backend/dashboard/tests.py
Normal file
3
backend/dashboard/tests.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
6
backend/dashboard/urls.py
Normal file
6
backend/dashboard/urls.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.urls import path
|
||||||
|
from .views import DashboardStatsAPIView
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('dashboard/stats/', DashboardStatsAPIView.as_view(), name='dashboard-stats'),
|
||||||
|
]
|
||||||
58
backend/dashboard/views.py
Normal file
58
backend/dashboard/views.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from rest_framework.views import APIView
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from django.db.models import Count
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from tasks.models import Todo, RecurrenceTask
|
||||||
|
|
||||||
|
class DashboardStatsAPIView(APIView):
|
||||||
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
user = request.user
|
||||||
|
|
||||||
|
# Calculate task usage statistics
|
||||||
|
todo_count = Todo.objects.filter(user=user).count()
|
||||||
|
recurrence_task_count = RecurrenceTask.objects.filter(user=user).count()
|
||||||
|
|
||||||
|
# Calculate how many tasks were completed in the last 7 days
|
||||||
|
completed_todo_count_last_week = Todo.objects.filter(user=user, completed=True, last_update__gte=timezone.now() - timezone.timedelta(days=7)).count()
|
||||||
|
completed_recurrence_task_count_last_week = RecurrenceTask.objects.filter(user=user, completed=True, last_update__gte=timezone.now() - timezone.timedelta(days=7)).count()
|
||||||
|
|
||||||
|
# Calculate subtask completion rate
|
||||||
|
total_subtasks = Todo.objects.filter(user=user).aggregate(total=Count('subtask__id'))['total']
|
||||||
|
completed_subtasks = Todo.objects.filter(user=user, subtask__completed=True).aggregate(total=Count('subtask__id'))['total']
|
||||||
|
|
||||||
|
# Calculate overall completion rate
|
||||||
|
total_tasks = todo_count + recurrence_task_count
|
||||||
|
completed_tasks = completed_todo_count_last_week + completed_recurrence_task_count_last_week
|
||||||
|
overall_completion_rate = (completed_tasks / total_tasks) * 100 if total_tasks > 0 else 0
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'todo_count': todo_count,
|
||||||
|
'recurrence_task_count': recurrence_task_count,
|
||||||
|
'completed_todo_count_last_week': completed_todo_count_last_week,
|
||||||
|
'completed_recurrence_task_count_last_week': completed_recurrence_task_count_last_week,
|
||||||
|
'total_subtasks': total_subtasks,
|
||||||
|
'completed_subtasks': completed_subtasks,
|
||||||
|
'overall_completion_rate': overall_completion_rate,
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
# Handle incoming data from the POST request
|
||||||
|
# Update the necessary information based on the data
|
||||||
|
|
||||||
|
task_id = request.data.get('task_id')
|
||||||
|
is_completed = request.data.get('is_completed')
|
||||||
|
|
||||||
|
try:
|
||||||
|
task = Todo.objects.get(id=task_id, user=request.user)
|
||||||
|
task.completed = is_completed
|
||||||
|
task.save()
|
||||||
|
return Response({'message': 'Task completion status updated successfully'}, status=status.HTTP_200_OK)
|
||||||
|
except Todo.DoesNotExist:
|
||||||
|
return Response({'error': 'Task not found'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 4.2.6 on 2023-11-17 16:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('tasks', '0013_alter_recurrencetask_recurrence_rule'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='recurrencetask',
|
||||||
|
name='completed',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='todo',
|
||||||
|
name='completed',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -18,7 +18,6 @@ class Task(models.Model):
|
|||||||
:param title: Title of the task.
|
:param title: Title of the task.
|
||||||
:param notes: Optional additional notes for the task.
|
:param notes: Optional additional notes for the task.
|
||||||
:param tags: Associated tags for the task.
|
:param tags: Associated tags for the task.
|
||||||
:param completed: A boolean field indicating whether the task is completed.
|
|
||||||
:param importance: The importance of the task (range: 1 to 5)
|
:param importance: The importance of the task (range: 1 to 5)
|
||||||
:param difficulty: The difficulty of the task (range: 1 to 5).
|
:param difficulty: The difficulty of the task (range: 1 to 5).
|
||||||
:param challenge: Associated challenge (optional).
|
:param challenge: Associated challenge (optional).
|
||||||
@ -62,12 +61,14 @@ class Todo(Task):
|
|||||||
NOT_IMPORTANT_URGENT = 3, 'Not Important & Urgent'
|
NOT_IMPORTANT_URGENT = 3, 'Not Important & Urgent'
|
||||||
NOT_IMPORTANT_NOT_URGENT = 4, 'Not Important & Not Urgent'
|
NOT_IMPORTANT_NOT_URGENT = 4, 'Not Important & Not Urgent'
|
||||||
|
|
||||||
|
completed = models.BooleanField(default=False)
|
||||||
priority = models.PositiveSmallIntegerField(choices=EisenhowerMatrix.choices, default=EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT)
|
priority = models.PositiveSmallIntegerField(choices=EisenhowerMatrix.choices, default=EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
class RecurrenceTask(Task):
|
class RecurrenceTask(Task):
|
||||||
|
completed = models.BooleanField(default=False)
|
||||||
recurrence_rule = models.CharField()
|
recurrence_rule = models.CharField()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user