From ba44d940a02fff119f05927473da00da7e3e5a03 Mon Sep 17 00:00:00 2001 From: Yaroslav Kivaev Date: Tue, 31 May 2022 09:31:39 +0300 Subject: [PATCH 1/4] OpenAPI created --- backend/InnoCart/urls.py | 6 + backend/openapi.yml | 255 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+) create mode 100644 backend/openapi.yml diff --git a/backend/InnoCart/urls.py b/backend/InnoCart/urls.py index 1f95783..0f47823 100644 --- a/backend/InnoCart/urls.py +++ b/backend/InnoCart/urls.py @@ -18,10 +18,16 @@ from rest_framework.urlpatterns import format_suffix_patterns from orders import views +from rest_framework.schemas import get_schema_view + urlpatterns = [ path('admin/', admin.site.urls), path('orders/', views.order_list), path('orders/', views.order_detail), + path('api_schema/', get_schema_view( + title='API Schema', + description='Guide for the REST API' + ), name='api_schema'), ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/backend/openapi.yml b/backend/openapi.yml new file mode 100644 index 0000000..382c14a --- /dev/null +++ b/backend/openapi.yml @@ -0,0 +1,255 @@ +openapi: 3.0.2 +info: + title: API Schema + version: '' + description: Guide for the REST API +paths: + /orders/: + get: + summary: getAllOrders + operationId: listorder_lists + description: List of all users + parameters: [] + responses: + '200': + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Order' + description: '' + tags: + - orders + post: + summary: createNewOrder + operationId: createorder_list + description: Create new order + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - orders + /orders/{id}: + get: + summary: getOrderById + operationId: retrieveorder_detail + description: Get order by id + parameters: + - name: id + in: path + required: true + description: '' + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: '' + tags: + - orders + put: + summary: acceptOrder + operationId: updateorder_detail + description: Accept order by angel + parameters: + - name: id + in: path + required: true + description: '' + schema: + type: string + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '200': + content: + application/json: + schema: {} + description: '' + tags: + - orders + + /users/: + get: + summary: getAllUsers + operationId: listusers_lists + description: List all code users + parameters: [] + responses: + '200': + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + description: '' + tags: + - customers + post: + summary: createNewUser + operationId: createuser_list + description: Create new user + parameters: [] + requestBody: + content: + application/json: + schema: {} + application/x-www-form-urlencoded: + schema: {} + multipart/form-data: + schema: {} + responses: + '201': + content: + application/json: + schema: {} + description: '' + tags: + - customers + /users/{id}: + get: + summary: getUserById + operationId: listusersbyid_lists + description: Get user by id + parameters: + - name: id + in: path + required: true + description: '' + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/User' + description: '' + tags: + - customers + /users/{id}/orders: + get: + summary: getAllOrdersOfTheUser + operationId: listordersofuser_lists + description: List all user's orders + parameters: + - name: id + in: path + required: true + description: '' + schema: + type: string + responses: + '200': + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Order' + description: '' + tags: + - customers + /users/{id}/orders/{order_id}: + get: + summary: getOrderOfUser + operationId: orderofuser_lists + description: Get user's order by id + parameters: + - name: id + in: path + required: true + description: '' + schema: + type: string + - name: order_id + in: path + required: true + description: '' + schema: + type: string + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/Order' + description: '' + tags: + - customers + +components: + schemas: + User: + type: object + properties: + id: + type: integer + example: 5 + name: + type: string + example: John + phoneNumber: + type: integer + example: 88005553535 + email: + type: string + example: mail@innopolis.ru + required: + - id + - name + - phoneNumber + - email + + OrderStatus: + description: Performing status + type: string + enum: [OFFERED, DELIVERY, PERFORMED] + + Order: + type: object + properties: + id: + type: integer + example: 4 + description: + type: string + example: Description of the + orderStatus: + $ref: '#/components/schemas/OrderStatus' + possibleDeliveryMen: + type: array + items: + $ref: '#/components/schemas/User' + acceptedDeliveryMen: + $ref: '#/components/schemas/User' + required: + - id + - description + - orderStatus + - possibleDeliveryMen + - acceptedDeliveryMen + \ No newline at end of file From a5b9053768dacc6650e24b682ea160529dd211b4 Mon Sep 17 00:00:00 2001 From: angel_in_a_jar Date: Wed, 8 Jun 2022 20:36:28 +0300 Subject: [PATCH 2/4] login, register, deliver --- backend/InnoCart/settings.py | 1 - backend/InnoCart/urls.py | 8 +- backend/openapi.yml | 449 ++++++++++++++++------ backend/orders/__init__.py | 0 backend/orders/admin.py | 3 - backend/orders/apps.py | 6 - backend/orders/migrations/0001_initial.py | 25 -- backend/orders/migrations/__init__.py | 0 backend/orders/models.py | 10 - backend/orders/serializers.py | 29 -- backend/orders/tests.py | 3 - backend/orders/urls.py | 10 - backend/orders/views.py | 50 --- 13 files changed, 332 insertions(+), 262 deletions(-) delete mode 100644 backend/orders/__init__.py delete mode 100644 backend/orders/admin.py delete mode 100644 backend/orders/apps.py delete mode 100644 backend/orders/migrations/0001_initial.py delete mode 100644 backend/orders/migrations/__init__.py delete mode 100644 backend/orders/models.py delete mode 100644 backend/orders/serializers.py delete mode 100644 backend/orders/tests.py delete mode 100644 backend/orders/urls.py delete mode 100644 backend/orders/views.py diff --git a/backend/InnoCart/settings.py b/backend/InnoCart/settings.py index 8f57ad0..142fe80 100644 --- a/backend/InnoCart/settings.py +++ b/backend/InnoCart/settings.py @@ -37,7 +37,6 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'orders', 'rest_framework', 'rest_framework_swagger', ] diff --git a/backend/InnoCart/urls.py b/backend/InnoCart/urls.py index 0f47823..e88b396 100644 --- a/backend/InnoCart/urls.py +++ b/backend/InnoCart/urls.py @@ -16,18 +16,12 @@ from django.contrib import admin from django.urls import path from rest_framework.urlpatterns import format_suffix_patterns -from orders import views from rest_framework.schemas import get_schema_view urlpatterns = [ path('admin/', admin.site.urls), - path('orders/', views.order_list), - path('orders/', views.order_detail), - path('api_schema/', get_schema_view( - title='API Schema', - description='Guide for the REST API' - ), name='api_schema'), + path('api_schema/', get_schema_view(title='API Schema', description='Guide for the REST API'), name='api_schema'), ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/backend/openapi.yml b/backend/openapi.yml index 382c14a..8e3773a 100644 --- a/backend/openapi.yml +++ b/backend/openapi.yml @@ -4,63 +4,163 @@ info: version: '' description: Guide for the REST API paths: + /login/: + get: + summary: login + operationId: loginUser + description: Login into the account + parameters: + - name: email + in: query + required: true + description: '' + schema: + type: string + + - name: passwordMd5hash + in: query + required: true + description: '' + schema: + type: string + + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/LoginResponse' + description: 'Success' + tags: + - sign in, sign up + + /register/: + post: + summary: register + operationId: createUser + description: Create new user + parameters: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/User' + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/LoginResponse' + description: 'Success' + tags: + - sign in, sign up + /orders/: get: - summary: getAllOrders + summary: getAllOrders / filter operationId: listorder_lists - description: List of all users - parameters: [] + description: List of all orders(or filter by weight) + parameters: + - name: token + in: query + required: true + description: '' + schema: + type: string + - name: weightMin + in: query + required: false + description: '' + schema: + type: integer + - name: weightMax + in: query + required: false + description: '' + schema: + type: integer + - name: costMin + in: query + required: false + description: '' + schema: + type: integer + - name: costMax + in: query + required: false + description: '' + schema: + type: integer + - name: status + in: query + required: false + description: '' + schema: + type: string + example: IN_PROGRESS + enum: [CREATED, IN_PROGRESS, COMPLETED] responses: '200': content: application/json: schema: type: array - items: + items: $ref: '#/components/schemas/Order' - description: '' + description: 'Success' tags: - orders post: summary: createNewOrder operationId: createorder_list description: Create new order - parameters: [] + parameters: + - name: token + in: query + required: true + description: '' + schema: + type: string requestBody: content: application/json: - schema: {} - application/x-www-form-urlencoded: - schema: {} - multipart/form-data: - schema: {} + schema: + $ref: '#/components/schemas/Order' responses: '201': content: application/json: - schema: {} - description: '' + schema: + $ref: '#/components/schemas/Order' + description: 'Success' tags: - orders + /orders/{id}: get: summary: getOrderById operationId: retrieveorder_detail description: Get order by id parameters: + - name: token + in: query + required: true + description: '' + schema: + type: string - name: id in: path required: true description: '' schema: - type: string + type: integer responses: '200': content: application/json: - schema: + schema: $ref: '#/components/schemas/Order' - description: '' + description: 'Success' tags: - orders put: @@ -68,139 +168,144 @@ paths: operationId: updateorder_detail description: Accept order by angel parameters: + - name: token + in: query + required: true + description: '' + schema: + type: string - name: id in: path required: true description: '' schema: - type: string + type: integer requestBody: content: application/json: - schema: {} - application/x-www-form-urlencoded: - schema: {} - multipart/form-data: - schema: {} + schema: + $ref: '#/components/schemas/Order' responses: '200': content: application/json: - schema: {} - description: '' + schema: + $ref: '#/components/schemas/Order' + description: 'Success' tags: - orders - /users/: - get: - summary: getAllUsers - operationId: listusers_lists - description: List all code users - parameters: [] - responses: - '200': - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/User' - description: '' - tags: - - customers - post: - summary: createNewUser - operationId: createuser_list - description: Create new user - parameters: [] - requestBody: - content: - application/json: - schema: {} - application/x-www-form-urlencoded: - schema: {} - multipart/form-data: - schema: {} - responses: - '201': - content: - application/json: - schema: {} - description: '' - tags: - - customers /users/{id}: get: summary: getUserById operationId: listusersbyid_lists description: Get user by id parameters: + - name: token + in: query + required: true + description: '' + schema: + type: string - name: id in: path required: true description: '' schema: - type: string + type: integer responses: '200': content: application/json: schema: $ref: '#/components/schemas/User' - description: '' + description: 'Success' tags: - customers - /users/{id}/orders: + + /delivery/: get: - summary: getAllOrdersOfTheUser - operationId: listordersofuser_lists - description: List all user's orders + summary: getAllListOfDelivery with filter + operationId: listdelivery_lists + description: List of all delivery parameters: - - name: id - in: path - required: true - description: '' - schema: - type: string + - name: token + in: query + required: true + description: '' + schema: + type: string + - name: customerId + in: query + required: false + description: '' + schema: + type: integer + - name: angelId + in: query + required: false + description: '' + schema: + type: integer responses: '200': content: application/json: schema: type: array - items: - $ref: '#/components/schemas/Order' - description: '' + items: + $ref: '#/components/schemas/Delivery' + description: 'Success' tags: - - customers - /users/{id}/orders/{order_id}: + - delivery + post: + summary: startDelivery + operationId: createdelivery_list + description: Create new delivery + parameters: [] + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Delivery' + responses: + '201': + content: + application/json: + schema: + $ref: '#/components/schemas/Delivery' + description: 'Success' + tags: + - delivery + + /delivery/{orderId}: get: - summary: getOrderOfUser - operationId: orderofuser_lists - description: Get user's order by id + summary: getDeliveryByOrderId + operationId: listdeliverybyorderid_lists + description: Delivery by order if parameters: - - name: id - in: path - required: true - description: '' - schema: - type: string - - name: order_id - in: path - required: true - description: '' - schema: - type: string + - name: token + in: query + required: true + description: '' + schema: + type: string + - name: orderId + in: path + required: true + description: '' + schema: + type: integer responses: '200': content: application/json: - schema: - $ref: '#/components/schemas/Order' - description: '' + schema: + $ref: '#/components/schemas/Delivery' + description: 'Success' tags: - - customers - + - delivery + components: schemas: User: @@ -208,7 +313,9 @@ components: properties: id: type: integer - example: 5 + example: 1 + passwordMd5hash: + type: string name: type: string example: John @@ -218,38 +325,144 @@ components: email: type: string example: mail@innopolis.ru + age: + type: integer + example: 23 + deliveryRate: + type: number + example: 4.3 + createdOrdersHistoryIds: + type: array + items: + type: integer + example: [3243, 435, 4] + deliveredOrdersHistoryIds: + type: array + items: + type: integer + example: [75643, 345, 3] required: - id - name - phoneNumber - email - - OrderStatus: - description: Performing status - type: string - enum: [OFFERED, DELIVERY, PERFORMED] + - deliveryRate + - age + - createdOrdersHistoryIds + - deliveredOrdersHistoryIds Order: type: object properties: id: type: integer - example: 4 + example: 5467 + customerId: + type: integer + example: 45678 description: type: string - example: Description of the - orderStatus: - $ref: '#/components/schemas/OrderStatus' - possibleDeliveryMen: + example: Description of the order + expectedDeliveryTime: + type: string + format: date-time + status: + type: string + example: IN_PROGRESS + enum: [CREATED, IN_PROGRESS, COMPLETED] + weight: + type: number + example: 3.5 + cost: + type: integer + example: 1200 + fee: + type: integer + example: 100 + address: + type: string + example: Inno basement + possibleAngelsIds: type: array items: - $ref: '#/components/schemas/User' - acceptedDeliveryMen: - $ref: '#/components/schemas/User' - required: + type: integer + example: [786, 3, 234] + picture: + type: string + example: url + required: - id + - customerId - description - - orderStatus - - possibleDeliveryMen - - acceptedDeliveryMen - \ No newline at end of file + - status + - weight + - cost + - fee + - address + - picture + - possibleAngelsIds + - expectedDeliveryTime + + Delivery: + type: object + properties: + customerId: + type: integer + example: 32453 + angelId: + type: integer + example: 87654 + orderId: + type: integer + example: 97865 + estimatedTime: + type: string + format: date-time + customerConfirmation: + type: boolean + example: true + angelConfirmation: + type: boolean + example: false + required: + - customerId + - angelId + - orderId + - estimatedTime + - customerConfirmation + - angelConfirmation + + Feedback: + type: object + properties: + objectId: + type: integer + example: 07986 + subjectId: + type: integer + example: 87965 + deal: + type: string + example: hello + enum: [DELIVERY, ORDERING] + description: + type: string + example: I like this angel + required: + - objectId + - subjectId + - deal + - description + + LoginResponse: + type: object + properties: + token: + type: string + example: "185ca069-7e19-43ab-9843-d4923877e2d0" + userId: + type: integer + example: 87965 + required: + - token + - userId \ No newline at end of file diff --git a/backend/orders/__init__.py b/backend/orders/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/orders/admin.py b/backend/orders/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/backend/orders/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/backend/orders/apps.py b/backend/orders/apps.py deleted file mode 100644 index 8ae0375..0000000 --- a/backend/orders/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class OrdersConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'orders' diff --git a/backend/orders/migrations/0001_initial.py b/backend/orders/migrations/0001_initial.py deleted file mode 100644 index 6dae5d9..0000000 --- a/backend/orders/migrations/0001_initial.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.0.4 on 2022-05-29 20:23 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Order', - fields=[ - ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('customer', models.IntegerField()), - ('description', models.CharField(blank=True, default='', max_length=100)), - ('status', models.BooleanField(default=False)), - ('acceptedDelivery', models.BooleanField(default=False)), - ('deliveryMan', models.IntegerField()), - ], - ), - ] diff --git a/backend/orders/migrations/__init__.py b/backend/orders/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/backend/orders/models.py b/backend/orders/models.py deleted file mode 100644 index 03c9be0..0000000 --- a/backend/orders/models.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.db import models - -# Create your models here. - -class Order(models.Model): - customer = models.IntegerField() - description = models.CharField(max_length=100, blank=True, default='') - status = models.BooleanField(default=False) - acceptedDelivery = models.BooleanField(default=False) - deliveryMan = models.IntegerField() \ No newline at end of file diff --git a/backend/orders/serializers.py b/backend/orders/serializers.py deleted file mode 100644 index 6e3604c..0000000 --- a/backend/orders/serializers.py +++ /dev/null @@ -1,29 +0,0 @@ -from rest_framework import serializers -from orders.models import Order - - -class OrderSerializer(serializers.Serializer): - id = serializers.IntegerField(read_only=True) - customer = serializers.IntegerField() - description = serializers.CharField(max_length=100, default='') - status = serializers.BooleanField(default=False) - acceptedDelivery = serializers.BooleanField(default=False) - deliveryMan = serializers.IntegerField() - - def create(self, validated_data): - """ - Create and return a new `Snippet` instance, given the validated data. - """ - return Order.objects.create(**validated_data) - - def update(self, instance, validated_data): - """ - Update and return an existing `Snippet` instance, given the validated data. - """ - instance.customer = validated_data.get('customer', instance.customer) - instance.description = validated_data.get('description', instance.description) - instance.status = validated_data.get('status', instance.status) - instance.acceptedDelivery = validated_data.get('acceptedDelivery', instance.acceptedDelivery) - instance.deliveryMan = validated_data.get('deliveryMan', instance.deliveryMan) - instance.save() - return instance \ No newline at end of file diff --git a/backend/orders/tests.py b/backend/orders/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/backend/orders/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/backend/orders/urls.py b/backend/orders/urls.py deleted file mode 100644 index f91e13b..0000000 --- a/backend/orders/urls.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.urls import path -from rest_framework.urlpatterns import format_suffix_patterns -from orders import views - -urlpatterns = [ - path('orders/', views.order_list), - path('orders/', views.order_detail), -] - -urlpatterns = format_suffix_patterns(urlpatterns) \ No newline at end of file diff --git a/backend/orders/views.py b/backend/orders/views.py deleted file mode 100644 index a5a7d1b..0000000 --- a/backend/orders/views.py +++ /dev/null @@ -1,50 +0,0 @@ -#from django.shortcuts import render - -from rest_framework import status -from rest_framework.decorators import api_view -from rest_framework.response import Response -from orders.models import Order -from orders.serializers import OrderSerializer - - -@api_view(['GET', 'POST']) -def order_list(request, format=None): - """ - List all code orders, or create a new order. - """ - if request.method == 'GET': - orders = Order.objects.all() - serializer = OrderSerializer(orders, many=True) - return Response(serializer.data) - - elif request.method == 'POST': - serializer = OrderSerializer(data=request.data) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data, status=status.HTTP_201_CREATED) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - -@api_view(['GET', 'PUT', 'DELETE']) -def order_detail(request, pk, format=None): - """ - Retrieve, update or delete an order. - """ - try: - order = Order.objects.get(pk=pk) - except Order.DoesNotExist: - return Response(status=status.HTTP_404_NOT_FOUND) - - if request.method == 'GET': - serializer = OrderSerializer(order) - return Response(serializer.data) - - elif request.method == 'PUT': - serializer = OrderSerializer(order, data=request.data) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - - elif request.method == 'DELETE': - order.delete() - return Response(status=status.HTTP_204_NO_CONTENT) From 5092ebb111956624206de00b87d7c17406e7b3f9 Mon Sep 17 00:00:00 2001 From: Yaroslav Kivaev Date: Fri, 10 Jun 2022 09:08:38 +0300 Subject: [PATCH 3/4] Phone number is string now --- backend/openapi.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/openapi.yml b/backend/openapi.yml index 8e3773a..bb34806 100644 --- a/backend/openapi.yml +++ b/backend/openapi.yml @@ -320,7 +320,7 @@ components: type: string example: John phoneNumber: - type: integer + type: string example: 88005553535 email: type: string @@ -350,6 +350,7 @@ components: - age - createdOrdersHistoryIds - deliveredOrdersHistoryIds + - passwordMd5hash Order: type: object From 38ce924eb7bb430b42e8f102869ce9010d64d4ab Mon Sep 17 00:00:00 2001 From: Yaroslav Kivaev Date: Fri, 10 Jun 2022 09:22:51 +0300 Subject: [PATCH 4/4] Cost and fee now is decimal --- backend/openapi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/openapi.yml b/backend/openapi.yml index bb34806..bbfccd8 100644 --- a/backend/openapi.yml +++ b/backend/openapi.yml @@ -375,10 +375,10 @@ components: type: number example: 3.5 cost: - type: integer + type: number example: 1200 fee: - type: integer + type: number example: 100 address: type: string