Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 0 additions & 2 deletions teeting_backend/assignment/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Generated by Django 3.2.9 on 2021-11-22 05:37

import datetime
from django.db import migrations, models

Expand Down
1 change: 1 addition & 0 deletions teeting_backend/finance/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion teeting_backend/finance/migrations/0002_analysis_child.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion teeting_backend/finance/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
path('analysis', ChildAnalysisView.as_view()), # 자녀분석 조회 ?childId=<int>
path('balance/', ParentBalanceView.as_view()), # 잔액조회 부모
path('balance/child', ChildBalanceView.as_view()), # 잔액조회 자녀
path('transaction', ChildTransactionView.as_view()), # 거래내역조회 자녀 ?childId=<int>&period=<string>
# path('transaction', ChildTransactionView.as_view()), # 거래내역조회 자녀 부모 포함?childId=<int>&period=<string>
path('transaction', TransactionView.as_view()),
path('remittance', RemittanceView.as_view()), #송금하기, ?childId=<int>
]
145 changes: 94 additions & 51 deletions teeting_backend/finance/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down Expand Up @@ -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 = []
Expand All @@ -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)


# 자녀 분석결과 조회
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions teeting_backend/ttAccount/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions teeting_backend/ttAccount/migrations/0002_user_birthda.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
Original file line number Diff line number Diff line change
@@ -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',
),
]
1 change: 1 addition & 0 deletions teeting_backend/ttAccount/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down