From 4f8340b408060312cd7506f9c85058ff6c13e70c Mon Sep 17 00:00:00 2001 From: aswanthabam Date: Sun, 22 Oct 2023 19:49:13 +0530 Subject: [PATCH 1/6] Added Channel and OrgAffiliation CRUD operations --- .../affiliation/affiliation_views.py | 86 +++ api/dashboard/affiliation/serializers.py | 36 + api/dashboard/affiliation/urls.py | 10 + api/dashboard/channels/channel_views.py | 86 +++ api/dashboard/channels/serializers.py | 47 ++ api/dashboard/channels/urls.py | 10 + api/dashboard/urls.py | 2 + hello.py | 719 ++++++++++++++++++ 8 files changed, 996 insertions(+) create mode 100644 api/dashboard/affiliation/affiliation_views.py create mode 100644 api/dashboard/affiliation/serializers.py create mode 100644 api/dashboard/affiliation/urls.py create mode 100644 api/dashboard/channels/channel_views.py create mode 100644 api/dashboard/channels/serializers.py create mode 100644 api/dashboard/channels/urls.py create mode 100644 hello.py diff --git a/api/dashboard/affiliation/affiliation_views.py b/api/dashboard/affiliation/affiliation_views.py new file mode 100644 index 00000000..21d82d28 --- /dev/null +++ b/api/dashboard/affiliation/affiliation_views.py @@ -0,0 +1,86 @@ +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 + +class AffiliationGetView(APIView): + authentication_classes = [CustomizePermission] + + + def get(self,request): + all_affiliations = OrgAffiliation.objects.all() + + serial_ = AffiliationReadSerializer(data=all_affiliations,many=True) + serial_.is_valid() + return CustomResponse(response=serial_.data).get_success_response() + +class AffiliationAddView(APIView): + authentication_classes = [CustomizePermission] + + @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() + + +class AffiliationEditView(APIView): + authentication_classes = [CustomizePermission] + + @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() + +class AffiliationDeleteView(APIView): + authentication_classes = [CustomizePermission] + + @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() \ No newline at end of file diff --git a/api/dashboard/affiliation/serializers.py b/api/dashboard/affiliation/serializers.py new file mode 100644 index 00000000..664a6260 --- /dev/null +++ b/api/dashboard/affiliation/serializers.py @@ -0,0 +1,36 @@ +from rest_framework import serializers +from db.organization import OrgAffiliation + +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 + + 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 \ No newline at end of file diff --git a/api/dashboard/affiliation/urls.py b/api/dashboard/affiliation/urls.py new file mode 100644 index 00000000..a67e12ea --- /dev/null +++ b/api/dashboard/affiliation/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import affiliation_views + +urlpatterns = [ + path('',affiliation_views.AffiliationGetView.as_view()), + path('create/',affiliation_views.AffiliationAddView.as_view()), + path('edit//',affiliation_views.AffiliationEditView.as_view()), + path('delete//',affiliation_views.AffiliationDeleteView.as_view()) +] diff --git a/api/dashboard/channels/channel_views.py b/api/dashboard/channels/channel_views.py new file mode 100644 index 00000000..9cc2c53e --- /dev/null +++ b/api/dashboard/channels/channel_views.py @@ -0,0 +1,86 @@ +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 + +class ChannelGetView(APIView): + authentication_classes = [CustomizePermission] + + + def get(self,request): + all_channels = Channel.objects.all() + + serial_ = ChannelReadSerializer(data=all_channels,many=True) + serial_.is_valid() + return CustomResponse(response=serial_.data).get_success_response() + +class ChannelAddView(APIView): + authentication_classes = [CustomizePermission] + + @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() + + +class ChannelEditView(APIView): + authentication_classes = [CustomizePermission] + + @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() + +class ChannelDeleteView(APIView): + authentication_classes = [CustomizePermission] + + @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() \ No newline at end of file diff --git a/api/dashboard/channels/serializers.py b/api/dashboard/channels/serializers.py new file mode 100644 index 00000000..235d6b52 --- /dev/null +++ b/api/dashboard/channels/serializers.py @@ -0,0 +1,47 @@ +from rest_framework import serializers +from db.task import Channel +from django.utils import timezone +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'] = timezone.now() + validated_data['updated_at'] = timezone.now() + 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 = timezone.now() + instance.save() + return instance \ No newline at end of file diff --git a/api/dashboard/channels/urls.py b/api/dashboard/channels/urls.py new file mode 100644 index 00000000..2c7d5e1c --- /dev/null +++ b/api/dashboard/channels/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import channel_views + +urlpatterns = [ + path('',channel_views.ChannelGetView.as_view()), + path('create/',channel_views.ChannelAddView.as_view()), + path('edit//',channel_views.ChannelEditView.as_view()), + path('delete//',channel_views.ChannelDeleteView.as_view()) +] diff --git a/api/dashboard/urls.py b/api/dashboard/urls.py index a2151839..3c46702a 100644 --- a/api/dashboard/urls.py +++ b/api/dashboard/urls.py @@ -18,4 +18,6 @@ path('organisation/', include('api.dashboard.organisation.urls')), path('dynamic-management/', include('api.dashboard.dynamic_management.urls')), path('error-log/', include('api.dashboard.error_log.urls')), + path('affiliation/',include('api.dashboard.affiliation.urls')), + path('channels/',include('api.dashboard.channels.urls')) ] diff --git a/hello.py b/hello.py new file mode 100644 index 00000000..9cae60e1 --- /dev/null +++ b/hello.py @@ -0,0 +1,719 @@ +# This is an auto-generated Django model module. +# You'll have to do the following manually to clean this up: +# * Rearrange models' order +# * Make sure each model has one field with primary_key=True +# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior +# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table +# Feel free to rename the models, but don't rename db_table values or field names. +from django.db import models + + +class Channel(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(unique=True, max_length=75) + discord_id = models.CharField(max_length=36) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'channel' + + +class College(models.Model): + id = models.CharField(primary_key=True, max_length=36) + level = models.IntegerField() + org = models.ForeignKey('Organization', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'college' + + +class Country(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'country' + + +class Department(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'department' + + +class Device(models.Model): + id = models.CharField(primary_key=True, max_length=36) + browser = models.CharField(max_length=36) + os = models.CharField(max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + last_log_in = models.DateTimeField() + + class Meta: + managed = False + db_table = 'device' + + +class District(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + zone = models.ForeignKey('Zone', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'district' + + +class DynamicRole(models.Model): + id = models.CharField(primary_key=True, max_length=36) + type = models.CharField(max_length=50) + role = models.ForeignKey('Role', models.DO_NOTHING, db_column='role') + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'dynamic_role' + + +class DynamicUser(models.Model): + id = models.CharField(primary_key=True, max_length=36) + type = models.CharField(max_length=50) + user = models.ForeignKey('User', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'dynamic_user' + + +class ForgotPassword(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + expiry = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'forgot_password' + + +class Hackathon(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + tagline = models.CharField(max_length=150, blank=True, null=True) + description = models.CharField(max_length=5000, blank=True, null=True) + participant_count = models.IntegerField(blank=True, null=True) + type = models.CharField(max_length=8, blank=True, null=True) + website = models.CharField(max_length=200, blank=True, null=True) + org = models.ForeignKey('Organization', models.DO_NOTHING, blank=True, null=True) + district = models.ForeignKey(District, models.DO_NOTHING, blank=True, null=True) + place = models.CharField(max_length=255, blank=True, null=True) + event_logo = models.CharField(max_length=200, blank=True, null=True) + banner = models.CharField(max_length=200, blank=True, null=True) + is_open_to_all = models.IntegerField(blank=True, null=True) + application_start = models.DateTimeField(blank=True, null=True) + application_ends = models.DateTimeField(blank=True, null=True) + event_start = models.DateTimeField(blank=True, null=True) + event_end = models.DateTimeField(blank=True, null=True) + status = models.CharField(max_length=20, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon' + + +class HackathonForm(models.Model): + id = models.CharField(primary_key=True, max_length=36) + hackathon = models.ForeignKey(Hackathon, models.DO_NOTHING) + field_name = models.CharField(max_length=255) + field_type = models.CharField(max_length=50) + is_required = models.IntegerField(blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon_form' + + +class HackathonOrganiserLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + organiser = models.ForeignKey('User', models.DO_NOTHING) + hackathon = models.ForeignKey(Hackathon, models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon_organiser_link' + + +class HackathonSubmission(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.OneToOneField('User', models.DO_NOTHING) + hackathon = models.ForeignKey(Hackathon, models.DO_NOTHING) + data = models.CharField(max_length=2000) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'hackathon_submission' + + +class Integration(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=255) + token = models.CharField(max_length=400) + created_at = models.DateTimeField() + updated_at = models.DateTimeField() + auth_token = models.CharField(max_length=255, blank=True, null=True) + base_url = models.CharField(max_length=255, blank=True, null=True) + + class Meta: + managed = False + db_table = 'integration' + + +class IntegrationAuthorization(models.Model): + id = models.CharField(primary_key=True, max_length=36) + integration = models.ForeignKey(Integration, models.DO_NOTHING) + user = models.OneToOneField('User', models.DO_NOTHING) + integration_value = models.CharField(unique=True, max_length=255) + additional_field = models.CharField(max_length=255, blank=True, null=True) + verified = models.IntegerField() + updated_at = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'integration_authorization' + unique_together = (('integration', 'user', 'integration_value'),) + + +class InterestGroup(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + code = models.CharField(unique=True, max_length=5, blank=True, null=True) + icon = models.CharField(max_length=10, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'interest_group' + + +class IntroTaskLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + progress = models.IntegerField() + channel_id = models.CharField(max_length=36, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'intro_task_log' + + +class KarmaActivityLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + karma = models.IntegerField() + task = models.ForeignKey('TaskList', models.DO_NOTHING) + task_message_id = models.CharField(max_length=36) + lobby_message_id = models.CharField(max_length=36, blank=True, null=True) + dm_message_id = models.CharField(max_length=36, blank=True, null=True) + peer_approved = models.IntegerField(blank=True, null=True) + peer_approved_by = models.CharField(max_length=36, blank=True, null=True) + appraiser_approved = models.IntegerField(blank=True, null=True) + appraiser_approved_by = models.CharField(max_length=36, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'karma_activity_log' + + +class LearningCircle(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=255) + circle_code = models.CharField(unique=True, max_length=15, blank=True, null=True) + ig = models.ForeignKey(InterestGroup, models.DO_NOTHING) + org = models.ForeignKey('Organization', models.DO_NOTHING, blank=True, null=True) + meet_place = models.CharField(max_length=255, blank=True, null=True) + meet_time = models.DateTimeField(blank=True, null=True) + day = models.CharField(max_length=20, blank=True, null=True) + note = models.CharField(max_length=500, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'learning_circle' + + +class Level(models.Model): + id = models.CharField(primary_key=True, max_length=36) + level_order = models.IntegerField() + name = models.CharField(unique=True, max_length=36) + karma = models.IntegerField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'level' + + +class MucoinActivityLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + coin = models.FloatField() + status = models.CharField(max_length=36) + task = models.ForeignKey('TaskList', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by', blank=True, null=True) + updated_at = models.DateTimeField(blank=True, null=True) + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by', blank=True, null=True) + created_at = models.DateTimeField(blank=True, null=True) + + class Meta: + managed = False + db_table = 'mucoin_activity_log' + + +class MucoinInviteLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + email = models.CharField(max_length=200) + invite_code = models.CharField(max_length=36) + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'mucoin_invite_log' + + +class Notification(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + title = models.CharField(max_length=50) + description = models.CharField(max_length=200) + button = models.CharField(max_length=10, blank=True, null=True) + url = models.CharField(max_length=100, blank=True, null=True) + created_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + + class Meta: + managed = False + db_table = 'notification' + + +class OrgAffiliation(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'org_affiliation' + + +class OrgDiscordLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + discord_id = models.CharField(unique=True, max_length=36) + org = models.OneToOneField('Organization', models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'org_discord_link' + + +class Organization(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + code = models.CharField(unique=True, max_length=12) + org_type = models.CharField(max_length=25) + affiliation = models.ForeignKey(OrgAffiliation, models.DO_NOTHING, blank=True, null=True) + district = models.ForeignKey(District, models.DO_NOTHING, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'organization' + + +class OtpVerification(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + otp = models.IntegerField() + expiry = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'otp_verification' + + +class Role(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + description = models.CharField(max_length=300, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'role' + + +class Socials(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey('User', models.DO_NOTHING) + github = models.CharField(max_length=60, blank=True, null=True) + facebook = models.CharField(max_length=60, blank=True, null=True) + instagram = models.CharField(max_length=60, blank=True, null=True) + linkedin = models.CharField(max_length=60, blank=True, null=True) + dribble = models.CharField(max_length=60, blank=True, null=True) + behance = models.CharField(max_length=60, blank=True, null=True) + stackoverflow = models.CharField(max_length=60, blank=True, null=True) + medium = models.CharField(max_length=60, blank=True, null=True) + updated_by = models.CharField(max_length=36) + updated_at = models.DateTimeField(blank=True, null=True) + created_by = models.CharField(max_length=36, blank=True, null=True) + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'socials' + + +class State(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + country = models.ForeignKey(Country, models.DO_NOTHING) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'state' + + +class SystemSetting(models.Model): + key = models.CharField(primary_key=True, max_length=100) + value = models.CharField(max_length=100) + updated_at = models.DateTimeField() + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'system_setting' + + +class TaskList(models.Model): + id = models.CharField(primary_key=True, max_length=36) + hashtag = models.CharField(max_length=75) + discord_link = models.CharField(max_length=200, blank=True, null=True) + title = models.CharField(max_length=75) + description = models.CharField(max_length=200, blank=True, null=True) + karma = models.IntegerField(blank=True, null=True) + channel = models.ForeignKey(Channel, models.DO_NOTHING, blank=True, null=True) + type = models.ForeignKey('TaskType', models.DO_NOTHING) + org = models.ForeignKey(Organization, models.DO_NOTHING, blank=True, null=True) + level = models.ForeignKey(Level, models.DO_NOTHING, blank=True, null=True) + ig = models.ForeignKey(InterestGroup, models.DO_NOTHING, blank=True, null=True) + active = models.IntegerField() + variable_karma = models.IntegerField() + usage_count = models.IntegerField(blank=True, null=True) + event = models.CharField(max_length=50, blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'task_list' + + +class TaskType(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=75) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'task_type' + + +class UrlShortener(models.Model): + id = models.CharField(primary_key=True, max_length=36) + title = models.CharField(max_length=100) + short_url = models.CharField(unique=True, max_length=100) + long_url = models.CharField(max_length=500) + count = models.IntegerField(blank=True, null=True) + updated_by = models.ForeignKey('User', models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey('User', models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'url_shortener' + + +class UrlShortenerTracker(models.Model): + id = models.CharField(primary_key=True, max_length=36) + url_shortener = models.ForeignKey(UrlShortener, models.DO_NOTHING, blank=True, null=True) + ip_address = models.CharField(max_length=45, blank=True, null=True) + browser = models.CharField(max_length=255, blank=True, null=True) + operating_system = models.CharField(max_length=255, blank=True, null=True) + version = models.CharField(max_length=255, blank=True, null=True) + device_type = models.CharField(max_length=255, blank=True, null=True) + city = models.CharField(max_length=36, blank=True, null=True) + region = models.CharField(max_length=36, blank=True, null=True) + country = models.CharField(max_length=36, blank=True, null=True) + location = models.CharField(max_length=36, blank=True, null=True) + referrer = models.CharField(max_length=36, blank=True, null=True) + + class Meta: + managed = False + db_table = 'url_shortener_tracker' + + +class User(models.Model): + id = models.CharField(primary_key=True, max_length=36) + discord_id = models.CharField(unique=True, max_length=36, blank=True, null=True) + muid = models.CharField(unique=True, max_length=100) + first_name = models.CharField(max_length=75) + last_name = models.CharField(max_length=75, blank=True, null=True) + email = models.CharField(unique=True, max_length=200) + password = models.CharField(max_length=200, blank=True, null=True) + mobile = models.CharField(max_length=15) + gender = models.CharField(max_length=10, blank=True, null=True) + dob = models.DateField(blank=True, null=True) + admin = models.IntegerField() + active = models.IntegerField() + exist_in_guild = models.IntegerField() + created_at = models.DateTimeField() + profile_pic = models.CharField(max_length=200, blank=True, null=True) + + class Meta: + managed = False + db_table = 'user' + + +class UserCircleLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + circle = models.ForeignKey(LearningCircle, models.DO_NOTHING) + lead = models.IntegerField(blank=True, null=True) + accepted = models.IntegerField(blank=True, null=True) + accepted_at = models.DateTimeField(blank=True, null=True) + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_circle_link' + + +class UserIgLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + ig = models.ForeignKey(InterestGroup, models.DO_NOTHING) + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_ig_link' + + +class UserLvlLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.OneToOneField(User, models.DO_NOTHING) + level = models.ForeignKey(Level, models.DO_NOTHING) + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_lvl_link' + + +class UserOrganizationLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + org = models.ForeignKey(Organization, models.DO_NOTHING) + department = models.ForeignKey(Department, models.DO_NOTHING, blank=True, null=True) + graduation_year = models.CharField(max_length=10, blank=True, null=True) + verified = models.IntegerField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_organization_link' + + +class UserReferralLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + referral = models.ForeignKey(User, models.DO_NOTHING) + is_coin = models.IntegerField(blank=True, null=True) + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_referral_link' + + +class UserRoleLink(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + role = models.ForeignKey(Role, models.DO_NOTHING) + verified = models.IntegerField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_role_link' + + +class UserSettings(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.ForeignKey(User, models.DO_NOTHING) + is_public = models.IntegerField() + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'user_settings' + + +class VoucherLog(models.Model): + id = models.CharField(primary_key=True, max_length=36) + code = models.CharField(max_length=15) + user = models.ForeignKey(User, models.DO_NOTHING) + task = models.ForeignKey(TaskList, models.DO_NOTHING) + karma = models.IntegerField() + week = models.CharField(max_length=2) + month = models.CharField(max_length=10) + claimed = models.IntegerField() + updated_by = models.CharField(max_length=36) + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'voucher_log' + + +class Wallet(models.Model): + id = models.CharField(primary_key=True, max_length=36) + user = models.OneToOneField(User, models.DO_NOTHING) + karma = models.BigIntegerField() + coin = models.IntegerField() + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'wallet' + + +class Zone(models.Model): + id = models.CharField(primary_key=True, max_length=36) + name = models.CharField(max_length=75) + state = models.ForeignKey(State, models.DO_NOTHING) + updated_by = models.ForeignKey(User, models.DO_NOTHING, db_column='updated_by') + updated_at = models.DateTimeField() + created_by = models.ForeignKey(User, models.DO_NOTHING, db_column='created_by') + created_at = models.DateTimeField() + + class Meta: + managed = False + db_table = 'zone' From 4b7819a6c4d8ed592c4cd54c3f4e98424fdc8ba3 Mon Sep 17 00:00:00 2001 From: aswanthabam Date: Sun, 22 Oct 2023 21:19:07 +0530 Subject: [PATCH 2/6] Added pagination for channel and org_affiliation crud operation --- api/dashboard/affiliation/affiliation_views.py | 5 +++-- api/dashboard/channels/channel_views.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/dashboard/affiliation/affiliation_views.py b/api/dashboard/affiliation/affiliation_views.py index 21d82d28..4801c353 100644 --- a/api/dashboard/affiliation/affiliation_views.py +++ b/api/dashboard/affiliation/affiliation_views.py @@ -4,6 +4,7 @@ from .serializers import AffiliationReadSerializer, AffiliationCreateUpdateSerializer from db.organization import OrgAffiliation from utils.response import CustomResponse +from utils.utils import CommonUtils class AffiliationGetView(APIView): authentication_classes = [CustomizePermission] @@ -11,8 +12,8 @@ class AffiliationGetView(APIView): def get(self,request): all_affiliations = OrgAffiliation.objects.all() - - serial_ = AffiliationReadSerializer(data=all_affiliations,many=True) + pager_ = CommonUtils.get_paginated_queryset(all_affiliations,request,['title']) + serial_ = AffiliationReadSerializer(data=pager_.get('queryset'),many=True) serial_.is_valid() return CustomResponse(response=serial_.data).get_success_response() diff --git a/api/dashboard/channels/channel_views.py b/api/dashboard/channels/channel_views.py index 9cc2c53e..8744e493 100644 --- a/api/dashboard/channels/channel_views.py +++ b/api/dashboard/channels/channel_views.py @@ -4,15 +4,15 @@ from .serializers import ChannelReadSerializer,ChannelCreateUpdateSerializer from db.task import Channel from utils.response import CustomResponse +from utils.utils import CommonUtils class ChannelGetView(APIView): authentication_classes = [CustomizePermission] - def get(self,request): all_channels = Channel.objects.all() - - serial_ = ChannelReadSerializer(data=all_channels,many=True) + pager_ = CommonUtils.get_paginated_queryset(all_channels,request,['name','discord_id','id']) + serial_ = ChannelReadSerializer(data=pager_.get("queryset"),many=True) serial_.is_valid() return CustomResponse(response=serial_.data).get_success_response() From 92547fa22279f69c785364ba55223c225b38f2c1 Mon Sep 17 00:00:00 2001 From: aswanthabam Date: Sun, 22 Oct 2023 22:47:00 +0530 Subject: [PATCH 3/6] Fix: Bugs in Org Affiliation and Channel CRUD --- api/dashboard/affiliation/affiliation_views.py | 18 ++++-------------- api/dashboard/affiliation/serializers.py | 3 ++- api/dashboard/affiliation/urls.py | 8 ++++---- api/dashboard/channels/channel_views.py | 16 +++------------- api/dashboard/channels/urls.py | 8 ++++---- 5 files changed, 17 insertions(+), 36 deletions(-) diff --git a/api/dashboard/affiliation/affiliation_views.py b/api/dashboard/affiliation/affiliation_views.py index 4801c353..d5ef2bf0 100644 --- a/api/dashboard/affiliation/affiliation_views.py +++ b/api/dashboard/affiliation/affiliation_views.py @@ -6,20 +6,17 @@ from utils.response import CustomResponse from utils.utils import CommonUtils -class AffiliationGetView(APIView): +class AffiliationView(APIView): authentication_classes = [CustomizePermission] def get(self,request): all_affiliations = OrgAffiliation.objects.all() pager_ = CommonUtils.get_paginated_queryset(all_affiliations,request,['title']) - serial_ = AffiliationReadSerializer(data=pager_.get('queryset'),many=True) - serial_.is_valid() + serial_ = AffiliationReadSerializer(pager_.get('queryset'),many=True) + # serial_.is_valid() return CustomResponse(response=serial_.data).get_success_response() - -class AffiliationAddView(APIView): - authentication_classes = [CustomizePermission] - + @role_required([RoleType.ADMIN.value]) def post(self,request): user_id = JWTUtils.fetch_user_id(request) @@ -37,10 +34,6 @@ def post(self,request): general_message=serial_.errors ).get_failure_response() - -class AffiliationEditView(APIView): - authentication_classes = [CustomizePermission] - @role_required([RoleType.ADMIN.value]) def put(self,request,affiliation_id): user_id = JWTUtils.fetch_user_id(request) @@ -69,9 +62,6 @@ def put(self,request,affiliation_id): message=serializer.errors ).get_failure_response() -class AffiliationDeleteView(APIView): - authentication_classes = [CustomizePermission] - @role_required([RoleType.ADMIN.value]) def delete(self,request,affiliation_id): user_id = JWTUtils.fetch_user_id(request) diff --git a/api/dashboard/affiliation/serializers.py b/api/dashboard/affiliation/serializers.py index 664a6260..793e30d0 100644 --- a/api/dashboard/affiliation/serializers.py +++ b/api/dashboard/affiliation/serializers.py @@ -1,5 +1,6 @@ from rest_framework import serializers from db.organization import OrgAffiliation +import uuid class AffiliationReadSerializer(serializers.ModelSerializer): @@ -24,7 +25,7 @@ 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): diff --git a/api/dashboard/affiliation/urls.py b/api/dashboard/affiliation/urls.py index a67e12ea..7cfb05ee 100644 --- a/api/dashboard/affiliation/urls.py +++ b/api/dashboard/affiliation/urls.py @@ -3,8 +3,8 @@ from . import affiliation_views urlpatterns = [ - path('',affiliation_views.AffiliationGetView.as_view()), - path('create/',affiliation_views.AffiliationAddView.as_view()), - path('edit//',affiliation_views.AffiliationEditView.as_view()), - path('delete//',affiliation_views.AffiliationDeleteView.as_view()) + path('',affiliation_views.AffiliationView.as_view()), + path('create/',affiliation_views.AffiliationView.as_view()), + path('edit//',affiliation_views.AffiliationView.as_view()), + path('delete//',affiliation_views.AffiliationView.as_view()) ] diff --git a/api/dashboard/channels/channel_views.py b/api/dashboard/channels/channel_views.py index 8744e493..ced529a1 100644 --- a/api/dashboard/channels/channel_views.py +++ b/api/dashboard/channels/channel_views.py @@ -6,19 +6,16 @@ from utils.response import CustomResponse from utils.utils import CommonUtils -class ChannelGetView(APIView): +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']) - serial_ = ChannelReadSerializer(data=pager_.get("queryset"),many=True) - serial_.is_valid() + serial_ = ChannelReadSerializer(pager_.get("queryset"),many=True) + # serial_.is_valid() return CustomResponse(response=serial_.data).get_success_response() -class ChannelAddView(APIView): - authentication_classes = [CustomizePermission] - @role_required([RoleType.ADMIN.value]) def post(self,request): user_id = JWTUtils.fetch_user_id(request) @@ -36,10 +33,6 @@ def post(self,request): general_message=serial_.errors ).get_failure_response() - -class ChannelEditView(APIView): - authentication_classes = [CustomizePermission] - @role_required([RoleType.ADMIN.value]) def put(self,request,channel_id): user_id = JWTUtils.fetch_user_id(request) @@ -68,9 +61,6 @@ def put(self,request,channel_id): message=serializer.errors ).get_failure_response() -class ChannelDeleteView(APIView): - authentication_classes = [CustomizePermission] - @role_required([RoleType.ADMIN.value]) def delete(self,request,channel_id): user_id = JWTUtils.fetch_user_id(request) diff --git a/api/dashboard/channels/urls.py b/api/dashboard/channels/urls.py index 2c7d5e1c..c466b0ab 100644 --- a/api/dashboard/channels/urls.py +++ b/api/dashboard/channels/urls.py @@ -3,8 +3,8 @@ from . import channel_views urlpatterns = [ - path('',channel_views.ChannelGetView.as_view()), - path('create/',channel_views.ChannelAddView.as_view()), - path('edit//',channel_views.ChannelEditView.as_view()), - path('delete//',channel_views.ChannelDeleteView.as_view()) + path('',channel_views.ChannelView.as_view()), + path('create/',channel_views.ChannelView.as_view()), + path('edit//',channel_views.ChannelView.as_view()), + path('delete//',channel_views.ChannelView.as_view()) ] From d9b7730b17d7a5a309fbcd29726f5cdfe6377c35 Mon Sep 17 00:00:00 2001 From: aswanthabam Date: Sun, 22 Oct 2023 23:28:44 +0530 Subject: [PATCH 4/6] Fix : bugs Add: Org affiliation&Channels pagination search optins --- api/dashboard/affiliation/affiliation_views.py | 4 ++-- api/dashboard/channels/channel_views.py | 4 ++-- api/dashboard/channels/serializers.py | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api/dashboard/affiliation/affiliation_views.py b/api/dashboard/affiliation/affiliation_views.py index d5ef2bf0..bd7147e3 100644 --- a/api/dashboard/affiliation/affiliation_views.py +++ b/api/dashboard/affiliation/affiliation_views.py @@ -12,10 +12,10 @@ class AffiliationView(APIView): def get(self,request): all_affiliations = OrgAffiliation.objects.all() - pager_ = CommonUtils.get_paginated_queryset(all_affiliations,request,['title']) + 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(response=serial_.data).get_success_response() + return CustomResponse().paginated_response(data=serial_.data,pagination=pager_.get("pagination")) @role_required([RoleType.ADMIN.value]) def post(self,request): diff --git a/api/dashboard/channels/channel_views.py b/api/dashboard/channels/channel_views.py index ced529a1..d35183d7 100644 --- a/api/dashboard/channels/channel_views.py +++ b/api/dashboard/channels/channel_views.py @@ -11,10 +11,10 @@ class ChannelView(APIView): def get(self,request): all_channels = Channel.objects.all() - pager_ = CommonUtils.get_paginated_queryset(all_channels,request,['name','discord_id','id']) + 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(response=serial_.data).get_success_response() + return CustomResponse().paginated_response(data=serial_.data,pagination=pager_.get("pagination")) @role_required([RoleType.ADMIN.value]) def post(self,request): diff --git a/api/dashboard/channels/serializers.py b/api/dashboard/channels/serializers.py index 235d6b52..25ee6f59 100644 --- a/api/dashboard/channels/serializers.py +++ b/api/dashboard/channels/serializers.py @@ -1,6 +1,7 @@ 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): @@ -33,8 +34,8 @@ def create(self, validated_data): validated_data['id'] = uuid.uuid4() validated_data['created_by_id'] = user_id validated_data['updated_by_id'] = user_id - validated_data['created_at'] = timezone.now() - validated_data['updated_at'] = timezone.now() + 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): @@ -42,6 +43,6 @@ def update(self, instance, validated_data): 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 = timezone.now() + instance.updated_at = DateTimeUtils.get_current_utc_time() instance.save() return instance \ No newline at end of file From 463e654b2d1cd734c1c6ff3d140c18a6e1918d53 Mon Sep 17 00:00:00 2001 From: anirudh-mk Date: Tue, 24 Oct 2023 12:29:23 +0530 Subject: [PATCH 5/6] fix(InterestGroupAPI):shorting fixed --- api/dashboard/ig/dash_ig_view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/dashboard/ig/dash_ig_view.py b/api/dashboard/ig/dash_ig_view.py index 12f34b34..06739b77 100644 --- a/api/dashboard/ig/dash_ig_view.py +++ b/api/dashboard/ig/dash_ig_view.py @@ -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", }, ) From 03e5bfcf0e51aead72f0e77779a54b258928b7e2 Mon Sep 17 00:00:00 2001 From: anirudh-mk Date: Tue, 24 Oct 2023 12:42:21 +0530 Subject: [PATCH 6/6] fix(InterestGroupApi):post and put --- api/dashboard/ig/dash_ig_serializer.py | 2 +- api/dashboard/ig/dash_ig_view.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/dashboard/ig/dash_ig_serializer.py b/api/dashboard/ig/dash_ig_serializer.py index b79298e7..f84edfd4 100644 --- a/api/dashboard/ig/dash_ig_serializer.py +++ b/api/dashboard/ig/dash_ig_serializer.py @@ -41,4 +41,4 @@ class Meta: "icon", "created_by", "updated_by" - ] \ No newline at end of file + ] diff --git a/api/dashboard/ig/dash_ig_view.py b/api/dashboard/ig/dash_ig_view.py index 06739b77..f7268d28 100644 --- a/api/dashboard/ig/dash_ig_view.py +++ b/api/dashboard/ig/dash_ig_view.py @@ -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 = request.data.dict() + request_data["created_by"] = request_data["updated_by"] = user_id serializer = InterestGroupCreateUpdateSerializer( @@ -78,9 +80,10 @@ 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 + request_data = request.data.dict() request_data["updated_by"] = user_id serializer = InterestGroupCreateUpdateSerializer(