-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from MikiEremiki/develop
Develop
- Loading branch information
Showing
41 changed files
with
2,220 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: ci | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- | ||
name: Build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
dockerfile: Dockerfile-server | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/baby_domik_fastapi:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ config/* | |
settings.py | ||
/src/utilities/pickle/ud_ids/ | ||
/src/utilities/pickle/user_ids | ||
**/sql_files/ | ||
docker-compose-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM python:3.12-slim as base | ||
|
||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
WORKDIR /app | ||
|
||
RUN --mount=type=bind,source=requirements-server.txt,target=requirements-server.txt \ | ||
python -m pip install -r requirements-server.txt | ||
|
||
COPY /src/api/fastapi_nats.py . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
uvicorn | ||
fastapi | ||
faststream[nats] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from faststream import Logger | ||
from faststream.nats import JStream, NatsMessage, NatsBroker | ||
from telegram.ext import Application | ||
from yookassa.domain.notification import WebhookNotificationFactory | ||
|
||
from settings.settings import nats_url | ||
|
||
|
||
def connect_to_nats(app: Application, | ||
webhook_notification_factory: WebhookNotificationFactory): | ||
broker = NatsBroker(nats_url) | ||
stream = JStream(name="baby_domik", max_msgs=100, max_age=60*60*24*7) | ||
|
||
@broker.subscriber("bot", stream=stream, durable='yookassa') | ||
async def nats_handler( | ||
data: dict, | ||
logger: Logger, | ||
nats_message: NatsMessage, | ||
): | ||
logger.info(f'{data=}') | ||
notification = webhook_notification_factory.create(data) | ||
# print(f'{nats_message=}') | ||
await app.update_queue.put(notification) | ||
|
||
return broker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import asyncio | ||
from dataclasses import dataclass | ||
|
||
import uvicorn | ||
from fastapi import FastAPI, Response | ||
from faststream.nats.fastapi import NatsRouter, Logger, NatsBroker | ||
|
||
router = NatsRouter('nats://nats:4222') | ||
|
||
|
||
@dataclass | ||
class WebhookNotification: | ||
type: str | ||
event: str | ||
object: dict | ||
|
||
|
||
@router.get("/") | ||
async def hello_http(): | ||
return "Hello, HTTP!" | ||
|
||
|
||
@router.post("/yookassa") | ||
async def post_notification( | ||
message: WebhookNotification, | ||
logger: Logger, | ||
broker: NatsBroker | ||
): | ||
logger.info(message) | ||
await broker.publish(message, 'bot', stream="baby_domik") | ||
return Response(status_code=200) | ||
|
||
|
||
app = FastAPI(lifespan=router.lifespan_context) | ||
app.include_router(router, tags=["main requests"]) | ||
|
||
|
||
async def main(): | ||
webserver = uvicorn.Server( | ||
config=uvicorn.Config( | ||
app=app, | ||
host='0.0.0.0', | ||
port=8443, | ||
) | ||
) | ||
await webserver.serve() | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from yookassa.domain import models | ||
from settings.settings import URL_BOT | ||
|
||
|
||
def create_param_payment( | ||
price: [str, int], | ||
description: str, | ||
return_url: str = URL_BOT, | ||
*, | ||
quantity: str = "1", | ||
payment_method_type: str = "sbp", # "yoo_money" | ||
payment_mode: str = "full_payment", | ||
payment_subject: str = "service", | ||
**kwargs, | ||
) -> dict: | ||
return { | ||
"amount": models.Amount(value=price, currency="RUB"), | ||
"payment_method_data": { | ||
"type": payment_method_type | ||
}, | ||
"confirmation": { | ||
"type": "redirect", | ||
"return_url": return_url | ||
}, | ||
"capture": True, | ||
'receipt': { | ||
"customer": { | ||
'email': '[email protected]' | ||
}, | ||
"items": [ | ||
{ | ||
"description": description, | ||
"quantity": quantity, | ||
"amount": models.Amount(value=price, currency="RUB"), | ||
"vat_code": "1", | ||
"payment_mode": payment_mode, | ||
"payment_subject": payment_subject, | ||
} | ||
] | ||
}, | ||
'metadata': kwargs | ||
} |
Oops, something went wrong.