멘토니께 리뷰를 받았다. 우리팀 백엔드는 총 3명으로 업무를 페이지별로 나누었다. 일반 유저가 볼 수 있는 제품 필터 페이지가 있고 호스트가 따로 볼 수 있는 제품 필터 페이지가 있었는데 제품 필터 기능을 내가 진행하고 있었기 때문에 한번에 받아서 작성하라는 말씀이셨다. 갑자기 업무가 늘어났다. 원래도 내 속도에 맞지 않은 많은 업무라고 생각했는데 갑자기 우리팀 모두 많이 바빠졌다. 호스트가 받는 제품 리스트도 따로 작성했고 검색 기능도 작성해보았다. 또한 기존에 페이지별로 작성했던 것들을 기능별로 분류했다. 제품에 대한 정보를 전달하는 기능, 호스트 정보에 대한 기능, 리뷰기능을 분류했다. 특히 검색과 예약쪽은 깊이 들어갈 수록 생각해야 하는 부분이 많아서 매우 어려웠다. 하지만 시간이 부족해서 가장 간단하게만 작성했다.
class HostResistPlaceList(View):
@login_authorization
def get(sef, request):
try:
user = request.user
host = Host.objects.get(user_id=user.id)
if not host:
return JsonResponse({'message': 'You\'ar not host'}, status=401)
places = Place.objects.filter(host_id=host.id)
hostplace = [{
"id" : place.id,
"title" : place.title,
"subtitle" : place.subtitle,
"img_url" : place.image_url,
"location" : place.location,
"closed_date" : place.close_date,
"running_date" : place.running_date if place.running_date.strftime("%Y-%m-%d") >= datetime.now()
.strftime("%Y-%m-%d") else "is_closed",
} for place in places]
return JsonResponse({'results': hostplace}, status=200)
except AttributeError:
return JsonResponse({'message': 'None host'}, status=403)
class PlaceSearchView(View):
def get(self, request):
word = request.GET.get('k', None)
q = Q()
if word:
q &= Q(title__icontains=word)
places = Place.objects.filter(q)
result = [{
'id': place.id,
'img_url': place.image_url,
'title': place.title,
'subtitle': place.subtitle,
'location': place.location,
'price': place.price
}for place in places]
return JsonResponse({'result': result}, status=200)
class PlaceInformationView(View):
def get(self, request, place_id):
try:
place = Place.objects.get(id=place_id)
result = {
'id' : place.id,
'title' : place.title,
'image_url' : place.image_url,
'subtitle' : place.subtitle,
'running_date' : place.running_date,
'location' : place.location,
'max_visitor' : place.max_visitor,
'running_time' : place.running_time,
'price' : place.price,
'preparation' : place.preparation,
'latitude' : place.latitude,
'longitude' : place.longitude
}
return JsonResponse({'result': result}, status=200)
except Place.DoesNotExist:
return JsonResponse({'message': 'Place does not exit'}, status=404)