Skip to content

Commit

Permalink
Merge pull request #86 from resum-ai/feat/resume
Browse files Browse the repository at this point in the history
Feat/resume
  • Loading branch information
yjoonjang authored Apr 13, 2024
2 parents 4de5794 + 6f88756 commit 8fe1fdd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.0.3 on 2024-04-13 08:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="customuser",
name="available_chat_count",
field=models.IntegerField(default=5),
),
migrations.AddField(
model_name="customuser",
name="reset_chat_date",
field=models.DateField(blank=True, null=True),
),
]
3 changes: 3 additions & 0 deletions accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
is_active = models.BooleanField(default=True) # 계정 활성화 상태
created_at = models.DateTimeField(auto_now_add=True)

available_chat_count = models.IntegerField(default=5)
reset_chat_date = models.DateField(null=True, blank=True)

USERNAME_FIELD = "email"
REQUIRED_FIELDS = []

Expand Down
10 changes: 10 additions & 0 deletions resume/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from datetime import datetime

from django.http import Http404
from django.db.models import Q
Expand Down Expand Up @@ -386,6 +387,13 @@ class ChatView(APIView):
},
)
def post(self, request, id):
user = request.user
today = datetime.now().date()

# 채팅 횟수 count
if user.chat_count <= 0:
return JsonResponse({"error": "채팅 횟수가 모두 소진되었습니다."}, status=status.HTTP_403_FORBIDDEN)

query = request.data.get("query", "")

resume = get_object_or_404(Resume, pk=id)
Expand All @@ -408,6 +416,8 @@ def post(self, request, id):
resume=resume, query=query, response=chatbot_response
)
new_chat_history.save()
user.available_chat_count -= 1
user.save()

# 챗봇의 응답을 반환
return JsonResponse({"answer": chatbot_response}, status=status.HTTP_200_OK)
Expand Down

0 comments on commit 8fe1fdd

Please sign in to comment.