Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] ig #1422

Merged
merged 24 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f8340b
Added Channel and OrgAffiliation CRUD operations
aswanthabam Oct 22, 2023
4b7819a
Added pagination for channel and org_affiliation crud operation
aswanthabam Oct 22, 2023
92547fa
Fix: Bugs in Org Affiliation and Channel CRUD
aswanthabam Oct 22, 2023
d9b7730
Fix : bugs
aswanthabam Oct 22, 2023
b7b4876
user table updated
adnankattekaden Oct 23, 2023
6d93091
Merge remote-tracking branch 'origin/dev' into dev
adnankattekaden Oct 23, 2023
463e654
fix(InterestGroupAPI):shorting fixed
anirudh-mk Oct 24, 2023
03e5bfc
fix(InterestGroupApi):post and put
anirudh-mk Oct 24, 2023
3da11e7
Merge pull request #1412 from anirudh-mk/dev
Oct 24, 2023
2324de6
Merge pull request #1395 from aswanthabam/dev
Oct 24, 2023
eff4737
Merge pull request #1413 from gtech-mulearn/dev
Oct 24, 2023
bef57ca
minor fix
adnankattekaden Oct 24, 2023
f762177
Merge branch 'dev' into dev
adnankattekaden Oct 24, 2023
70214f3
Merge pull request #1414 from adnankattekaden/dev
adnankattekaden Oct 24, 2023
af349b3
Merge pull request #1415 from gtech-mulearn/dev
adnankattekaden Oct 24, 2023
44e1750
validate district
adnankattekaden Oct 24, 2023
0412848
Merge pull request #1416 from adnankattekaden/dev
adnankattekaden Oct 24, 2023
b819454
Merge pull request #1417 from gtech-mulearn/dev
adnankattekaden Oct 24, 2023
80d01f8
ig fix
adnankattekaden Oct 24, 2023
095d632
Merge pull request #1418 from adnankattekaden/dev
adnankattekaden Oct 24, 2023
b16fe51
Merge pull request #1419 from gtech-mulearn/dev
adnankattekaden Oct 24, 2023
8fb7a12
minor db
adnankattekaden Oct 24, 2023
0ae26a9
Merge pull request #1420 from adnankattekaden/dev
adnankattekaden Oct 24, 2023
f2077c2
Merge pull request #1421 from gtech-mulearn/dev
adnankattekaden Oct 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json

import requests
from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q
from django.db.models.functions import Coalesce
from rest_framework.views import APIView
Expand Down Expand Up @@ -158,3 +161,35 @@ def get(self, request):
'learning_circle_count': learning_circles_count
}
return CustomResponse(response=data).get_success_response()


class GTASANDSHOREAPI(APIView):
def get(self, request):

response = requests.get('https://devfolio.vez.social/rank')
if response.status_code == 200:
# Save JSON response to a local file
with open('response.json', 'w') as json_file:
json.dump(response.json(), json_file)

with open('response.json', 'r') as file:
data = json.load(file)
else:
with open('response.json', 'r') as file:
data = json.load(file)

# Create a dictionary to store the grouped data
grouped_colleges = {}

for college, count in data.items():
# Clean the college name by removing spaces and converting to lowercase
cleaned_college = college.replace(" ", "").lower()

# Check if the cleaned name already exists in the grouped_colleges dictionary
if cleaned_college in grouped_colleges:
# If it exists, add the count to the existing entry
grouped_colleges[cleaned_college] += int(count)
else:
# If it doesn't exist, create a new entry
grouped_colleges[cleaned_college] = int(count)
return CustomResponse(response=grouped_colleges).get_success_response()
1 change: 1 addition & 0 deletions api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path('college-wise-lc-report/', common_views.CollegeWiseLcReport.as_view()),
path('download/lc-report/', common_views.LcReportDownloadAPI.as_view()),
path('global-count/', common_views.GlobalCountAPI.as_view()),
path('gta-sandshore/',common_views.GTASANDSHOREAPI.as_view())
]
77 changes: 77 additions & 0 deletions api/dashboard/affiliation/affiliation_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from rest_framework.views import APIView
from utils.permission import CustomizePermission,role_required,JWTUtils
from utils.types import RoleType
from .serializers import AffiliationReadSerializer, AffiliationCreateUpdateSerializer
from db.organization import OrgAffiliation
from utils.response import CustomResponse
from utils.utils import CommonUtils

