From f998b6ae071c6457858a77b43d4bfb9db0d1c4b4 Mon Sep 17 00:00:00 2001
From: addffa <adli.daffa5@gmail.com>
Date: Sun, 16 Aug 2020 20:38:15 +0700
Subject: [PATCH 1/9] [GREEN] fix form mutasi mustahik

---
 sizakat/mustahik/forms.py | 1 +
 sizakat/mustahik/tests.py | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/sizakat/mustahik/forms.py b/sizakat/mustahik/forms.py
index 9af65d6..d6b1039 100644
--- a/sizakat/mustahik/forms.py
+++ b/sizakat/mustahik/forms.py
@@ -55,6 +55,7 @@ class DataSourceInstitusiForm(forms.ModelForm):
             'pic_position',
             'name',
             'province',
+            'regency',
             'sub_district',
             'village',
             'rt',
diff --git a/sizakat/mustahik/tests.py b/sizakat/mustahik/tests.py
index 082e828..186b0c3 100644
--- a/sizakat/mustahik/tests.py
+++ b/sizakat/mustahik/tests.py
@@ -739,6 +739,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
                 "picPosition": "Vice",
                 "name": "Pesantren Yatim",
                 "province": "Jawa Barat",
+                "regency": "Kabupaten",
                 "subDistrict": "Dusun",
                 "village": "desa",
                 "rt": "002",
@@ -806,6 +807,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
                 "picPosition": "Head",
                 "name": "Institusi Bandung",
                 "province": "Jawa Barat",
+                "regency": "Kota",
                 "subDistrict": "Bogor",
                 "village": "Desa",
                 "rt": "001",
-- 
GitLab


From 49263b7d937ac62307b8ced47fa1497226f1d4cc Mon Sep 17 00:00:00 2001
From: addffa <adli.daffa5@gmail.com>
Date: Sun, 16 Aug 2020 20:52:00 +0700
Subject: [PATCH 2/9] [GREEN] fix datasource institusi requirement

---
 .../migrations/0002_auto_20200816_1347.py     | 23 +++++++++++++++++++
 sizakat/mustahik/models.py                    |  3 ++-
 sizakat/mustahik/tests.py                     |  2 --
 3 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 sizakat/mustahik/migrations/0002_auto_20200816_1347.py

diff --git a/sizakat/mustahik/migrations/0002_auto_20200816_1347.py b/sizakat/mustahik/migrations/0002_auto_20200816_1347.py
new file mode 100644
index 0000000..457c1df
--- /dev/null
+++ b/sizakat/mustahik/migrations/0002_auto_20200816_1347.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.0.7 on 2020-08-16 13:47
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('mustahik', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='datasourceinstitusi',
+            name='address',
+            field=models.CharField(blank=True, max_length=255, null=True),
+        ),
+        migrations.AlterField(
+            model_name='datasourceinstitusi',
+            name='pic_position',
+            field=models.CharField(blank=True, max_length=50, null=True),
+        ),
+    ]
diff --git a/sizakat/mustahik/models.py b/sizakat/mustahik/models.py
index bf21785..1797390 100644
--- a/sizakat/mustahik/models.py
+++ b/sizakat/mustahik/models.py
@@ -105,11 +105,12 @@ class DataSourceInstitusi(DataSourceDetail):
     rw = models.CharField(
         max_length=3, validators=[validate_numeric_character]
     )
-    address = models.CharField(max_length=255)
+    address = models.CharField(max_length=255, blank=True, null=True)
     data_source = models.OneToOneField(
         'DataSource', on_delete=models.CASCADE,
         limit_choices_to={'category': DataSource.Category.INSTITUSI}
     )
+    pic_position = models.CharField(max_length=50, blank=True, null=True)
 
 
 class DataSourcePekerja(DataSourceDetail):
