You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
3.7 KiB
Python
142 lines
3.7 KiB
Python
|
|
|
|
from osinacore.models import *
|
|
from rest_framework.views import APIView
|
|
from rest_framework.response import Response
|
|
from rest_framework import status
|
|
from django.contrib.auth.models import User
|
|
from .serializers import *
|
|
|
|
class UserProfilesAPIView(APIView):
|
|
def get(self, request):
|
|
data = []
|
|
|
|
users = User.objects.all()
|
|
|
|
for user in users:
|
|
user_data = {
|
|
"user": UserSerializer(user).data,
|
|
"customer_profile": None,
|
|
"staff_profile": None
|
|
}
|
|
|
|
# Check for customer profile
|
|
customer = CustomerProfile.objects.filter(user=user).first()
|
|
if customer:
|
|
user_data["customer_profile"] = CustomerProfileSerializer(customer).data
|
|
|
|
# Check for staff profile
|
|
staff = StaffProfile.objects.filter(user=user).first()
|
|
if staff:
|
|
user_data["staff_profile"] = StaffProfileSerializer(staff).data
|
|
|
|
data.append(user_data)
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
|
def get_all_business_related_data():
|
|
|
|
business_types = BusinessType.objects.all()
|
|
departments = Department.objects.all()
|
|
job_positions = JobPosition.objects.all()
|
|
|
|
business_types_data = BusinessTypeSerializer(business_types, many=True).data
|
|
departments_data = DepartmentSerializer(departments, many=True).data
|
|
job_positions_data = JobPositionSerializer(job_positions, many=True).data
|
|
|
|
return {
|
|
'business_types': business_types_data,
|
|
'departments': departments_data,
|
|
'job_positions': job_positions_data,
|
|
}
|
|
|
|
|
|
class BusinessDataAPIView(APIView):
|
|
|
|
def get(self, request):
|
|
data = get_all_business_related_data()
|
|
return Response(data)
|
|
|
|
|
|
class ProjectsAPIView(APIView):
|
|
def get(self, request):
|
|
data = []
|
|
|
|
projects = Project.objects.all()
|
|
|
|
for project in projects:
|
|
project_data = ProjectSerializer(project).data
|
|
|
|
|
|
data.append(project_data)
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
|
class EpicsAPIView(APIView):
|
|
def get(self, request):
|
|
data = []
|
|
|
|
epics = Epic.objects.all()
|
|
|
|
for epic in epics:
|
|
epic_data = EpicSerializer(epic).data
|
|
|
|
|
|
data.append(epic_data)
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
|
|
|
class MileStoneAPIView(APIView):
|
|
def get(self, request):
|
|
data = []
|
|
|
|
milestones = Milestone.objects.all()
|
|
|
|
for milestone in milestones:
|
|
milestone_data = MileStoneSerializer(milestone).data
|
|
|
|
|
|
data.append(milestone_data)
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
|
class UserStoryAPIView(APIView):
|
|
def get(self, request):
|
|
data = []
|
|
|
|
userstories = UserStory.objects.all()
|
|
|
|
for userstory in userstories:
|
|
user_story_data = UserStorySerializer(userstory).data
|
|
|
|
|
|
data.append(user_story_data)
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
|
class TaskAPIView(APIView):
|
|
def get(self, request, project_id):
|
|
try:
|
|
project = Project.objects.get(id=project_id)
|
|
except Project.DoesNotExist:
|
|
return Response({"error": "Project not found"}, status=status.HTTP_404_NOT_FOUND)
|
|
|
|
tasks = Task.objects.filter(project=project)
|
|
data = TaskSerializer(tasks, many=True).data
|
|
|
|
return Response(data, status=status.HTTP_200_OK)
|
|
|
|
|
|
class DailyReportAPIView(APIView):
|
|
def get(self, request):
|
|
|
|
dailyreport = DailyReport.objects.all()
|
|
data = DailyReportSerializer(dailyreport, many=True).data
|
|
|
|
return Response(data, status=status.HTTP_200_OK) |