class AffiliationView(APIView):
authentication_classes = [CustomizePermission]


def get(self,request):
all_affiliations = OrgAffiliation.objects.all()
pager_ = CommonUtils.get_paginated_queryset(all_affiliations,request,['title'],sort_fields={'created':'created_at','updated':'updated_at','title':'title'})
serial_ = AffiliationReadSerializer(pager_.get('queryset'),many=True)
# serial_.is_valid()
return CustomResponse().paginated_response(data=serial_.data,pagination=pager_.get("pagination"))

@role_required([RoleType.ADMIN.value])
def post(self,request):
user_id = JWTUtils.fetch_user_id(request)

serial_ = AffiliationCreateUpdateSerializer(data=request.data,context={'user_id':user_id})

if serial_.is_valid():
serial_.save()

return CustomResponse(
general_message=f"{request.data.get('title')} added successfully"
).get_success_response()

return CustomResponse(
general_message=serial_.errors
).get_failure_response()

@role_required([RoleType.ADMIN.value])
def put(self,request,affiliation_id):
user_id = JWTUtils.fetch_user_id(request)
affiliation = OrgAffiliation.objects.filter(id=affiliation_id).first()

if affiliation is None:
return CustomResponse(
general_message="Invalid affiliation"
).get_failure_response()

serializer = AffiliationCreateUpdateSerializer(
affiliation,
data=request.data,
context={
"user_id": user_id
}
)
if serializer.is_valid():
serializer.save()

return CustomResponse(
general_message=f"{affiliation.title} Edited Successfully"
).get_success_response()

return CustomResponse(
message=serializer.errors
).get_failure_response()

@role_required([RoleType.ADMIN.value])
def delete(self,request,affiliation_id):
user_id = JWTUtils.fetch_user_id(request)
affiliation = OrgAffiliation.objects.filter(id=affiliation_id).first()

if affiliation is None:
return CustomResponse(
general_message="Invalid affiliation"
).get_failure_response()
affiliation.delete()
return CustomResponse(
general_message=f"{affiliation.title} Deleted Successfully"
).get_success_response()
37 changes: 37 additions & 0 deletions api/dashboard/affiliation/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from rest_framework import serializers
from db.organization import OrgAffiliation
import uuid

class AffiliationReadSerializer(serializers.ModelSerializer):

title = serializers.ReadOnlyField()
affiliation_id = serializers.ReadOnlyField(source='id')

class Meta:
model = OrgAffiliation
fields = [
"title",
"affiliation_id"
]

class AffiliationCreateUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = OrgAffiliation
fields = [
"title"
]

def create(self, validated_data):
user_id = self.context.get('user_id')
validated_data['created_by_id'] = user_id
validated_data['updated_by_id'] = user_id
validated_data['id'] = uuid.uuid4()
return OrgAffiliation.objects.create(**validated_data)

def update(self, instance, validated_data):
user_id = self.context.get('user_id')
instance.title = validated_data.get('title', instance.title)
instance.updated_by_id = user_id

instance.save()
return instance
10 changes: 10 additions & 0 deletions api/dashboard/affiliation/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path

from . import affiliation_views

urlpatterns = [
path('',affiliation_views.AffiliationView.as_view()),
path('create/',affiliation_views.AffiliationView.as_view()),
path('edit/<str:affiliation_id>/',affiliation_views.AffiliationView.as_view()),
path('delete/<str:affiliation_id>/',affiliation_views.AffiliationView.as_view())
]
76 changes: 76 additions & 0 deletions api/dashboard/channels/channel_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from rest_framework.views import APIView
from utils.permission import CustomizePermission,role_required,JWTUtils
from utils.types import RoleType
from .serializers import ChannelReadSerializer,ChannelCreateUpdateSerializer
from db.task import Channel
from utils.response import CustomResponse
from utils.utils import CommonUtils

class ChannelView(APIView):
authentication_classes = [CustomizePermission]

def get(self,request):
all_channels = Channel.objects.all()
pager_ = CommonUtils.get_paginated_queryset(all_channels,request,['name','discord_id','id'],sort_fields={'created':'created_at','updated':'updated_at','name':'name'})
serial_ = ChannelReadSerializer(pager_.get("queryset"),many=True)
# serial_.is_valid()
return CustomResponse().paginated_response(data=serial_.data,pagination=pager_.get("pagination"))

