Skip to content

Commit

Permalink
Merge pull request #61 from dev-lymar/kroshkaview
Browse files Browse the repository at this point in the history
Kroshkaview
  • Loading branch information
dev-lymar committed Jun 5, 2024
2 parents d7ada89 + b389b3c commit a5be5a9
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ jobs:
DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}
DATABASE_HOST=${{ secrets.DATABASE_HOST }}
DATABASE_PORT=${{ secrets.DATABASE_PORT }}
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
REDIS_HOST=${{ secrets.REDIS_HOST }}
REDIS_PORT=${{ secrets.REDIS_PORT }}
SECRET_KEY=${{ secrets.SECRET_KEY }}
EMAIL_HOST=${{ secrets.EMAIL_HOST }}
EMAIL_PORT=${{ secrets.EMAIL_PORT }}
Expand Down
62 changes: 46 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Python](https://img.shields.io/badge/-Python-3776AB?style=flat&logo=Python&logoColor=yellow)](https://www.python.org/)
[![Django REST Framework](https://img.shields.io/badge/-Django%20REST%20Framework-092E20?style=flat&logo=django&logoColor=white)](https://www.django-rest-framework.org/)
[![PostgreSQL](https://img.shields.io/badge/-PostgreSQL-336791?style=flat&logo=PostgreSQL&logoColor=white)](https://www.postgresql.org/)
[![Redis](https://img.shields.io/badge/Redis-DC382D?style=flat&logo=Redis&logoColor=white)](https://redis.io/)
[![Docker](https://img.shields.io/badge/-Docker-2496ED?style=flat&logo=Docker&logoColor=white)](https://www.docker.com/)
[![Nginx](https://img.shields.io/badge/-Nginx-269539?style=flat&logo=Nginx&logoColor=white)](https://www.nginx.com/)
[![Psycopg2-binary](https://img.shields.io/badge/-Psycopg2--binary-4169E1?style=flat)](https://pypi.org/project/psycopg2-binary/)
Expand All @@ -23,35 +24,52 @@

## How to run the project

1. Install [`Docker`](https://www.docker.com/) and [`Docker Compose`](https://docs.docker.com/compose/)
To get started with Melnichanka, you will need to have [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed on your system. You can follow the instructions for your operating system here and here.
1. Install [`Docker`](https://www.docker.com/)
and [`Docker Compose`](https://docs.docker.com/compose/)
To get started with Melnichanka, you will need to have [Docker](https://www.docker.com/)
and [Docker Compose](https://docs.docker.com/compose/) installed on your system. You can follow
the instructions for your operating system here and here.

Once you have [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/) installed, follow these steps to start the project:
Once you have [Docker](https://www.docker.com/)
and [Docker Compose](https://docs.docker.com/compose/) installed, follow these steps to start the
project:

- Clone the repository:

```sh
git clone https://github.com/KroshkaByte/Melnichanka.git
cd Melnichanka
```

- Start the project from root directory:

```sh
docker-compose up -d --build
```

- Open your web browser and navigate to http://localhost:80 to access the application.

## Project Description

Melnichanka is a web application designed to facilitate the process of submitting shipment applications to consignees. The application generates a package of documents required for shipment based on user input, including information about goods, brands, factories, and packages.
Melnichanka is a web application designed to facilitate the process of submitting shipment
applications to consignees. The application generates a package of documents required for shipment
based on user input, including information about goods, brands, factories, and packages.

The application is intended to be used by companies that need to submit shipment applications on a regular basis. By using Melnichanka, companies can streamline the process of generating the necessary documents, reduce errors, and save time and resources.
The application is intended to be used by companies that need to submit shipment applications on a
regular basis. By using Melnichanka, companies can streamline the process of generating the
necessary documents, reduce errors, and save time and resources.

The application includes a user-friendly interface that allows users to easily enter data and generate documents. The interface is designed to be intuitive and easy to use, even for users with little or no technical experience.
The application includes a user-friendly interface that allows users to easily enter data and
generate documents. The interface is designed to be intuitive and easy to use, even for users with
little or no technical experience.

Melnichanka is built using modern web technologies, including `Django`, a popular web framework for Python. The application is containerized using Docker and Docker Compose, making it easy to deploy and scale.

Overall, Melnichanka is a powerful and flexible tool that can help companies save time and resources when submitting shipment applications. By automating the process of generating documents, Melnichanka can help companies reduce errors, improve efficiency, and focus on their core business.
Melnichanka is built using modern web technologies, including `Django`, a popular web framework for
Python. The application is containerized using Docker and Docker Compose, making it easy to deploy
and scale.

Overall, Melnichanka is a powerful and flexible tool that can help companies save time and
resources when submitting shipment applications. By automating the process of generating documents,
Melnichanka can help companies reduce errors, improve efficiency, and focus on their core business.

## Usage

Expand All @@ -65,7 +83,8 @@ To use Melnichanka, follow these steps:

## Database Pre-population

To pre-populate the database with some initial data, you can use the provided script. This script utilizes the `Faker` library to generate fake data.
To pre-populate the database with some initial data, you can use the provided script. This script
utilizes the `Faker` library to generate fake data.

Please follow the steps below to run the script:

Expand All @@ -76,13 +95,17 @@ Please follow the steps below to run the script:
```sh
python3 manage.py runscript faker_script
```

Make sure `django-extensions` is installed and added to `INSTALLED_APPS` in your Django settings.

This command will execute the `faker_script` script, which will then populate the database with the generated data.
This command will execute the `faker_script` script, which will then populate the database with the
generated data.

Please note that the data generated by the Faker library is random and does not represent any real information.
Please note that the data generated by the Faker library is random and does not represent any real
information.

Ensure that your `virtual environment` is activated before running the commands, if you're using one.
Ensure that your `virtual environment` is activated before running the commands, if you're using
one.

## Documentation

Expand All @@ -91,28 +114,35 @@ API documentation is available through Swagger UI and ReDoc.
- [Swagger UI](https://dev-lymar.github.io/Melnichanka/melnichanka_swager_ui)
- [ReDoc](https://dev-lymar.github.io/Melnichanka/melnichanka_redoc)

For local access, navigate to [`Swagger UI`](http://localhost:8000/api/schema/swagger-ui/) and [`ReDoc`](http://localhost:8000/api/schema/redoc/) in your browser after starting the project.
For local access, navigate to [`Swagger UI`](http://localhost:8000/api/schema/swagger-ui/)
and [`ReDoc`](http://localhost:8000/api/schema/redoc/) in your browser after starting the project.

## Testing

To run the tests, navigate to the root directory of the project (where the manage.py file is located) and run the following command:
To run the tests, navigate to the root directory of the project (where the manage.py file is
located) and run the following command:

```sh
pytest .
```

or

```sh
python3 -m pytest .
```

- To run tests for a specific application (such as goods, logistics, users, etc.) use the following command:
- To run tests for a specific application (such as goods, logistics, users, etc.) use the following
command:

```sh
pytest goods
pytest logistics
pytest users
pytest clients
pytest makedoc
```

## Contributing

We welcome contributions to Melnichanka. To contribute:
Expand Down
58 changes: 58 additions & 0 deletions docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,33 @@ paths:
items:
$ref: '#/components/schemas/DirectorPosition'
description: ''
/api/v1/data/:
post:
operationId: v1_data_create
tags:
- v1
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/DataDoc'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/DataDoc'
multipart/form-data:
schema:
$ref: '#/components/schemas/DataDoc'
required: true
security:
- jwtAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/DataDoc'
description: ''
/api/v1/goods/:
get:
operationId: v1_goods_list
Expand Down Expand Up @@ -1348,6 +1375,24 @@ components:
- password_confirm
- phone_number_personal
- phone_number_work
DataDoc:
type: object
properties:
client_id:
type: integer
items:
type: array
items:
$ref: '#/components/schemas/OrderItem'
factory_id:
type: integer
destination:
type: string
required:
- client_id
- destination
- factory_id
- items
Department:
type: object
properties:
Expand Down Expand Up @@ -1428,6 +1473,19 @@ components:
type: string
required:
- refresh_token
OrderItem:
type: object
properties:
product_id:
type: integer
quantity:
type: integer
discount:
type: integer
default: 0
required:
- product_id
- quantity
PasswordToken:
type: object
properties:
Expand Down
14 changes: 14 additions & 0 deletions makedoc/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import serializers


class OrderItemSerializer(serializers.Serializer): # type: ignore
product_id = serializers.IntegerField()
quantity = serializers.IntegerField()
discount = serializers.IntegerField(required=False, default=0)


class DataDocSerializer(serializers.Serializer): # type: ignore
client_id = serializers.IntegerField()
items = serializers.ListField(child=OrderItemSerializer())
factory_id = serializers.IntegerField()
destination = serializers.CharField()
19 changes: 19 additions & 0 deletions makedoc/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from rest_framework.test import APIClient
from rest_framework_simplejwt.tokens import RefreshToken

from users.models import CustomUser


@pytest.fixture
def user(django_user_model):
return CustomUser.objects.create_user(email='test@example.com', full_name='Test User',
password='testpassword')


@pytest.fixture
def authorized_client(user):
client = APIClient()
refresh = RefreshToken.for_user(user)
client.credentials(HTTP_AUTHORIZATION=f"Bearer {str(refresh.access_token)}")
return client
52 changes: 52 additions & 0 deletions makedoc/tests/test_views_makedoc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest
from django.urls import reverse
from rest_framework.test import APIClient


@pytest.mark.django_db
def test__data_view__unauthorized_user_cannot_post_data() -> None:
client = APIClient()
url = reverse('data')
data = {
"client_id": 123,
"items": [
{"product_id": 1, "quantity": 2, "discount": 10},
{"product_id": 2, "quantity": 5, "discount": 4}
],
"factory_id": 1,
"destination": "New York"
}
response = client.post(url, data, format='json')
assert response.status_code == 401 # Unauthorized


@pytest.mark.django_db
def test__goods__authorized_user_can_post_data(authorized_client) -> None:
url = reverse('data')
data = {
"client_id": 123,
"items": [
{"product_id": 1, "quantity": 2, "discount": 10},
{"product_id": 2, "quantity": 5, "discount": 4}
],
"factory_id": 1,
"destination": "New York"
}
response = authorized_client.post(url, data, format='json')
assert response.status_code == 200


@pytest.mark.django_db
def test__goods__authorized_user_post_data_response_is_correct(authorized_client) -> None:
url = reverse('data')
data = {
"client_id": 123,
"items": [
{"product_id": 1, "quantity": 2, "discount": 10},
{"product_id": 2, "quantity": 5, "discount": 4}
],
"factory_id": 1,
"destination": "New York"
}
response = authorized_client.post(url, data, format='json')
assert response.json() == data
2 changes: 2 additions & 0 deletions makedoc/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.urls import path

from . import views
from .views import DataDocView

urlpatterns = [
path("filemake/", views.create_docs, name="file"),
path("data/", DataDocView.as_view(), name="data"),
]
17 changes: 17 additions & 0 deletions makedoc/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from django.http import HttpResponse
from rest_framework import generics, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from .serializers import DataDocSerializer
from .services import write_to_excel_auto, write_to_excel_rw, write_to_excel_sluzebnyi


Expand All @@ -9,3 +13,16 @@ def create_docs(request):
# Если применяется скидка, пишем служебную записку
write_to_excel_sluzebnyi(request) if 0 else None
return HttpResponse("Документы сохранены")


class DataDocView(generics.GenericAPIView): # type: ignore
serializer_class = DataDocSerializer
permission_classes = (IsAuthenticated,)

def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)

validated_data = serializer.validated_data

return Response(validated_data, status=status.HTTP_200_OK)

0 comments on commit a5be5a9

Please sign in to comment.