diff --git a/teeting_backend/assignment/migrations/0001_initial.py b/teeting_backend/assignment/migrations/0001_initial.py index 6bb8ddb..c2dcceb 100644 --- a/teeting_backend/assignment/migrations/0001_initial.py +++ b/teeting_backend/assignment/migrations/0001_initial.py @@ -1,5 +1,3 @@ -# Generated by Django 3.2.9 on 2021-11-22 05:37 - import datetime from django.db import migrations, models diff --git a/teeting_backend/finance/migrations/0001_initial.py b/teeting_backend/finance/migrations/0001_initial.py index 921b0bf..2cffadc 100644 --- a/teeting_backend/finance/migrations/0001_initial.py +++ b/teeting_backend/finance/migrations/0001_initial.py @@ -1,5 +1,6 @@ # Generated by Django 3.2.9 on 2021-11-22 05:37 + 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 af345e5..0863b62 100644 --- a/teeting_backend/finance/migrations/0002_analysis_child.py +++ b/teeting_backend/finance/migrations/0002_analysis_child.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.9 on 2021-11-22 05:37 +# Generated by Django 3.2.9 on 2021-11-22 05:37 from django.db import migrations, models import django.db.models.deletion 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/ttAccount/migrations/0001_initial.py b/teeting_backend/ttAccount/migrations/0001_initial.py index f751153..da92037 100644 --- a/teeting_backend/ttAccount/migrations/0001_initial.py +++ b/teeting_backend/ttAccount/migrations/0001_initial.py @@ -1,5 +1,6 @@ # Generated by Django 3.2.9 on 2021-11-22 05:37 + 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)