From 0c8ea96290c9eaa017bbf26d4b07825ba61c68fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=90=EC=A0=95=EB=B2=94?= <2018027383@hanyang.ac.kr> Date: Mon, 22 Nov 2021 19:43:48 +0900 Subject: [PATCH] =?UTF-8?q?[feat#33]=20=EB=B6=80=EB=AA=A8=20=EA=B1=B0?= =?UTF-8?q?=EB=9E=98=EB=82=B4=EC=97=AD=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assignment/migrations/0001_initial.py | 1 + .../assignment/migrations/0002_initial.py | 6 +- .../finance/migrations/0001_initial.py | 1 + .../finance/migrations/0002_analysis_child.py | 3 +- teeting_backend/finance/urls.py | 3 +- teeting_backend/finance/views.py | 145 ++++++++++++------ teeting_backend/teeting_backend/settings.py | 4 +- .../ttAccount/migrations/0001_initial.py | 2 + .../ttAccount/migrations/0002_user_birthda.py | 19 +++ .../0003_rename_birthda_user_birthday.py | 18 +++ teeting_backend/ttAccount/models.py | 1 + 11 files changed, 146 insertions(+), 57 deletions(-) create mode 100644 teeting_backend/ttAccount/migrations/0002_user_birthda.py create mode 100644 teeting_backend/ttAccount/migrations/0003_rename_birthda_user_birthday.py diff --git a/teeting_backend/assignment/migrations/0001_initial.py b/teeting_backend/assignment/migrations/0001_initial.py index 800fac0..5a7597a 100644 --- a/teeting_backend/assignment/migrations/0001_initial.py +++ b/teeting_backend/assignment/migrations/0001_initial.py @@ -1,3 +1,4 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:24 import datetime from django.db import migrations, models diff --git a/teeting_backend/assignment/migrations/0002_initial.py b/teeting_backend/assignment/migrations/0002_initial.py index 94cfb7a..b99a611 100644 --- a/teeting_backend/assignment/migrations/0002_initial.py +++ b/teeting_backend/assignment/migrations/0002_initial.py @@ -1,3 +1,4 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:24 from django.conf import settings from django.db import migrations, models @@ -9,11 +10,10 @@ class Migration(migrations.Migration): initial = True dependencies = [ - + ('assignment', '0001_initial'), ('ttAccount', '0001_initial'), migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ('assignment', '0001_initial'), - + ] operations = [ migrations.AddField( diff --git a/teeting_backend/finance/migrations/0001_initial.py b/teeting_backend/finance/migrations/0001_initial.py index ade193b..71de44f 100644 --- a/teeting_backend/finance/migrations/0001_initial.py +++ b/teeting_backend/finance/migrations/0001_initial.py @@ -1,3 +1,4 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:24 import django.core.validators from django.db import migrations, models diff --git a/teeting_backend/finance/migrations/0002_analysis_child.py b/teeting_backend/finance/migrations/0002_analysis_child.py index 0285f0c..a032d23 100644 --- a/teeting_backend/finance/migrations/0002_analysis_child.py +++ b/teeting_backend/finance/migrations/0002_analysis_child.py @@ -1,3 +1,4 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:24 from django.db import migrations, models import django.db.models.deletion @@ -8,8 +9,8 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ('finance', '0001_initial'), ('ttAccount', '0001_initial'), + ('finance', '0001_initial'), ] operations = [ diff --git a/teeting_backend/finance/urls.py b/teeting_backend/finance/urls.py index cb4d866..e406f0a 100644 --- a/teeting_backend/finance/urls.py +++ b/teeting_backend/finance/urls.py @@ -23,6 +23,7 @@ path('analysis', ChildAnalysisView.as_view()), # 자녀분석 조회 ?childId= path('balance/', ParentBalanceView.as_view()), # 잔액조회 부모 path('balance/child', ChildBalanceView.as_view()), # 잔액조회 자녀 - path('transaction', ChildTransactionView.as_view()), # 거래내역조회 자녀 ?childId=&period= + # path('transaction', ChildTransactionView.as_view()), # 거래내역조회 자녀 부모 포함?childId=&period= + path('transaction', TransactionView.as_view()), path('remittance', RemittanceView.as_view()), #송금하기, ?childId= ] \ No newline at end of file diff --git a/teeting_backend/finance/views.py b/teeting_backend/finance/views.py index 0ef653a..6ce1ff0 100644 --- a/teeting_backend/finance/views.py +++ b/teeting_backend/finance/views.py @@ -70,7 +70,7 @@ def get(self, request): data["balance"] = int(res.json()["Ldbl"]) return HttpResponse(json.dumps(data), content_type="text/json-comment-filtered", status = status.HTTP_200_OK) else : - return HttpResponse(res.status_code) + return HttpResponse("No User", res.status_code) # 잔액조회 (자녀) class ChildBalanceView(APIView) : @@ -126,65 +126,110 @@ def get(self, request): children_data["balance"] = int(res.json()["Ldbl"]) data.append(children_data) else : - return HttpResponse(res.status_code) + return HttpResponse("No child", res.status_code) return HttpResponse(json.dumps(data), content_type="text/json-comment-filtered", status = status.HTTP_200_OK) - -# 자녀 거래내역 조회 -class ChildTransactionView(APIView) : +# 거래내역 조회 -> params가 있다면 자녀거래내역 조회 / 없다면 유저(부모)의 거래내역 조회 +class TransactionView(APIView) : permission_classes = [IsAuthenticated] authentication_classes = [TokenAuthentication] def get(self, request): + url = 'https://developers.nonghyup.com/InquireTransactionHistory.nh' # 거래내역 조회 url + user = User.objects.filter(username = self.request.user).first() childId = self.request.query_params.get('childId') - currentUser = User.objects.filter(username = self.request.user).first() - child = Child.objects.filter(parent = currentUser).filter(pk = childId).first() + + # params로 받은 childId값이 없다면 유저거래내역 조회 + if not childId : + apiNm = url[url.find(".com/")+5:url.find(".nh")] + tsymd = datetime.today().strftime("%Y%m%d") + trtm = "112428" + iscd = user.iscd + fintechApsno = "001" + apiSvcCd = "ReceivedTransferA" + # isTuno = 임의번호로 채번 + accessToken = user.accessToken + bncd = "011" # 농협은행코드 고정값 + acno = user.acno + insymd = (datetime.today() + relativedelta(days=-90)).strftime("%Y%m%d") + ineymd = datetime.today().strftime("%Y%m%d") + trnsDsnc = "A" + lnsq = "DESC" + pageNo = "1" + dmcnt = "100" + + headers = { + "Content-Type": "application/json; chearset=utf-8", + } - url = 'https://developers.nonghyup.com/InquireTransactionHistory.nh' # 거래내역 조회 url + body = { + "Header": { + "ApiNm": apiNm, + "Tsymd": tsymd, + "Trtm": trtm, + "Iscd": iscd, + "FintechApsno": fintechApsno, + "ApiSvcCd": apiSvcCd, + "IsTuno": "0007773" + str(random.randint(0,10000)), # isTuno + "AccessToken": accessToken + }, + "Bncd": bncd, + "Acno": acno, + "Insymd": insymd, + "Ineymd": ineymd, + "TrnsDsnc": trnsDsnc, + "Lnsq": lnsq, + "PageNo": pageNo, + "Dmcnt": dmcnt + } + + # params로 받은 childId값이 있다면 유저거래내역 조회 + else : + child = Child.objects.filter(parent = user).filter(pk = childId).first() - apiNm = url[url.find(".com/")+5:url.find(".nh")] - tsymd = datetime.today().strftime("%Y%m%d") - trtm = "112428" - iscd = child.iscd - fintechApsno = "001" - apiSvcCd = "ReceivedTransferA" - # isTuno = 임의번호로 채번 - accessToken = child.accessToken - bncd = "011" # 농협은행코드 고정값 - acno = child.acno - insymd = (datetime.today() + relativedelta(days=-90)).strftime("%Y%m%d") - ineymd = datetime.today().strftime("%Y%m%d") - trnsDsnc = "A" - lnsq = "DESC" - pageNo = "1" - dmcnt = "100" - - headers = { - "Content-Type": "application/json; chearset=utf-8", - } + apiNm = url[url.find(".com/")+5:url.find(".nh")] + tsymd = datetime.today().strftime("%Y%m%d") + trtm = "112428" + iscd = child.iscd + fintechApsno = "001" + apiSvcCd = "ReceivedTransferA" + # isTuno = 임의번호로 채번 + accessToken = child.accessToken + bncd = "011" # 농협은행코드 고정값 + acno = child.acno + insymd = (datetime.today() + relativedelta(days=-90)).strftime("%Y%m%d") + ineymd = datetime.today().strftime("%Y%m%d") + trnsDsnc = "A" + lnsq = "DESC" + pageNo = "1" + dmcnt = "100" + + headers = { + "Content-Type": "application/json; chearset=utf-8", + } - body = { - "Header": { - "ApiNm": apiNm, - "Tsymd": tsymd, - "Trtm": trtm, - "Iscd": iscd, - "FintechApsno": fintechApsno, - "ApiSvcCd": apiSvcCd, - "IsTuno": "0007773" + str(random.randint(0,10000)), # isTuno - "AccessToken": accessToken - }, - "Bncd": bncd, - "Acno": acno, - "Insymd": insymd, - "Ineymd": ineymd, - "TrnsDsnc": trnsDsnc, - "Lnsq": lnsq, - "PageNo": pageNo, - "Dmcnt": dmcnt - } + body = { + "Header": { + "ApiNm": apiNm, + "Tsymd": tsymd, + "Trtm": trtm, + "Iscd": iscd, + "FintechApsno": fintechApsno, + "ApiSvcCd": apiSvcCd, + "IsTuno": "0007773" + str(random.randint(0,10000)), # isTuno + "AccessToken": accessToken + }, + "Bncd": bncd, + "Acno": acno, + "Insymd": insymd, + "Ineymd": ineymd, + "TrnsDsnc": trnsDsnc, + "Lnsq": lnsq, + "PageNo": pageNo, + "Dmcnt": dmcnt + } # 프론트에 response로 줄 json data data = [] @@ -206,8 +251,7 @@ def get(self, request): return HttpResponse(json.dumps(data), content_type="text/json-comment-filtered", status = status.HTTP_200_OK) else : - return HttpResponse(res.status_code) - + return HttpResponse("No User or No Child", res.status_code) # 자녀 분석결과 조회 @@ -228,7 +272,6 @@ def get(self, request): if not child : return HttpResponse("You don't have such child", status=status.HTTP_400_BAD_REQUEST) - # 필터링할 날짜 범위 지정 if period == "week" : start_date = datetime.now().date() + relativedelta(days=-7) diff --git a/teeting_backend/teeting_backend/settings.py b/teeting_backend/teeting_backend/settings.py index 684d09e..bdbb952 100644 --- a/teeting_backend/teeting_backend/settings.py +++ b/teeting_backend/teeting_backend/settings.py @@ -151,4 +151,6 @@ 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication', ) -} \ No newline at end of file +} + +SITE_ID = 1 \ No newline at end of file diff --git a/teeting_backend/ttAccount/migrations/0001_initial.py b/teeting_backend/ttAccount/migrations/0001_initial.py index a8959bf..b9f9216 100644 --- a/teeting_backend/ttAccount/migrations/0001_initial.py +++ b/teeting_backend/ttAccount/migrations/0001_initial.py @@ -1,3 +1,5 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:24 + from django.conf import settings from django.db import migrations, models import django.db.models.deletion diff --git a/teeting_backend/ttAccount/migrations/0002_user_birthda.py b/teeting_backend/ttAccount/migrations/0002_user_birthda.py new file mode 100644 index 0000000..39abdf8 --- /dev/null +++ b/teeting_backend/ttAccount/migrations/0002_user_birthda.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ttAccount', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='birthda', + field=models.CharField(default=19990221, max_length=8), + preserve_default=False, + ), + ] diff --git a/teeting_backend/ttAccount/migrations/0003_rename_birthda_user_birthday.py b/teeting_backend/ttAccount/migrations/0003_rename_birthda_user_birthday.py new file mode 100644 index 0000000..363bff2 --- /dev/null +++ b/teeting_backend/ttAccount/migrations/0003_rename_birthda_user_birthday.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.9 on 2021-11-22 10:32 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('ttAccount', '0002_user_birthda'), + ] + + operations = [ + migrations.RenameField( + model_name='user', + old_name='birthda', + new_name='birthday', + ), + ] diff --git a/teeting_backend/ttAccount/models.py b/teeting_backend/ttAccount/models.py index 0e1ebb5..6b5b83f 100644 --- a/teeting_backend/ttAccount/models.py +++ b/teeting_backend/ttAccount/models.py @@ -48,6 +48,7 @@ class User(AbstractBaseUser, PermissionsMixin) : username = models.CharField(max_length=30, unique=True) firstname = models.CharField(max_length=30) lastname = models.CharField(max_length=30) + birthday = models.CharField(max_length=8) is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=True)