@role_required([RoleType.ADMIN.value])
def post(self,request):
user_id = JWTUtils.fetch_user_id(request)

serial_ = ChannelCreateUpdateSerializer(data=request.data,context={'user_id':user_id})

if serial_.is_valid():
serial_.save()

return CustomResponse(
general_message=f"{request.data.get('name')} added successfully"
).get_success_response()

return CustomResponse(
general_message=serial_.errors
).get_failure_response()

@role_required([RoleType.ADMIN.value])
def put(self,request,channel_id):
user_id = JWTUtils.fetch_user_id(request)
channel = Channel.objects.filter(id=channel_id).first()

if channel is None:
return CustomResponse(
general_message="Invalid channel"
).get_failure_response()

serializer = ChannelCreateUpdateSerializer(
channel,
data=request.data,
context={
"user_id": user_id
}
)
if serializer.is_valid():
serializer.save()

return CustomResponse(
general_message=f"{channel.name} Edited Successfully"
).get_success_response()

return CustomResponse(
message=serializer.errors
).get_failure_response()

@role_required([RoleType.ADMIN.value])
def delete(self,request,channel_id):
user_id = JWTUtils.fetch_user_id(request)
channel = Channel.objects.filter(id=channel_id).first()

if channel is None:
return CustomResponse(
general_message="Invalid channel"
).get_failure_response()
channel.delete()
return CustomResponse(
general_message=f"{channel.name} Deleted Successfully"
).get_success_response()
48 changes: 48 additions & 0 deletions api/dashboard/channels/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from rest_framework import serializers
from db.task import Channel
from django.utils import timezone
from utils.utils import DateTimeUtils
import uuid
class ChannelReadSerializer(serializers.ModelSerializer):

name = serializers.ReadOnlyField()
discord_id = serializers.ReadOnlyField()
channel_id = serializers.ReadOnlyField(source='id')
updated_at = serializers.ReadOnlyField()
created_at = serializers.ReadOnlyField()

class Meta:
model = Channel
fields = [
"name",
"channel_id",
"discord_id",
"created_at",
"updated_at"
]

class ChannelCreateUpdateSerializer(serializers.ModelSerializer):
class Meta:
model = Channel
fields = [
"name",
"discord_id"
]

def create(self, validated_data):
user_id = self.context.get('user_id')
validated_data['id'] = uuid.uuid4()
validated_data['created_by_id'] = user_id
validated_data['updated_by_id'] = user_id
validated_data['created_at'] = DateTimeUtils.get_current_utc_time()
validated_data['updated_at'] = DateTimeUtils.get_current_utc_time()
return Channel.objects.create(**validated_data)

def update(self, instance, validated_data):
user_id = self.context.get('user_id')
instance.name = validated_data.get('name', instance.name)
instance.discord_id = validated_data.get('discord_id', instance.name)
instance.updated_by_id = user_id
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
return instance
10 changes: 10 additions & 0 deletions api/dashboard/channels/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path

from . import channel_views

urlpatterns = [
path('',channel_views.ChannelView.as_view()),
path('create/',channel_views.ChannelView.as_view()),
path('edit/<str:channel_id>/',channel_views.ChannelView.as_view()),
path('delete/<str:channel_id>/',channel_views.ChannelView.as_view())
]
2 changes: 1 addition & 1 deletion api/dashboard/ig/dash_ig_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ class Meta:
"icon",
"created_by",
"updated_by"
]
]
7 changes: 5 additions & 2 deletions api/dashboard/ig/dash_ig_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def get(self, request):
{
"name": "name",
"updated_on": "updated_at",
"updated_by": "updated_by",
"updated_by": "updated_by__first_name",
"created_on": "created_at",
"created_by": "created_by",
"created_by": "created_by__first_name",
},
)

Expand All @@ -52,7 +52,9 @@ def get(self, request):
@role_required([RoleType.ADMIN.value])
def post(self, request):
user_id = JWTUtils.fetch_user_id(request)

request_data = request.data

request_data["created_by"] = request_data["updated_by"] = user_id

serializer = InterestGroupCreateUpdateSerializer(
Expand All @@ -78,6 +80,7 @@ def post(self, request):
def put(self, request, pk):
user_id = JWTUtils.fetch_user_id(request)
ig = InterestGroup.objects.get(id=pk)

ig_old_name = ig.name

request_data = request.data
Expand Down
Loading