Skip to content

Commit

Permalink
fix(word): fix the bug about .add() (#325)
Browse files Browse the repository at this point in the history
* fix(word): fix a bug about .add() on WD0601

* fix(word): fix a bug about delete on WD0602

* feat(word): delete unnecessary file

* fix(word): update the "words" in request.body

* fix(word): Transfer the list_id to the path parameter on WD0604

* feat(word): use len() to display quantities on WD0605

* fix(word): transfer list_id into path parameter on WD0606

fix(utils): fix typos

* fix(word): transfer list_id into path parameter on WD0607

* feat(word): add test files
CapooL authored Sep 11, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 93b0a1c commit 71304de
Showing 7 changed files with 4,485 additions and 34 deletions.
2 changes: 1 addition & 1 deletion hinghwa-dict-backend/utils/exception/types/not_found.py
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ def __init__(self, id=""):
class ListsNotFoundException(NotFoundException):
"""
词单不存在
param id:订单id
param id:词单id
"""

def __init__(self, id=""):
13 changes: 5 additions & 8 deletions hinghwa-dict-backend/word/lists/view/manage_all_list.py
Original file line number Diff line number Diff line change
@@ -23,17 +23,14 @@ def post(self, request):
if not list_form.is_valid():
raise BadRequestException()
list = list_form.save(commit=False)
list.createTime = timezone.now()
list.updateTime = timezone.now()
list.author = user
list.id = generate_list_id()
for id in body["words"]:
word = Word.objects.get(id=id)
print()
print(list)
print(type(word))
list.save()
list.words.add(word)
list.author = user
list.createTime = timezone.now()
list.updateTime = timezone.now()
list.save()
return JsonResponse(list_all(list), status=200)

# WD0605查找词单(多)
@@ -43,4 +40,4 @@ def get(self, request):
result = []
for list in total_list:
result.append(list_all(list))
return JsonResponse({"total": result.count(), "lists": result})
return JsonResponse({"total": len(result), "lists": result})
19 changes: 12 additions & 7 deletions hinghwa-dict-backend/word/lists/view/manage_single_list.py
Original file line number Diff line number Diff line change
@@ -14,9 +14,8 @@
class ManageSingleLists(View):
# WD0602删除词单
@csrf_exempt
def delete(self, request):
def delete(self, request, list_id):
token_pass(request.headers, -1)
list_id = request.GET["list_id"]
list = List.objects.filter(id=list_id)
if not list.exists():
raise ListsNotFoundException()
@@ -25,23 +24,29 @@ def delete(self, request):
return JsonResponse({}, status=200)

# WD0603更改词单信息
def put(self, request):
def put(self, request, list_id):
token_pass(request.headers, -1)
list_id = request.GET["list_id"]
list = List.objects.filter(id=list_id)
if not list.exists():
raise ListsNotFoundException()
list = list[0]
body = demjson.decode(request.body)
for key in body:
setattr(list, key, body[key])
if key != "words":
setattr(list, key, body[key])
else:
for id in body["words"]:
Word.objects.get(id=id)
list.words.clear()
for id in body["words"]:
word = Word.objects.get(id=id)
list.words.add(word)
list.save()
return JsonResponse(list_all(list), status=200)

# WD0604查看词单(单)
def get(self, request):
def get(self, request, list_id):
token_pass(request.headers, 0)
list_id = request.GET["list_id"]
list = List.objects.filter(id=list_id)
if not list.exists():
raise ListsNotFoundException()
15 changes: 6 additions & 9 deletions hinghwa-dict-backend/word/lists/view/manage_word_in_list.py
Original file line number Diff line number Diff line change
@@ -15,28 +15,25 @@
class ManageListWords(View):
# WD0606增加词单词语
@csrf_exempt
def post(self, request):
def post(self, request, list_id):
token_pass(request.headers, -1)
list_id = request.GET["list_id"]
list = List.objects.filter(id=list_id)
if not list.exists():
raise ListsNotFoundException()
body = demjson.decode(request)
list = list[0]
body = demjson.decode(request.body)
for id in body["words"]:
word = Word.objects.get(id=id)
if not word:
raise WordNotFoundException()
list.words.add(word)
list.updateTime = timezone.now()
list.save()
return JsonResponse(list_all(list), status=200)

# WD0607删除词单词语
@csrf_exempt
def delete(self, request):
def delete(self, request, list_id):
token_pass(request.headers, -1)
list_id = request.GET["list_id"]
body = demjson.decode(request)
body = demjson.decode(request.body)
list = List.objects.filter(id=list_id)
if not list.exists():
raise ListsNotFoundException()
@@ -48,4 +45,4 @@ def delete(self, request):
list.words.remove(word)
list.updateTime = timezone.now()
list.save()
return JsonResponse({}, status=200)
return JsonResponse(list_all(list), status=200)
9 changes: 0 additions & 9 deletions hinghwa-dict-backend/word/lists/views.py

This file was deleted.

2,792 changes: 2,792 additions & 0 deletions tests/word_list_200.json

Large diffs are not rendered by default.

1,669 changes: 1,669 additions & 0 deletions tests/word_list_404.json

Large diffs are not rendered by default.

0 comments on commit 71304de

Please sign in to comment.