def put(self, request): pk = JWTService.run_auth_process(request.headers) serializer = MyProfilePutSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) where = request.data['where'] if not (where == 'web' or where == 'mobile'): return Response( { 'detail': "You have to include 'web' or 'mobile' in 'from_where'" }, status=status.HTTP_400_BAD_REQUEST) profile = request.FILES.get('profile') if profile is not None: S3Service.upload_profile(pk, profile, S3Service.make_s3_resource()) background = request.FILES.get('background') if background is not None: S3Service.upload_background(pk, background, S3Service.make_s3_resource(), where) data = serializer.initial_data ProfileService.change_profile_with_pk(pk, data["nickname"], data["status_message"]) return Response(status=status.HTTP_200_OK)
def get(self, request): pk = JWTService.run_auth_process(request.headers) friend_list = FriendService.sort_list(FriendService.get_friend_list(pk)) filter_friend_list = FriendService.filter_if_hidden_false(friend_list) return Response(FriendService.convert_list_to_dict(filter_friend_list), status=status.HTTP_200_OK)
def get_queryset(self): pk = JWTService.run_auth_process(self.request.headers) if len(AdminTbl.objects.filter(id=pk).values()): if 'q' not in self.request.GET: raise InvalidSort sort = self.request.GET['sort'] search = self.request.GET['q'] report_ids = [] if sort == 'title': queryset = ReportTbl.objects.filter(is_accepted=1) \ .filter(title__contains=search)\ .filter(is_submitted=1) return queryset elif sort == 'user': queryset = ReportTbl.objects.filter(is_accepted=1) \ .filter(team_name__contains=search)\ .filter(is_submitted=1) users = UserTbl.objects.filter(name__contains=search) for user in users: members = MemberTbl.objects.filter(user_email=user.email) for member in members: report_ids.append(member.report_id) for report_id in report_ids: report = ReportTbl.objects.filter(is_accepted=1) \ .filter(id=report_id)\ .filter(is_submitted=1) queryset = queryset | report return queryset else: raise InvalidSort
def get_queryset(self, *args, **kwargs): pk = JWTService.run_auth_process(self.request.headers) if len(AdminTbl.objects.filter(id=pk).values()): queryset = ReportTbl.objects.filter(is_accepted=0)\ .filter(comment__isnull=True)\ .filter(is_submitted=1) return queryset
def delete(self, request, guest_id): host_id = JWTService.run_auth_process(request.headers) if not UserService.check_pk_exists(guest_id): raise FriendNotFound if host_id is guest_id: raise Myself if not FriendService.check_both_friend(host_id, guest_id): raise NotFriend FriendService.delete_friend(host_id, guest_id) return Response(status=status.HTTP_200_OK)
def get(self, request, kakao_id): host_id = JWTService.run_auth_process(request.headers) if not KakaoIdService.check_kakao_id_exist(kakao_id): raise InvalidKakaoId profile = KakaoIdService.get_profile_with_kakao_id(kakao_id) guest_id = profile.user_id.id return Response({ "id": guest_id, "nickname": profile.nickname, "myself": True if host_id == guest_id else False, "relate": FriendService.check_relationship(id1=host_id, id2=guest_id) }, status=status.HTTP_200_OK)
def get(self, request): pk = JWTService.run_auth_process(request.headers) profile = ProfileService.get_profile_with_pk(pk) return Response( { "id": pk, "nickname": profile.nickname, "status_message": "" if profile.status_message is None else profile.status_message }, status=status.HTTP_200_OK)
def put(self, request, guest_id): host_id = JWTService.run_auth_process(request.headers) if UserPutAPIService.check_put_bad_request(request.data): raise PutBadRequest if not UserService.check_pk_exists(guest_id): raise FriendNotFound if host_id is guest_id: raise Myself if not FriendService.check_both_friend(host_id, guest_id): raise NotFriend key = UserPutAPIService.get_key_from_data(request.data) set_status = True if request.data[key] is "1" else False if FriendService.check_friend_status(host_id=host_id, guest_id=guest_id, key=key) is set_status: raise SameStatus FriendService.set_friend_status(host_id, guest_id, key, set_status) return Response(status=status.HTTP_200_OK)
def post(self, request, user_id): host_id = JWTService.run_auth_process(request.headers) guest_id = user_id if not UserService.check_pk_exists(guest_id): raise FriendNotFound if host_id is guest_id: raise Myself if FriendService.check_both_friend(id1=host_id, id2=guest_id): raise AlreadyFriend if FriendService.check_request_friend(host_id=host_id, guest_id=guest_id): raise AlreadyRequest FriendService.create_new_friend(host_id=host_id, guest_id=guest_id) if FriendService.check_request_friend(host_id=guest_id, guest_id=host_id): return Response(status=status.HTTP_201_CREATED) return Response(status=status.HTTP_200_OK)
def get(self, request, user_id): pk = JWTService.run_auth_process(request.headers) if not UserService.check_pk_exists(user_id): raise UserNotFound if not FriendService.check_both_friend( id1=pk, id2=user_id) and pk is not user_id: raise NotFriend profile = ProfileService.get_profile_with_pk(user_id) return Response( { "id": user_id, "nickname": profile.nickname, "status_message": "" if profile.status_message is None else profile.status_message, "myself": True if pk is user_id else False }, status=status.HTTP_200_OK)
def get_queryset(self): pk = JWTService.run_auth_process(self.request.headers) if len(AdminTbl.objects.filter(id=pk).values()): if 'q' not in self.request.GET: raise InvalidSort filter = self.request.GET['q'] if filter == '2021': queryset = ReportTbl.objects\ .filter(created_at__startswith='2021')\ .filter(is_accepted=1).filter(is_submitted=1) return queryset elif filter == 'SOLE': ids = ReportTypeTbl.objects.filter(type='SOLE').values_list( 'report_id', flat=True).distinct() print(list(ids)) queryset = ReportTbl.objects.filter(pk__in=list(ids))\ .filter(is_accepted=1).filter(is_submitted=1) return queryset elif filter == 'TEAM': ids = ReportTypeTbl.objects.filter(type='TEAM').values_list( 'report_id', flat=True).distinct() print(list(ids)) queryset = ReportTbl.objects.filter(pk__in=list(ids)) \ .filter(is_accepted=1).filter(is_submitted=1) return queryset elif filter == 'CIRCLE': ids = ReportTypeTbl.objects.filter(type='CIRCLE').values_list( 'report_id', flat=True).distinct() print(list(ids)) queryset = ReportTbl.objects.filter(pk__in=list(ids)) \ .filter(is_accepted=1).filter(is_submitted=1) return queryset else: raise InvalidSort
def get(self, request): pk = JWTService.run_auth_process(request.headers) friend_list = FriendService.sort_list(FriendService.get_request_list(host_id=pk)) return Response(FriendService.convert_list_to_dict(friend_list), status=status.HTTP_200_OK)
def get_queryset(self, *args, **kwargs): pk = JWTService.run_auth_process(self.request.headers) if len(AdminTbl.objects.filter(id=pk).values()): queryset = QuestionTbl.objects.all() return queryset
def get(self, request): pk = JWTService.run_auth_process(request.headers, 'refresh') return Response( {'access_token': JWTService.create_access_token_with_id(pk)}, status=status.HTTP_200_OK)
def get(self, request): pk = JWTService.run_auth_process(request.headers) return Response({"kakao_id": KakaoIdService.get_kakao_id_with_pk(pk)}, status=status.HTTP_200_OK)
def perform_create(self, serializer): pk = JWTService.run_auth_process(self.request.headers) if len(AdminTbl.objects.filter(id=pk).values()): serializer.save()