Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
danial29rus committed Feb 22, 2023
1 parent 50920d1 commit f3dda55
Show file tree
Hide file tree
Showing 787 changed files with 271,871 additions and 0 deletions.
Binary file added .coverage
Binary file not shown.
25 changes: 25 additions & 0 deletions app/api/endpoints/bookings/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from app.api.endpoints.bookings.models import Bookings
from app.api.endpoints.hotels.models import Hotels, Rooms
from sqlalchemy import select


async def get_booking_info(booking_id: int, session):
get_booking = select(
Hotels.name.label("hotel_name"),
Rooms.name.label("room_name"),
Rooms.description.label("room_description"),
Bookings.date_from,
Bookings.date_to,
Bookings.total_cost,
Bookings.total_days,
).select_from(Bookings).filter_by(
id=booking_id
).join(
Rooms, Rooms.id == Bookings.room_id
).join(
Hotels, Hotels.id == Rooms.hotel_id
)

booking_info = await session.execute(get_booking)
booking_info = booking_info.one_or_none()
return booking_info
25 changes: 25 additions & 0 deletions app/api/endpoints/pages/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi import APIRouter, Request, Depends
from fastapi.templating import Jinja2Templates

from app.api.endpoints.hotels.router import get_hotel_locations

router = APIRouter(
prefix="/pages",
tags=["Pages"]
)

templates = Jinja2Templates(directory="app/api/endpoints/templates")


@router.get("/base")
def get_base_page(request: Request):
return templates.TemplateResponse("base.html", {"request": request})


# @router.get("/search")
# def search(request: Request):
# return templates.TemplateResponse("search.html", {"request": request})

@router.get("/search/{location_hotel}")
def get_search_page(request: Request, location=Depends(get_hotel_locations)):
return templates.TemplateResponse("search.html", {"request": request, "operations": location["data"]})
Binary file added app/api/endpoints/static/stocks_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/api/endpoints/static/stocks_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/api/endpoints/static/stocks_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions app/api/endpoints/tasks/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from fastapi import APIRouter, BackgroundTasks, Depends

from app.api.endpoints.auth.utils import get_current_user

from app.api.endpoints.tasks.tasks import send_email_report_dashboard
# from app.api.endpoints.tasks.tasks2 import send_email_async

router = APIRouter(prefix="/report")


@router.get("/dashboard")
def get_dashboard_report(background_tasks: BackgroundTasks, user=Depends(get_current_user)):
# 1400 ms - Клиент ждет
# send_email_report_dashboard(user.id)
# 500 ms - Задача выполняется на фоне FastAPI в event loop'е или в другом треде
#background_tasks.add_task(send_email_report_dashboard, user.username)
# 600 ms - Задача выполняется воркером Celery в отдельном процессе
send_email_report_dashboard.delay(user.email)
return {
"status": 200,
"data": "Письмо отправлено",
"details": None
}



32 changes: 32 additions & 0 deletions app/api/endpoints/tasks/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ssl

from celery import Celery
import smtplib
from email.message import EmailMessage

from fastapi import Depends
from app.api.endpoints.auth.utils import get_current_user
from app.config import SMTP_PASSWORD, SMTP_USER, SMTP_TO_USER

SMTP_HOST = "smtp.gmail.com"
SMTP_PORT = 465

celery = Celery('tasks', broker='redis://localhost:6379')


def get_email_template_dashboard(email_to: str):
email = EmailMessage()
email['Subject'] = 'Натрейдил Отчет Дашборд'
email['From'] = SMTP_USER
email['To'] = email_to

email.set_content(f"Здравствуйте, {email_to}, вы забронировали отель !")
return email


