put class on parent scope
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SearchResponse(BaseModel):
|
||||
total_items: int
|
||||
total_pages: int
|
||||
items: list[dict]
|
||||
|
||||
|
||||
class RecordResponse(BaseModel):
|
||||
items: list[dict]
|
||||
last_key: str | None
|
||||
@@ -6,7 +6,6 @@ from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from elasticsearch import Elasticsearch
|
||||
|
||||
import elastic
|
||||
from http_models import SearchResponse
|
||||
from models import Course
|
||||
from settings import COURSE_TABLE, ELASTIC_CONN
|
||||
|
||||
@@ -15,7 +14,7 @@ elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
|
||||
|
||||
@router.get('/', compress=True, tags=['Course'])
|
||||
def get_courses() -> SearchResponse:
|
||||
def get_courses():
|
||||
event = router.current_event
|
||||
query = event.get_query_string_value('query', '{}')
|
||||
page_size = event.get_query_string_value('page_size', '25')
|
||||
|
||||
@@ -6,7 +6,6 @@ from elasticsearch import Elasticsearch
|
||||
from pydantic import BaseModel
|
||||
|
||||
import elastic
|
||||
from http_models import SearchResponse
|
||||
from settings import ELASTIC_CONN, ENROLLMENT_TABLE
|
||||
|
||||
router = Router()
|
||||
@@ -14,7 +13,7 @@ elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
|
||||
|
||||
@router.get('/', compress=True, tags=['Enrollment'])
|
||||
def get_enrollments() -> SearchResponse:
|
||||
def get_enrollments():
|
||||
event = router.current_event
|
||||
query = event.get_query_string_value('query', '{}')
|
||||
page_size = event.get_query_string_value('page_size', '25')
|
||||
|
||||
@@ -4,7 +4,6 @@ from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from elasticsearch import Elasticsearch
|
||||
|
||||
import elastic
|
||||
from http_models import SearchResponse
|
||||
from settings import ELASTIC_CONN, ORDER_TABLE
|
||||
|
||||
router = Router()
|
||||
@@ -12,7 +11,7 @@ elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
|
||||
|
||||
@router.get('/', compress=True, tags=['Order'])
|
||||
def get_orders() -> SearchResponse:
|
||||
def get_orders():
|
||||
event = router.current_event
|
||||
query = event.get_query_string_value('query', '{}')
|
||||
page_size = event.get_query_string_value('page_size', '25')
|
||||
|
||||
@@ -28,7 +28,12 @@ collect = DynamoDBCollection(user_layer)
|
||||
elastic_client = Elasticsearch(**ELASTIC_CONN)
|
||||
|
||||
|
||||
@router.get('/', compress=True, tags=['User'], summary='Get users')
|
||||
@router.get(
|
||||
'/',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Get users',
|
||||
)
|
||||
def get_users():
|
||||
event = router.current_event
|
||||
query = event.get_query_string_value('query', '{}')
|
||||
@@ -42,22 +47,27 @@ def get_users():
|
||||
)
|
||||
|
||||
|
||||
@router.post('/', compress=True, tags=['User'], summary='Create user')
|
||||
@router.post('/', compress=True, tags=['User'], description='Create user')
|
||||
def post_user(payload: User):
|
||||
return Response(status_code=HTTPStatus.CREATED)
|
||||
|
||||
|
||||
class ResetPasswordPayload(BaseModel):
|
||||
class NewPasswordPayload(BaseModel):
|
||||
cognito_sub: UUID4
|
||||
new_password: Annotated[str, StringConstraints(min_length=6)]
|
||||
|
||||
|
||||
@router.patch('/<id>', compress=True, tags=['User'])
|
||||
def patch_reset(id: str, payload: ResetPasswordPayload):
|
||||
def patch_reset(id: str, payload: NewPasswordPayload):
|
||||
return Response(status_code=HTTPStatus.OK)
|
||||
|
||||
|
||||
@router.get('/<id>/emails', compress=True, tags=['User'], summary='Get user emails')
|
||||
@router.get(
|
||||
'/<id>/emails',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Get user emails',
|
||||
)
|
||||
def get_emails(id: str):
|
||||
start_key = router.current_event.get_query_string_value('start_key', None)
|
||||
|
||||
@@ -67,7 +77,12 @@ def get_emails(id: str):
|
||||
)
|
||||
|
||||
|
||||
@router.get('/<id>/logs', compress=True, tags=['User'], summary='Get user logs')
|
||||
@router.get(
|
||||
'/<id>/logs',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Get user logs',
|
||||
)
|
||||
def get_logs(id: str):
|
||||
start_key = router.current_event.get_query_string_value('start_key', None)
|
||||
|
||||
@@ -77,7 +92,12 @@ def get_logs(id: str):
|
||||
)
|
||||
|
||||
|
||||
@router.get('/<id>/orgs', compress=True, tags=['User'], summary='Get user orgs')
|
||||
@router.get(
|
||||
'/<id>/orgs',
|
||||
compress=True,
|
||||
tags=['User'],
|
||||
summary='Get user orgs',
|
||||
)
|
||||
def get_orgs(id: str):
|
||||
start_key = router.current_event.get_query_string_value('start_key', None)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Globals:
|
||||
Architectures:
|
||||
- x86_64
|
||||
Layers:
|
||||
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:13
|
||||
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:14
|
||||
Environment:
|
||||
Variables:
|
||||
TZ: America/Sao_Paulo
|
||||
|
||||
@@ -477,6 +477,15 @@ class DynamoDBPersistenceLayer:
|
||||
return True
|
||||
|
||||
|
||||
class MissingError(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class PaginatedResult(TypedDict):
|
||||
items: list[dict]
|
||||
last_key: str | None
|
||||
|
||||
|
||||
class DynamoDBCollection:
|
||||
"""
|
||||
Example
|
||||
@@ -508,13 +517,6 @@ class DynamoDBCollection:
|
||||
)
|
||||
"""
|
||||
|
||||
class MissingError(ValueError):
|
||||
pass
|
||||
|
||||
class PaginatedResult(TypedDict):
|
||||
items: list[dict]
|
||||
last_key: str | None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
persistence_layer: DynamoDBPersistenceLayer,
|
||||
|
||||
@@ -10,6 +10,7 @@ from layercake.dynamodb import (
|
||||
DynamoDBCollection,
|
||||
DynamoDBPersistenceLayer,
|
||||
KeyPair,
|
||||
MissingError,
|
||||
PartitionKey,
|
||||
TransactItems,
|
||||
serialize,
|
||||
@@ -103,7 +104,7 @@ def test_collection_get_item(
|
||||
'update_date': '2023-11-09T12:13:04.308986-03:00',
|
||||
}
|
||||
|
||||
with pytest.raises(DynamoDBCollection.MissingError):
|
||||
with pytest.raises(MissingError):
|
||||
collect.get_item(key=KeyPair('5OxmMjL-ujoR5IMGegQz', 'notfound'))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user