Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
dbbee72
chore: crete auth app
Apr 16, 2022
4d4b059
chore: add auth to installed apps
oyasr Apr 16, 2022
a8ad3b2
chore: add .vscode to gitignore
oyasr Apr 16, 2022
94b8696
feat: create initial user model
oyasr Apr 16, 2022
9b30190
chore: create locations app
oyasr Apr 16, 2022
7adf5a3
feat: create initial locations models
oyasr Apr 16, 2022
120a724
feat: add govs and cities data
oyasr Apr 16, 2022
974fd8f
feat: add gov-city db population service
oyasr Apr 16, 2022
5abf6cc
feat: add user create service
oyasr Apr 17, 2022
06118a0
merge dev
oyasr Apr 17, 2022
d3dc2c4
refactor: move auth app inside api/
oyasr Apr 17, 2022
e5332fd
feat: Implement Case model
OsamaRagab520 Apr 17, 2022
ed92a3d
feat: Implement Case services
OsamaRagab520 Apr 17, 2022
c81d9f2
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 17, 2022
07d909b
fix: add cases app to local apps
oyasr Apr 17, 2022
1e78ea0
fix: locations typo
oyasr Apr 17, 2022
35e28d2
fix: add api namespace to app names
oyasr Apr 17, 2022
fc8d6eb
fix: rquirements typo
oyasr Apr 17, 2022
fee730d
fix: circular import
oyasr Apr 17, 2022
ff30b99
Merge branch 'dev' into feature/user-authentication
oyasr Apr 17, 2022
6fbdc72
feat: add location attribute to case model
OsamaRagab520 Apr 17, 2022
c614576
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 17, 2022
796ad07
fix: admin page typo
oyasr Apr 17, 2022
b4f1678
Merge branch 'dev' into feature/user-model
oyasr Apr 17, 2022
7b77806
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 17, 2022
a631c03
feat: initial database migration
oyasr Apr 17, 2022
27eed05
feat: add cases app models to admin site
OsamaRagab520 Apr 17, 2022
3aaeba6
feat: add locations app models to admin site
oyasr Apr 17, 2022
755fd88
Merge branch 'dev' into feature/user-authentication
OsamaRagab520 Apr 17, 2022
619987c
chore: update requirements folder
oyasr Apr 17, 2022
0816e2e
fix: json paths
oyasr Apr 17, 2022
457c8cd
Merge branch 'dev' into feature/location-model
oyasr Apr 17, 2022
a7b64e4
feat: add governorate list selector
oyasr Apr 17, 2022
2e1de07
chore: add dj-rest-auth lib
OsamaRagab520 Apr 17, 2022
4b08e24
Merge branch 'dev' into feature/user-authentication
OsamaRagab520 Apr 17, 2022
9892c81
fix: add None as default value for lon & lat
oyasr Apr 17, 2022
c5e47a5
fix: add firebase token to create user service
oyasr Apr 17, 2022
acef245
Merge branch 'dev' into feature/user-authentication
OsamaRagab520 Apr 17, 2022
612641c
feat: implement user registration
OsamaRagab520 Apr 17, 2022
6a191ad
chore: rename auth app to authentication
OsamaRagab520 Apr 18, 2022
cc16528
fix: RegisterSerializer fields
OsamaRagab520 Apr 18, 2022
10742a9
fix: location clean logic
oyasr Apr 18, 2022
7b59ff2
Merge branch 'dev' into feature/location-model
oyasr Apr 18, 2022
43bcb2c
Merge branch 'dev' into feature/user-authentication
OsamaRagab520 Apr 18, 2022
d6df20c
fix: modify address to accpet null
OsamaRagab520 Apr 18, 2022
fe03a91
Merge branch 'dev' into feature/location-model
OsamaRagab520 Apr 18, 2022
bb3f8fe
Merge branch 'dev' into feature/user-authentication
OsamaRagab520 Apr 18, 2022
198caa6
feat: create custom error handler
oyasr Apr 19, 2022
1737adf
fix: update token auth
OsamaRagab520 Apr 19, 2022
7506331
Merge branch 'dev' of https://github.com/MafQud/API into dev
OsamaRagab520 Apr 19, 2022
a4a1306
feat: implement user registration
OsamaRagab520 Apr 19, 2022
5ef868b
Merge branch 'dev' into feature/user-model
OsamaRagab520 Apr 19, 2022
507a8df
refactor: create_location service
OsamaRagab520 Apr 19, 2022
ce911ae
Merge branch 'dev' into feature/location-model
OsamaRagab520 Apr 19, 2022
28148e9
Merge branch 'feature/location-model' into dev
OsamaRagab520 Apr 19, 2022
c571802
Merge branch 'dev' into feature/user-authentication
OsamaRagab520 Apr 19, 2022
f086437
refactor: migrate to simpleJWT
OsamaRagab520 Apr 19, 2022
9ffb86b
fix: CreateUserApi
OsamaRagab520 Apr 19, 2022
aa00cfa
fix: circural referance
OsamaRagab520 Apr 19, 2022
e8e3ebf
Merge branch 'feature/api-errors' into dev
OsamaRagab520 Apr 19, 2022
c58b39b
Merge branch 'feature/user-model' into dev
OsamaRagab520 Apr 19, 2022
7352c07
chore: apply new model migrations
OsamaRagab520 Apr 19, 2022
5f73013
fix: remove dj-rest-auth from installed apps
oyasr Apr 19, 2022
083303a
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 20, 2022
0e21f5d
feat: add common tools
OsamaRagab520 Apr 20, 2022
aa03b9d
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 20, 2022
0850ecc
refactor: case services
OsamaRagab520 Apr 20, 2022
7e2d5a3
feat: add custom permissions
oyasr Apr 21, 2022
2dd6f16
refactor: CaseDetails model
OsamaRagab520 Apr 21, 2022
191919c
refactor: case services
OsamaRagab520 Apr 21, 2022
aa9dc34
feat: implement case create view
OsamaRagab520 Apr 21, 2022
0da530b
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 22, 2022
390f519
feat: s3 direct upload
oyasr Apr 22, 2022
898f6d0
feat: implement user detail view
oyasr Apr 23, 2022
bcfb922
feat: implement user update view
oyasr Apr 24, 2022
9f914c1
feat: implement update location service
oyasr Apr 24, 2022
7e51ec3
Merge branch 'dev' into feature/user-model
oyasr Apr 24, 2022
0ec293b
refactor: update user location in place
oyasr Apr 24, 2022
99d549d
refactor: make urls for each app
oyasr Apr 24, 2022
1e650b9
fix: api namespace collision
oyasr Apr 24, 2022
3f20267
test: user model test cases
oyasr Apr 24, 2022
e2d1c90
feat: implement DetailCaseApi
OsamaRagab520 Apr 24, 2022
ca2c659
Merge branch 'dev' into feature/case-model
OsamaRagab520 Apr 26, 2022
00766bc
fix: append api namespace to apis url
oyasr Apr 26, 2022
0feb4e8
Merge branch 'feature/user-authentication' into dev
oyasr Apr 26, 2022
dac4f4b
feat: implement CaseListApi
OsamaRagab520 May 3, 2022
b669bf6
Merge branch 'dev' into feature/case-model
OsamaRagab520 May 3, 2022
800eadb
chore: run jobs on dev PR & commits
OsamaRagab520 May 8, 2022
f6a96f6
MAFQUD-208 : notification system (#20)
oyasr May 8, 2022
a9f24ee
MAFQUD-206 : phone validation (#21)
oyasr May 8, 2022
c5e5f97
MAFQUD-207 : Refactor services (#22)
OsamaRagab520 May 8, 2022
c1e5893
MAFQUD-205 : Write list case matches Endpoint (#26)
OsamaRagab520 May 10, 2022
c149531
MAFQUD-210: national id (#27)
oyasr May 10, 2022
3f1d6b7
Final tweaks (#30)
OsamaRagab520 May 13, 2022
e75b3f7
chore: disable push notification & hot fixes
OsamaRagab520 May 13, 2022
de3ab40
chore: integrate files into cases instead of urls
OsamaRagab520 May 15, 2022
5f21b07
chore: apply clean migrations
OsamaRagab520 May 15, 2022
a3696d2
chore: update app base settings
OsamaRagab520 May 15, 2022
fb9159f
fix: minor cases app bugs
OsamaRagab520 May 21, 2022
d2211a3
feat: pack user info in the token
OsamaRagab520 May 21, 2022
89e24ee
chore: use firebase_token as the id for fcm device
OsamaRagab520 May 21, 2022
4ae6c26
chore: disable unnessary urls
OsamaRagab520 May 21, 2022
1ff40cc
Merge branch 'master' into dev
OsamaRagab520 May 21, 2022
682bd81
chore: delete unnssary authentication classes and configure jwt life …
OsamaRagab520 May 23, 2022
5b93bb8
chore: move UserCasesListApi to cases app instead of users
OsamaRagab520 May 25, 2022
c9cd81a
chore: nest locations responses
OsamaRagab520 May 25, 2022
c921ce5
Merge branch 'master' into dev
OsamaRagab520 May 25, 2022
df5f294
chore: change pagination style & add case & action field to notificat…
OsamaRagab520 May 26, 2022
9bae0c3
Merge branch 'master' into dev
OsamaRagab520 May 26, 2022
2157cb0
chore: update notification serializer
OsamaRagab520 May 26, 2022
123808b
feat: write case contacts model
oyasr May 27, 2022
154cbfb
chore: make database migration
oyasr May 27, 2022
7468129
feat: implement create and update case contacts
oyasr May 27, 2022
81d30f8
chore: change pagnition style
OsamaRagab520 May 27, 2022
685d18a
Merge branch 'dev' of https://github.com/MafQud/API into dev
OsamaRagab520 May 27, 2022
1c7c69b
Merge branch 'master' into dev
OsamaRagab520 May 27, 2022
51948bf
chore production settings
OsamaRagab520 May 27, 2022
b73ac35
feat: add two new notifications
OsamaRagab520 May 29, 2022
fce8c9e
feat: add NotificationReadApi
OsamaRagab520 May 29, 2022
f82e6b2
fix: update aws signature version to v4
oyasr Jun 3, 2022
23bd163
fix: increase the expiration time of aws presigned url to 5 mins
oyasr Jun 3, 2022
a5034b2
feat: update case'name filter (#72)
OsamaRagab520 Jun 5, 2022
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
1 change: 1 addition & 0 deletions api/cases/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class FilterSerializer(serializers.Serializer):
end_date = serializers.DateField(required=False)
gov = serializers.IntegerField(required=False)
name = serializers.CharField(required=False)
include_null = serializers.BooleanField(required=False)

class OutputSerializer(serializers.Serializer):
id = serializers.IntegerField()
Expand Down
13 changes: 10 additions & 3 deletions api/cases/filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import django_filters
from django.db.models.query import Q

from .models import Case

Expand All @@ -8,9 +9,7 @@ class CaseFilter(django_filters.FilterSet):
type = django_filters.CharFilter(lookup_expr="iexact")

gov = django_filters.NumberFilter(field_name="location__gov")
name = django_filters.CharFilter(
field_name="details__name", lookup_expr="icontains"
)
name = django_filters.CharFilter(field_name="details__name", method="filter_name")

start_age = django_filters.NumberFilter(
field_name="details__age", lookup_expr="gte"
Expand All @@ -24,6 +23,14 @@ class CaseFilter(django_filters.FilterSet):
field_name="details__last_seen", lookup_expr="lte"
)

def filter_name(self, queryset, name, value):
if self.data.get("include_null"):
return queryset.filter(
Q(details__name__icontains=value) | Q(details__name__isnull=True)
)

return queryset.filter(details__name__icontains=value)

class Meta:
model = Case
fields = [
Expand Down
30 changes: 27 additions & 3 deletions api/cases/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ def process_case(case: Case) -> List[Dict[int, int]]:


def case_matching_binding(*, case: Case, matches_list: List[Dict[int, int]]) -> None:
"""
Bind the processed case with it's matches by instaniating CaseMatch objects
"""
""" """
if not matches_list:
create_notification(
case=case,
action=Notification.Action.PUBLISH,
title="لم نجد حالات مشابه هل تود فى نشر الحاله",
body="لم نعثر على اى حالات مشابهه يمكنك نشر بيانات المفقود فى نطاق اوسع لتزيد احتماليه العثور عليه",
level=Notification.Level.WARNING,
sent_to=case.user,
)
return

cases_ids = [match["id"] for match in matches_list]
Expand All @@ -141,6 +147,24 @@ def case_matching_binding(*, case: Case, matches_list: List[Dict[int, int]]) ->
else:
create_case_match(missing=match, found=case, score=score)

create_notification(
case=match,
action=Notification.Action.MATCHES,
title="تم العثور على حالات مشابه",
body="تم الوصول لبعض النتائج قم بتصفحها الان",
level=Notification.Level.SUCCESS,
sent_to=match.user,
)

create_notification(
case=case,
action=Notification.Action.MATCHES,
title="تم العثور على حالات مشابه",
body="تم الوصول لبعض النتائج قم بتصفحها الان",
level=Notification.Level.SUCCESS,
sent_to=case.user,
)


def activate_case(case: Case):
matches = process_case(case)
Expand Down
5 changes: 4 additions & 1 deletion api/integrations/aws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import boto3
from attrs import define
from botocore.config import Config

from api.common.utils import assert_settings

Expand Down Expand Up @@ -51,7 +52,9 @@ def s3_get_client():
service_name="s3",
aws_access_key_id=credentials.access_key_id,
aws_secret_access_key=credentials.secret_access_key,
region_name=credentials.region_name,
region_name="eu-south-1",
endpoint_url="https://s3.eu-south-1.amazonaws.com/",
config=Config(signature_version="s3v4"),
)


Expand Down
15 changes: 13 additions & 2 deletions api/notifications/apis.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from rest_framework import serializers
from rest_framework import serializers, status
from rest_framework.response import Response
from rest_framework.views import APIView

from api.apis.pagination import LimitOffsetPagination, get_paginated_response
from api.notifications.selectors import list_user_notification
from api.notifications.selectors import get_notification, list_user_notification
from api.notifications.services import read_notification


class NotificationListApi(APIView):
Expand Down Expand Up @@ -30,3 +32,12 @@ def get(self, request):
request=request,
view=self,
)


class NotificationReadApi(APIView):
def get(self, request, notification_id):

notification = get_notification(pk=notification_id, fetched_by=request.user)
read_notification(notification)

return Response(status=status.HTTP_200_OK)
16 changes: 15 additions & 1 deletion api/notifications/selectors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
from django.core.exceptions import PermissionDenied
from django.db.models.query import QuerySet
from django.shortcuts import get_object_or_404

from api.notifications.models import Notification
from api.users.models import User


def list_user_notification(*, user: User):
def list_user_notification(*, user: User) -> QuerySet[Notification]:
return user.notifications.all()


def get_notification(*, pk: int, fetched_by: User) -> Notification:
notification = get_object_or_404(Notification, pk=pk)

if not notification.sent_to == fetched_by:
raise PermissionDenied()

return notification
6 changes: 6 additions & 0 deletions api/notifications/services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional

from django.utils import timezone
from fcm_django.models import FCMDevice

from api.cases.models import Case
Expand Down Expand Up @@ -47,3 +48,8 @@ def create_fcm_device(
device.save()

return device


def read_notification(notification: Notification):
notification.read_at = timezone.now()
notification.save()
7 changes: 6 additions & 1 deletion api/notifications/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.urls import path

from api.notifications.apis import NotificationListApi
from api.notifications.apis import NotificationListApi, NotificationReadApi

app_name = "notifications"
urlpatterns = [
path("", NotificationListApi.as_view(), name="notification_list"),
path(
"<int:notification_id>/read/",
NotificationReadApi.as_view(),
name="notification_read",
),
]
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,4 @@
# https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
AWS_DEFAULT_ACL = env("AWS_DEFAULT_ACL", default="public-read")

AWS_PRESIGNED_EXPIRY = env.int("AWS_PRESIGNED_EXPIRY", default=10) # seconds
AWS_PRESIGNED_EXPIRY = env.int("AWS_PRESIGNED_EXPIRY", default=300) # seconds