diff --git a/taxi_project/myAPP/models.py b/taxi_project/myAPP/models.py index cfffae6..d952953 100644 --- a/taxi_project/myAPP/models.py +++ b/taxi_project/myAPP/models.py @@ -76,3 +76,18 @@ def save(self, *args, **kwargs): def __str__(self): return self.address_name +class Taxi(models.Model): + license_number = models.CharField(max_length=10) + # 택시 위도 - 고정 + latitude = models.DecimalField(max_digits=10, decimal_places=6) + # 택시 경도 - 고정 + longitude = models.DecimalField(max_digits=10, decimal_places=6) + driver_name = models.CharField(max_length=5) + driver_phone = models.CharField( + max_length=13, + validators=[RegexValidator(regex=r'^010-\d{4}-\d{4}$', message='올바른 연락처 형식이 아닙니다.')] + ) + acceptance = models.IntegerField(default = 0) + + def __str__(self): + return self.license_number \ No newline at end of file diff --git a/taxi_project/myAPP/serializer.py b/taxi_project/myAPP/serializer.py index ac36e36..be68585 100644 --- a/taxi_project/myAPP/serializer.py +++ b/taxi_project/myAPP/serializer.py @@ -50,4 +50,8 @@ class UserInfoSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('user_name', 'user_age', 'user_gender') - \ No newline at end of file + +class TaxiSerializer(serializers.ModelSerializer): + class Meta: + model = Taxi + fields = '__all__' \ No newline at end of file diff --git a/taxi_project/myAPP/urls.py b/taxi_project/myAPP/urls.py index 9ec22b1..a473d48 100644 --- a/taxi_project/myAPP/urls.py +++ b/taxi_project/myAPP/urls.py @@ -5,4 +5,5 @@ urlpatterns = [ path('signup', views.signup), path('login', views.login), + path('taxi', views.new_taxi) ] \ No newline at end of file diff --git a/taxi_project/myAPP/views.py b/taxi_project/myAPP/views.py index b86a9a4..b2cc36a 100644 --- a/taxi_project/myAPP/views.py +++ b/taxi_project/myAPP/views.py @@ -60,4 +60,20 @@ def login(request): return Response({'status':'200', 'refresh_token': refresh_token, 'access_token': access_token, }, status=status.HTTP_200_OK) - return Response({'status':'401', 'message': '아이디 또는 비밀번호가 일치하지 않습니다.'}, status=status.HTTP_401_UNAUTHORIZED) \ No newline at end of file + return Response({'status':'401', 'message': '아이디 또는 비밀번호가 일치하지 않습니다.'}, status=status.HTTP_401_UNAUTHORIZED) + +@swagger_auto_schema( + method="POST", + tags=["택시 api"], + operation_summary="택시 생성", + request_body=TaxiSerializer +) +@api_view(['POST']) +@permission_classes([AllowAny]) +def new_taxi(request): + serializer = TaxiSerializer(data = request.data) + + if serializer.is_valid(): + serializer.save() + return Response({'status':'201','message': 'All data added successfully'}, status=201) + return Response({'status':'400','message':serializer.errors}, status=400) \ No newline at end of file