Skip to content

Commit aa22f9e

Browse files
authored
Merge: 대여기록 생성 버그 수정, 테스트 코드 수정, 코드 포매터 적용
[Hotfix/inspection] 대여기록 생성 버그 수정, 테스트 코드 수정, 코드 포매터 적용
2 parents 89abdc1 + f4ffaa5 commit aa22f9e

File tree

7 files changed

+27
-14
lines changed

7 files changed

+27
-14
lines changed

apps/chat/serializers.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ class EnterChatroomSerializer(serializers.ModelSerializer[Chatroom]):
8585
class Meta:
8686
model = Chatroom
8787
fields = [
88-
"product", "product_image", "product_name", "product_rental_fee", "product_condition", "rental_history"
88+
"product",
89+
"product_image",
90+
"product_name",
91+
"product_rental_fee",
92+
"product_condition",
93+
"rental_history",
8994
]
9095

9196
def to_representation(self, instance: Chatroom) -> Dict[str, Any]:

apps/chat/views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
from rest_framework.views import APIView
1212

1313
from apps.chat import serializers
14-
from apps.chat.models import Chatroom, Message
14+
from apps.chat.models import Chatroom
1515
from apps.chat.utils import (
1616
change_entered_status,
1717
check_entered_chatroom,
1818
delete_chatroom,
1919
)
20-
from apps.product.serializers import RentalHistorySerializer, RentalHistoryStatusSerializer
20+
from apps.product.serializers import RentalHistoryStatusSerializer
2121
from apps.user.api_schema import UserInfoSerializer
2222

2323

@@ -86,7 +86,7 @@ class ChatDetailView(APIView):
8686
"product_rental_fee": serializer.CharField(),
8787
"product_condition": serializer.CharField(),
8888
"messages": serializers.MessageSerializer(many=True),
89-
"rental_history": RentalHistoryStatusSerializer()
89+
"rental_history": RentalHistoryStatusSerializer(),
9090
},
9191
),
9292
description="""

apps/product/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class RentalHistory(BaseModel):
6060
]
6161
product = models.ForeignKey(Product, on_delete=models.CASCADE)
6262
borrower = models.ForeignKey(Account, on_delete=models.CASCADE)
63-
rental_date = models.DateTimeField(auto_now_add=True)
64-
return_date = models.DateTimeField(null=True, blank=True) # 대여 반납일
63+
rental_date = models.DateTimeField()
64+
return_date = models.DateTimeField() # 대여 반납일
6565
status = models.CharField(choices=STATUS_CHOICE, default="REQUEST", max_length=10)
6666

6767
def __str__(self) -> str:

apps/product/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class RentalHistorySerializer(serializers.ModelSerializer[RentalHistory]):
164164
class Meta:
165165
model = RentalHistory
166166
exclude = ("borrower",)
167-
read_only_fields = ("created_at", "updated_at", "rental_date")
167+
read_only_fields = ("created_at", "updated_at")
168168

169169
def get_lender_nickname(self, obj: RentalHistory) -> str:
170170
return obj.product.lender.nickname

apps/product/tests.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ def setUp(self) -> None:
5353

5454
def test_대여자가_정상적인_물품_대여신청을_했을때(self) -> None:
5555
data = {
56+
"borrower_id": self.borrower.id,
5657
"product": self.product.uuid,
5758
"rental_date": timezone.now(),
5859
"return_date": timezone.now() + timedelta(days=3),
60+
"status": "REQUEST",
5961
}
6062
response = self.client.post(self.url, data, headers={"Authorization": f"Bearer {self.token}"})
6163
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
@@ -73,9 +75,11 @@ def test_이미_대여중인_상품을_대여하려고_시도하는경우_테스
7375
)
7476
self.assertEqual(RentalHistory.objects.count(), 1)
7577
data = {
76-
"product": history.product.uuid,
78+
"borrower_id": int(self.borrower.id),
79+
"product": str(history.product.uuid),
7780
"rental_date": history.rental_date.isoformat(),
78-
"return_date": history.return_date.isoformat(), # type: ignore
81+
"return_date": history.rental_date.isoformat(),
82+
"status": history.status,
7983
}
8084
response = self.client.post(self.url, data, headers={"Authorization": f"Bearer {self.token}"})
8185
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
@@ -188,7 +192,6 @@ def test_대여날짜_변경_테스트(self) -> None:
188192
data = {"return_date": timezone.now() + timedelta(days=4)}
189193

190194
response = self.client.patch(self.url, data=data, headers={"Authorization": f"Bearer {self.token}"})
191-
print(response.data)
192195
self.assertEqual(response.status_code, status.HTTP_200_OK)
193196
self.assertEqual(response.data.get("return_date").split("T")[0], data["return_date"].date().isoformat())
194197

apps/product/views.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,15 @@ def list(self, request: Request, *args: Any, **kwargs: Any) -> Response:
6363
return Response(serializer.data)
6464

6565
def create(self, request: Request, *args: Any, **kwargs: Any) -> Response:
66-
data = request.data.dict() # type: ignore
67-
data["borrower_id"] = self.request.user.id
66+
data = {
67+
"borrower_id": request.data.get("borrower_id"),
68+
"product": request.data.get("product"),
69+
"status": request.data.get("status"),
70+
}
6871
if RentalHistory.objects.filter(**data).exists():
69-
return Response({"msg": "이미 대여 신청중인 내역이 있습니다."}, status=status.HTTP_400_BAD_REQUEST)
72+
return Response({"msg": "이미 상품에 대한 대여 내역이 있습니다."}, status=status.HTTP_400_BAD_REQUEST)
73+
data["rental_date"] = request.data.get("rental_date")
74+
data["return_date"] = request.data.get("return_date")
7075
serializer = self.get_serializer(data=data)
7176
serializer.is_valid(raise_exception=True)
7277
self.perform_create(serializer)

apps/user/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def login_process_user(
263263
domain=settings.CSRF_COOKIE_DOMAIN,
264264
samesite=None,
265265
secure=settings.CSRF_COOKIE_SECURE,
266-
httponly=settings.CSRF_COOKIE_HTTPONLY
266+
httponly=settings.CSRF_COOKIE_HTTPONLY,
267267
)
268268
return response
269269

0 commit comments

Comments
 (0)