diff --git a/sizakat/mustahik/tests.py b/sizakat/mustahik/tests.py
index 186b0c3..6d3b5f4 100644
--- a/sizakat/mustahik/tests.py
+++ b/sizakat/mustahik/tests.py
@@ -804,7 +804,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
                 "picKtp": pic_ktp,
                 "picName": new_pic_name,
                 "picPhone": "123456789012",
-                "picPosition": "Head",
                 "name": "Institusi Bandung",
                 "province": "Jawa Barat",
                 "regency": "Kota",
@@ -812,7 +811,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
                 "village": "Desa",
                 "rt": "001",
                 "rw": "001",
-                "address": "Jalan suatu desa no 1",
                 "dataSource": data_source_institusi.pk,
                 "id": source_institusi.pk,
             }
-- 
GitLab


From 6028d9ab4e9ee07fd61390c41195419ba77ffd09 Mon Sep 17 00:00:00 2001
From: abdurrafiarief <abdurrafiarief@gmail.com>
Date: Thu, 27 Aug 2020 15:18:46 +0700
Subject: [PATCH 3/9] [RED] Add SDM search with picname test

---
 sizakat/mustahik/tests.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/sizakat/mustahik/tests.py b/sizakat/mustahik/tests.py
index 6d3b5f4..e221758 100644
--- a/sizakat/mustahik/tests.py
+++ b/sizakat/mustahik/tests.py
@@ -871,3 +871,38 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
             datasource_warga = datasource['dataSourceDetail']
             kelurahan = datasource_warga.get('village', None)
             self.assertIn(kelurahan, ['pinangranti', None])
+
+    def test_query_search_by_picname(self):
+        response = self.query(
+        '''
+        {
+            dataSources(picNameContains:"pic test") {
+                id
+                category
+                dataSourceDetail {
+                __typename
+                ... on DataSourceInstitusiType {
+                    picName
+                    name
+                }
+                ... on DataSourcePekerjaType {
+                    picName
+                    profession
+                    location
+                }
+                ... on DataSourceWargaType {
+                    picName
+                    rt
+                    rw
+                    village
+                }
+                }
+            }
+        }
+        ''')
+        self.assertResponseNoErrors(response)
+        datasources = json.loads(response.content)['data']['dataSources']
+        for datasource in datasources:
+            datasourceDetails = datasource['dataSourceDetail']
+            picName = datasourceDetails.get('picName', None)
+            self.assertIn(picName, ['pic test', None])
\ No newline at end of file
-- 
GitLab


From f5797bf75b97d25fbe355065494cae0c967568f7 Mon Sep 17 00:00:00 2001
From: abdurrafiarief <abdurrafiarief@gmail.com>
Date: Thu, 27 Aug 2020 15:46:17 +0700
Subject: [PATCH 4/9] [GREEN] Added feature search datasource by picName

---
 sizakat/mustahik/query.py | 18 +++++++++++++++---
 sizakat/mustahik/tests.py |  1 +
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/sizakat/mustahik/query.py b/sizakat/mustahik/query.py
index 3e989ce..e3e0d43 100644
--- a/sizakat/mustahik/query.py
+++ b/sizakat/mustahik/query.py
@@ -16,7 +16,8 @@ class MustahikQuery(graphene.ObjectType):
     mustahik = graphene.Field(MustahikType, id=graphene.ID(required=True))
     data_sources = graphene.List(
         DataSourceType, category=graphene.String(),
-        name_contains=graphene.String()
+        name_contains=graphene.String(),
+        picName_contains=graphene.String()
     )
     data_source = graphene.Field(DataSourceType, id=graphene.ID(required=True))
 
@@ -39,9 +40,13 @@ class MustahikQuery(graphene.ObjectType):
     def resolve_mustahik(self, info, id):
         return Mustahik.objects.get(pk=id)
 
+    def resolve_data_source(self, info, id):
+        return DataSource.objects.get(pk=id)
+
     def resolve_data_sources(self, info, **kwargs):
         category = kwargs.get('category', None)
         query = kwargs.get('name_contains', None)
