Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init mongo support #7

Merged
merged 7 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/release_beta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release Package

on:
workflow_dispatch:
permissions:
users:
- ItayTheDar
inputs:
increment_version:
description: 'Create a new beta release, deploy to TestPyPI, and install the package'

env:
VERSION_FILE_PATH: nest/__init__.py
CHANGELOG_FILE_PATH: CHANGELOG.md

jobs:
run-tests:
uses: ./.github/workflows/tests.yaml

release-package:
runs-on: ubuntu-latest
needs: run-tests
permissions:
contents: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.RELEASE_GIT_TOKEN }}

- name: Install python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install python dependencies
run: |
pip install --upgrade pip
pip install -r requirements-release.txt

- name: Build package
run: python -m build

- name: Publish package to TestPyPI
run: |
python -m twine upload dist/* -r testpypi -u ${{ secrets.TEST_PYPI_API_USER }} -p ${{ secrets.TEST_PYPI_API_TOKEN }}

- name: Install test package
run: |
pip install --index-url https://test.pypi.org/simple/ --no-deps pynest-api

# import to check if package is installed correctly
python -c "import nest"

- name: Copy pip url
run: |
echo "pip install --index-url https://test.pypi.org/simple/ --no-deps pynest-api"
30 changes: 30 additions & 0 deletions examples/nest_mongo_products/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# PyNest service

This is a template for a PyNest service.

## Start Service

## Step 1 - Create environment

- install requirements:

```bash
pip install -r requirements
```

## Step 2 - start service local

1. Run service with main method

```bash
python main.py
```
2. Run service using uvicorn

```bash
uvicorn "app:app" --host "0.0.0.0" --port "80" --reload
```

## Step 3 - Send requests

Go to the fastapi docs and use your api endpoints - http://127.0.0.1/docs
Empty file.
15 changes: 15 additions & 0 deletions examples/nest_mongo_products/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from orm_config import config
from nest.core.app import App
from src.examples.examples_module import ExamplesModule

app = App(
description="PyNest service",
modules=[
ExamplesModule,
]
)


@app.on_event("startup")
async def startup():
await config.create_all()
9 changes: 9 additions & 0 deletions examples/nest_mongo_products/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import uvicorn

if __name__ == '__main__':
uvicorn.run(
'app:app',
host="0.0.0.0",
port=8890,
reload=True
)
18 changes: 18 additions & 0 deletions examples/nest_mongo_products/orm_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from nest.core.database.base_odm import OdmService
from src.examples.examples_entity import Examples
import os
from dotenv import load_dotenv

load_dotenv()


config = OdmService(
db_type="mongodb",
config_params={
"db_name": os.getenv("DB_NAME"),
"host": os.getenv("DB_HOST"),
"port": os.getenv("DB_PORT"),
},
document_models=[Examples]
)

16 changes: 16 additions & 0 deletions examples/nest_mongo_products/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
anyio==3.6.2
click==8.1.3
fastapi==0.95.1
fastapi-utils==0.2.1
greenlet==2.0.2
h11==0.14.0
idna==3.4
pydantic==1.10.7
python-dotenv==1.0.0
sniffio==1.3.0
SQLAlchemy==1.4.48
starlette==0.26.1
typing_extensions==4.5.0
uvicorn==0.22.0
pynest-api==0.0.3

Empty file.
Empty file.
19 changes: 19 additions & 0 deletions examples/nest_mongo_products/src/examples/examples_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from nest.core import Controller, Get, Post, Depends

from src.examples.examples_service import ExamplesService
from src.examples.examples_model import Examples


@Controller("examples")
class ExamplesController:

service: ExamplesService = Depends(ExamplesService)

@Get("/get_examples")
async def get_examples(self):
return await self.service.get_examples()

@Post("/add_examples")
async def add_examples(self, examples: Examples):
return await self.service.add_examples(examples)

12 changes: 12 additions & 0 deletions examples/nest_mongo_products/src/examples/examples_entity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from beanie import Document


class Examples(Document):
name: str

class Config:
schema_extra = {
"example": {
"title": "Example Name",
}
}
6 changes: 6 additions & 0 deletions examples/nest_mongo_products/src/examples/examples_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pydantic import BaseModel


class Examples(BaseModel):
name: str

12 changes: 12 additions & 0 deletions examples/nest_mongo_products/src/examples/examples_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from src.examples.examples_service import ExamplesService
from src.examples.examples_controller import ExamplesController


class ExamplesModule:

def __init__(self):
self.providers = [ExamplesService]
self.controllers = [ExamplesController]



21 changes: 21 additions & 0 deletions examples/nest_mongo_products/src/examples/examples_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from src.examples.examples_model import Examples
from src.examples.examples_entity import Examples as ExamplesEntity
from nest.core.decorators import db_request_handler
from functools import lru_cache


@lru_cache()
class ExamplesService:

@db_request_handler
async def add_examples(self, examples: Examples):
new_examples = ExamplesEntity(
**examples.dict()
)
await new_examples.save()
return new_examples.id

@db_request_handler
async def get_examples(self):
return await ExamplesEntity.find_all().to_list()

Loading