@celery.task
def send_email_report_dashboard(email_to: str):
email = get_email_template_dashboard(email_to)
with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT) as server:
server.login(SMTP_USER, SMTP_PASSWORD)
server.send_message(email)
49 changes: 49 additions & 0 deletions app/api/endpoints/tasks/tasks2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# import os
#
# from celery import Celery
# from fastapi import BackgroundTasks, Depends
# from fastapi_mail import FastMail, MessageSchema, ConnectionConfig
#
# from app.api.endpoints.auth.router import current_user
# from app.config import SMTP_PASSWORD, SMTP_USER, SMTP_TO_USER
#
# SMTP_HOST = "smtp.gmail.com"
# SMTP_PORT = 587
#
# celery = Celery('tasks', broker='redis://localhost:6379')
#
#
# class Envs:
# MAIL_USERNAME = SMTP_USER
# MAIL_PASSWORD = SMTP_PASSWORD
# MAIL_FROM = SMTP_TO_USER
# MAIL_PORT = SMTP_PORT
# MAIL_SERVER = SMTP_HOST
# MAIL_FROM_NAME = 'danyanara'
#
#
# conf = ConnectionConfig(
# MAIL_USERNAME=Envs.MAIL_USERNAME,
# MAIL_PASSWORD=Envs.MAIL_PASSWORD,
# MAIL_FROM=Envs.MAIL_FROM,
# MAIL_PORT=Envs.MAIL_PORT,
# MAIL_SERVER=Envs.MAIL_SERVER,
# MAIL_FROM_NAME=Envs.MAIL_FROM_NAME,
# MAIL_TLS=True,
# MAIL_SSL=False,
# USE_CREDENTIALS=True,
# TEMPLATE_FOLDER='app/api/endpoints/templates/email'
# )
#
#
# async def send_email_async(subject: str, email_to: str, body: dict):
# message = MessageSchema(
# subject=subject,
# recipients=[email_to],
# body=body,
# subtype='html',
# )
#
# fm = FastMail(conf)
#
# await fm.send_message(message, template_name='email.html')
27 changes: 27 additions & 0 deletions app/api/endpoints/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.tailwindcss.com"></script>
{% block head %}{% endblock %}
<title>Booking</title>
</head>
<body>
<nav class="flex justify-between text-3xl my-3">
<ul class="flex ml-10">
<li>Booking</li>
</ul>
<ul class="flex gap-5 mr-10">
<li>Мой аккаунт</li>
<li>Выйти</li>
</ul>
</nav>
<hr>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
</html>
37 changes: 37 additions & 0 deletions app/api/endpoints/templates/email.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends "shared/base.html" %}


{% block title %}
<title>Job Detail</title>
{% endblock %}

{% block content %}
<div class="container">
<div class="row">
<h5 class="display-5">Signup to JobBoard</h5>
<div class="text-danger font-weight-bold">
{% for error in errors %}
<li>{{error}}</li>
{% endfor %}
</div>
</div>

<div class="row my-5">
<form method="POST">
<div class="mb-3">
<label>Username</label>
<input type="text" required class="form-control" name="username" value="{{username}}" placeholder="username">
</div>
<div class="mb-3">
<label>Email</label>
<input type="text" required placeholder="Your email" name="email" value="{{email}}" class="form-control">
</div>
<div class="mb-3">
<label>Password</label>
<input type="password" required placeholder="Choose a secure password" value="{{password}}" name="password" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
{% endblock %}
31 changes: 31 additions & 0 deletions app/api/endpoints/templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "base.html" %}

{% block head %}
<script>
const searchForOperation = () => {
const searchInputValue = document.getElementById("location_search").value;
window.location.href = `/pages/search/${searchInputValue}`;
}
</script>
{% endblock %}

{% block content %}
<div class="flex justify-center flex-col items-center">
<div class="flex my-3 gap-5">
<input id="location_search" type="text" placeholder="Тип операции" class="text-xl">
<button onclick="searchForOperation()" class="border-2 rounded-3xl bg-gray-300 p-3">Поиск по операциям</button>
</div>
<span>Например, Выплата купонов, Удержание НДФЛ по купонам, Вывод денежных средств, Продажа ценных бумаг</span>
{% for hotel in operations %}
<div class="flex rounded-3 border-2 p-3 mt-5">
<img width="150" src="{{ url_for('static', path='stocks_2.png') }}" alt="Стонкс" class="mr-5">
<div class="flex flex-col">
<span class="text-lg">{{ hotel["Hotels"].id }}</span>
<span class="text-lg">{{ hotel["Hotels"].location }}</span>
<span class="text-lg">{{ hotel["Hotels"].services }}</span>

</div>
</div>
{% endfor %}
</div>
{% endblock %}
Loading

0 comments on commit f3dda55

Please sign in to comment.