+        picName = kwargs.get('picName_contains', None)
         filter_query = Q()
         if category:
             filter_query &= Q(category=category)
@@ -56,7 +61,14 @@ class MustahikQuery(graphene.ObjectType):
                 | Q(datasourcewarga__village__icontains=query)
             )
 
+        if picName:
+            filter_query &= (
+                Q(datasourcepekerja__pic_name__icontains=picName)
+                | Q(datasourceinstitusi__pic_name__icontains=picName)
+                | Q(datasourcewarga__pic_name__icontains=picName)
+                
+            )
+
         return DataSource.objects.filter(filter_query)
 
-    def resolve_data_source(self, info, id):
-        return DataSource.objects.get(pk=id)
+
diff --git a/sizakat/mustahik/tests.py b/sizakat/mustahik/tests.py
index e221758..4aa61b9 100644
--- a/sizakat/mustahik/tests.py
+++ b/sizakat/mustahik/tests.py
@@ -479,6 +479,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
         self.assertEqual(content['data']['q3']['id'], str(institusi_detail.data_source.pk))
         self.assertEqual(content['data']['q3']['detail']['__typename'], 'DataSourceInstitusiType')
 
+
     def test_data_source_mutation_can_add_new_data_source(self):
         existing_data_source_ammount = DataSource.objects.count()
         response = self.query(
-- 
GitLab


From df13252dc39a54a513c75a07c925dec8b487de91 Mon Sep 17 00:00:00 2001
From: Naufal Alauddin Hilmi <naufal.alauddin@ui.ac.id>
Date: Thu, 3 Sep 2020 13:56:44 +0700
Subject: [PATCH 5/9] PBI 16 TASK: Pencarian mustahik dengan sdm

---
 sizakat/mustahik/query.py | 12 ++++++++++--
 sizakat/mustahik/tests.py | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/sizakat/mustahik/query.py b/sizakat/mustahik/query.py
index e3e0d43..72667bc 100644
--- a/sizakat/mustahik/query.py
+++ b/sizakat/mustahik/query.py
@@ -11,7 +11,8 @@ class MustahikQuery(graphene.ObjectType):
     mustahiks = graphene.List(
         MustahikType,
         statuses=graphene.List(graphene.String),
-        name_contains=graphene.String()
+        name_contains=graphene.String(),
+        data_sources=graphene.List(graphene.ID)
     )
     mustahik = graphene.Field(MustahikType, id=graphene.ID(required=True))
     data_sources = graphene.List(
@@ -23,15 +24,22 @@ class MustahikQuery(graphene.ObjectType):
 
     def resolve_mustahiks(self, info, **kwargs):
         statuses = kwargs.get('statuses', None)
+        data_sources = kwargs.get('data_sources', None)
         name_contains = kwargs.get('name_contains', None)
         filter_query = Q()
 
         if statuses and len(statuses) > 0:
-            filter_query |= reduce(
+            filter_query &= reduce(
                 lambda a, b: a | b,
                 [Q(status=status) for status in statuses]
             )
 
+        if data_sources and len(data_sources) > 0:
+            filter_query &= reduce(
+                lambda a, b: a | b,
+                [Q(data_source=data_source) for data_source in data_sources]
+            )
+
         if name_contains:
             filter_query &= Q(name__icontains=name_contains)
 
diff --git a/sizakat/mustahik/tests.py b/sizakat/mustahik/tests.py
index 4aa61b9..f82c5f6 100644
--- a/sizakat/mustahik/tests.py
+++ b/sizakat/mustahik/tests.py
@@ -361,6 +361,44 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
         content = json.loads(response.content)
         self.assertEqual(len(content['data']['mustahiks']), 0)
 
+    def test_mustahiks_query_if_data_sources_provided_should_return_mustahiks_with_coresponding_data_sources(self):
+        dataSourceId = DataSource.objects.all()[0].id
+        response = self.query(
+            '''
+            query mustahiks($dataSources: [ID]) {
+                mustahiks(dataSources: $dataSources) {
+                    dataSource {
+                        id
+                    }
+                }
+            }
+            ''',
+            op_name='mustahiks',
+            variables={'dataSources': [dataSourceId]}
+        )
+
+        content = json.loads(response.content)
+        self.assertEqual(int(content['data']['mustahiks'][0]['dataSource']['id']), dataSourceId)
+
+    def test_mustahiks_query_if_data_sources_provided_has_no_corresponding_mustahiks_it_should_return_empty_list(self):
+        dataSourceId = 99999
+        response = self.query(
+            '''
+            query mustahiks($dataSources: [ID]) {
+                mustahiks(dataSources: $dataSources) {
+                    dataSource {
+                        id
+                    }
+                }
+            }
+            ''',
+            op_name='mustahiks',
+            variables={'dataSources': [dataSourceId]}
+        )
+
+        content = json.loads(response.content)
+        self.assertEqual(len(content['data']['mustahiks']), 0)
+
     def test_data_sources_query_should_return_list_data_sources(self):
         response = self.query(
             '''
-- 
GitLab


From 2b265ebb2df76814429bcefb4e84d1575e7a707d Mon Sep 17 00:00:00 2001
From: hashlash <muh.ashlah@gmail.com>
Date: Fri, 4 Sep 2020 10:07:10 +0700
Subject: [PATCH 6/9] [CHORES] add django admin for mustahik related models

---
 sizakat/mustahik/admin.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/sizakat/mustahik/admin.py b/sizakat/mustahik/admin.py
index 8c38f3f..bca847d 100644
--- a/sizakat/mustahik/admin.py
+++ b/sizakat/mustahik/admin.py
@@ -1,3 +1,17 @@
 from django.contrib import admin
 
-# Register your models here.
+from .models import (
+    Mustahik,
+    DataSource,
+    DataSourceWarga,
+    DataSourceInstitusi,
+    DataSourcePekerja,
+)
+
+admin.site.register([
+    Mustahik,
+    DataSource,
+    DataSourceWarga,
+    DataSourceInstitusi,
+    DataSourcePekerja,
+])
-- 
GitLab


From 5c0bff978114936a3bb4830d43f38755f8e6c3da Mon Sep 17 00:00:00 2001
From: hashlash <muh.ashlah@gmail.com>
Date: Fri, 4 Sep 2020 18:41:21 +0700
Subject: [PATCH 7/9] [CHORES] change mustahik photo to imagefield

---
 Dockerfile                                     |  2 +-
 requirements.txt                               |  1 +
 ...0003_change_mustahik_photo_to_imagefield.py | 18 ++++++++++++++++++
 sizakat/mustahik/models.py                     |  2 +-
 4 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 sizakat/mustahik/migrations/0003_change_mustahik_photo_to_imagefield.py

diff --git a/Dockerfile b/Dockerfile
index 59005e6..2c9d4ff 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -8,7 +8,7 @@ ENV PYTHONUNBUFFERED 1
 COPY ./requirements.txt .
 
 RUN apk add --no-cache --virtual .build-deps \
-    gcc postgresql-dev libpq musl-dev \
+    gcc postgresql-dev libpq musl-dev jpeg-dev zlib-dev\
     && pip install --upgrade pip \
     && pip install -r requirements.txt \
     && find /usr/local \
diff --git a/requirements.txt b/requirements.txt
index cb089ee..fca7eb3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,5 +6,6 @@ django-graphql-jwt==0.3.1
 graphene-django==2.10.1
 gunicorn==20.0.4
 psycopg2-binary==2.8.5
+Pillow==7.2.0
 pytz==2020.1
 sqlparse==0.3.1
diff --git a/sizakat/mustahik/migrations/0003_change_mustahik_photo_to_imagefield.py b/sizakat/mustahik/migrations/0003_change_mustahik_photo_to_imagefield.py
new file mode 100644
index 0000000..c5ac8ca
--- /dev/null
+++ b/sizakat/mustahik/migrations/0003_change_mustahik_photo_to_imagefield.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.7 on 2020-09-04 11:39
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('mustahik', '0002_auto_20200816_1347'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='mustahik',
+            name='photo',
+            field=models.ImageField(default='images/default_photo.jpg', upload_to='images/mustahik'),
+        ),
+    ]
diff --git a/sizakat/mustahik/models.py b/sizakat/mustahik/models.py
index 1797390..40932b6 100644
--- a/sizakat/mustahik/models.py
+++ b/sizakat/mustahik/models.py
@@ -33,7 +33,7 @@ class Mustahik(models.Model):
     birthdate = models.DateField()
     status = models.CharField(max_length=32, choices=Status.choices)
     gender = models.CharField(max_length=1, choices=Gender.choices)
-    photo = models.FileField(
+    photo = models.ImageField(
         upload_to=os.path.join('images', 'mustahik'),
         default=os.path.join('images', 'default_photo.jpg')
     )
-- 
GitLab


From 441589687ca65cf4f1291a6ea22f7b2d06189270 Mon Sep 17 00:00:00 2001
From: hashlash <muh.ashlah@gmail.com>
Date: Fri, 4 Sep 2020 18:42:22 +0700
Subject: [PATCH 8/9] [CHORES] configure media files

---
 docker-compose.yml  | 3 +++
 nginx/default.conf  | 4 ++++
 sizakat/settings.py | 4 ++--
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/docker-compose.yml b/docker-compose.yml
index c1527a1..e280d56 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -9,6 +9,7 @@ services:
     volumes:
       - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
       - staticfiles:/var/www/html/static/
+      - mediafiles:/var/www/html/media/
     depends_on:
       - backend
 
@@ -20,6 +21,7 @@ services:
     volumes:
       - ./:/app/backend/
       - staticfiles:/app/backend/staticfiles/
+      - mediafiles:/app/backend/mediafiles/
     env_file:
       - .env
     environment:
@@ -39,3 +41,4 @@ services:
 volumes:
   postgres_data:
   staticfiles:
+  mediafiles:
diff --git a/nginx/default.conf b/nginx/default.conf
index 4b5e6f7..aef744d 100644
--- a/nginx/default.conf
+++ b/nginx/default.conf
@@ -5,6 +5,10 @@ server {
         root /var/www/html/;
     }
 
+    location /media/ {
+        root /var/www/html/;
+    }
+
     location / {
         proxy_pass http://backend:8000;
         proxy_set_header Host $http_host;
diff --git a/sizakat/settings.py b/sizakat/settings.py
index a3e25ad..7b2a30a 100644
--- a/sizakat/settings.py
+++ b/sizakat/settings.py
@@ -141,5 +141,5 @@ USE_TZ = True
 
 STATIC_URL = '/static/'
 STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
-MEDIA_URL = '/img/'
-MEDIA_ROOT = os.path.join(BASE_DIR, 'images')
+MEDIA_URL = '/media/'
+MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
-- 
GitLab


From e9140eb0faca3d8b7e7eecc57f271745656d2c54 Mon Sep 17 00:00:00 2001
From: hashlash <muh.ashlah@gmail.com>
Date: Fri, 4 Sep 2020 23:22:18 +0700
Subject: [PATCH 9/9] [REFACTOR] change mustahik photo representation to
 absolute uri

---
 sizakat/mustahik/types.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sizakat/mustahik/types.py b/sizakat/mustahik/types.py
index 2b1a7a2..a7e626b 100644
--- a/sizakat/mustahik/types.py
+++ b/sizakat/mustahik/types.py
@@ -13,6 +13,9 @@ class MustahikType(DjangoObjectType):
 
     age = graphene.Int(source='calculate_age')
 
+    def resolve_photo(self, info, **kwargs):
+        return self.photo and info.context.build_absolute_uri(self.photo.url)
+
 
 class DataSourceInstitusiType(DjangoObjectType):
     class Meta:
-- 
GitLab