Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 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
c16578b
feat: activate push notifications
oyasr Jun 7, 2022
58fa7b2
Merge branch 'dev' of https://github.com/MafQud/API into dev
oyasr Jun 7, 2022
7a5e921
feat: add case state update endpoints (#81)
OsamaRagab520 Jun 7, 2022
0cd790f
Merge branch 'master' into dev
OsamaRagab520 Jun 7, 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
16 changes: 16 additions & 0 deletions api/cases/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
list_user_cases,
)
from api.cases.services import (
archive_case,
create_case,
create_case_contact,
finish_case,
publish_case,
update_case_contact,
)
Expand Down Expand Up @@ -197,6 +199,20 @@ def get(self, request, case_id):
return Response(status=status.HTTP_200_OK)


class CaseFinishApi(APIView):
def get(self, request, case_id):
case = get_case(pk=case_id, fetched_by=request.user)
finish_case(case=case, performed_by=request.user)
return Response(status=status.HTTP_200_OK)


class CaseArchiveApi(APIView):
def get(self, request, case_id):
case = get_case(pk=case_id, fetched_by=request.user)
archive_case(case=case, performed_by=request.user)
return Response(status=status.HTTP_200_OK)


class UserCasesListApi(APIView):
class Pagination(LimitOffsetPagination):
default_limit = 10
Expand Down
2 changes: 2 additions & 0 deletions api/cases/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ def activate(self):
@transition(field=state, source=States.ACTIVE, target=States.FINISHED)
def finish(self):
self.is_active = False
self.posted_at = None

# Switch to ARCHIVED state from any state except ARCHIVED
@transition(field=state, source="+", target=States.ARCHIVED)
def archive(self):
self.is_active = False
self.posted_at = None

# If user selected incorrect match or lost again
@transition(
Expand Down
74 changes: 74 additions & 0 deletions api/cases/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def update_case():
...


@transaction.atomic
def create_case_details(
*,
case: Case,
Expand Down Expand Up @@ -124,6 +125,7 @@ def process_case(case: Case) -> List[Dict[int, int]]:
def case_matching_binding(*, case: Case, matches_list: List[Dict[int, int]]) -> None:
""" """
if not matches_list:
# TODO refactor notifications
create_notification(
case=case,
action=Notification.Action.PUBLISH,
Expand All @@ -132,6 +134,16 @@ def case_matching_binding(*, case: Case, matches_list: List[Dict[int, int]]) ->
level=Notification.Level.WARNING,
sent_to=case.user,
)
msg = Message(
notification=FirebaseNotification(
title="لم نجد حالات مشابه هل تود فى نشر الحاله",
body="لم نعثر على اى حالات مشابهه يمكنك نشر بيانات المفقود فى نطاق اوسع لتزيد احتماليه العثور عليه",
)
)

device = FCMDevice.objects.filter(user=case.user).first()
device.send_message(msg)

return

cases_ids = [match["id"] for match in matches_list]
Expand All @@ -154,6 +166,15 @@ def case_matching_binding(*, case: Case, matches_list: List[Dict[int, int]]) ->
level=Notification.Level.SUCCESS,
sent_to=match.user,
)
msg = Message(
notification=FirebaseNotification(
title="تم العثور على حالات مشابه",
body="تم الوصول لبعض النتائج قم بتصفحها الان",
)
)

device = FCMDevice.objects.filter(user=match.user).first()
device.send_message(msg)

create_notification(
case=case,
Expand All @@ -163,8 +184,18 @@ def case_matching_binding(*, case: Case, matches_list: List[Dict[int, int]]) ->
level=Notification.Level.SUCCESS,
sent_to=case.user,
)
msg = Message(
notification=FirebaseNotification(
title="تم العثور على حالات مشابه",
body="تم الوصول لبعض النتائج قم بتصفحها الان",
)
)

device = FCMDevice.objects.filter(user=case.user).first()
device.send_message(msg)


@transaction.atomic
def activate_case(case: Case):
matches = process_case(case)
case_matching_binding(case=case, matches_list=matches)
Expand All @@ -190,6 +221,7 @@ def activate_case(case: Case):
device.send_message(msg)


# TODO refactor object permission on view level to some mixin or permission class
def publish_case(*, case: Case, performed_by: User):
if case.user != performed_by:
raise PermissionDenied()
Expand Down Expand Up @@ -222,6 +254,48 @@ def publish_case(*, case: Case, performed_by: User):
device.send_message(msg)


def archive_case(*, case: Case, performed_by: User):
if case.user != performed_by:
raise PermissionDenied()

if case.state == Case.States.ARCHIVED:
raise ValidationError("Case already archived")

case.archive()
case.save()
create_notification(
case=case,
action=Notification.Action.PUBLISH,
title="تم ارشفه الحاله بنجاح",
body="تم ارشفه الحاله لن يتمكن اى احد للوصول لها غيرك",
level=Notification.Level.WARNING,
sent_to=case.user,
)


def finish_case(*, case: Case, performed_by: User):
if case.user != performed_by:
raise PermissionDenied()

if not case.is_active:
raise ValidationError("Cannot finish inactive case")

if case.state == Case.States.FINISHED:
raise ValidationError("Case already closed")

case.finish()
case.save()

create_notification(
case=case,
action=Notification.Action.NONE,
title="تم ارشفه الحاله بنجاح",
body="تم اغلاق الحاله بنجاح نرجو ان يكون ذويك على ما يرام",
level=Notification.Level.SUCCESS,
sent_to=case.user,
)


def create_case_contact(*, user: User, case: Case) -> CaseContact:
contact = CaseContact(case=case, user=user)
contact.full_clean()
Expand Down
4 changes: 4 additions & 0 deletions api/cases/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.urls import path

from .apis import (
CaseArchiveApi,
CaseContactCreateApi,
CaseContactUpdateApi,
CaseFinishApi,
CaseListApi,
CaseMatchListApi,
CasePublishApi,
Expand All @@ -25,4 +27,6 @@
# path("<int:case_id>/update/", UpdateCaseApi.as_view(), name="update"),
path("<int:case_id>/matches/", CaseMatchListApi.as_view(), name="matches"),
path("<int:case_id>/publish/", CasePublishApi.as_view(), name="publish"),
path("<int:case_id>/finish/", CaseFinishApi.as_view(), name="finish"),
path("<int:case_id>/archive/", CaseArchiveApi.as_view(), name="archive"),
]