Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import falcon
from awokado.consts import CREATE, READ
from awokado.meta import ResourceMeta
from awokado.resource import BaseResource
class HealthCheckResource(BaseResource):
Meta = ResourceMeta(name="healthcheck", methods=(READ, CREATE))
def on_get(
self,
req: falcon.request.Request,
resp: falcon.response.Response,
resource_id: int = None,
):
resp.body = "OK"
def on_post(
self, req: falcon.request.Request, resp: falcon.response.Response
):
raise Exception("Something Goes Wrong")
from awokado.resource import BaseResource
class Resource(BaseResource):
class Meta:
name = "_resource"
methods = tuple()
auth = None
skip_doc = True
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado import custom_fields
from awokado.consts import CREATE, READ, UPDATE, BULK_UPDATE, DELETE
from awokado.meta import ResourceMeta
from awokado.request import ReadContext
from awokado.resource import BaseResource
class TagResource(BaseResource):
Meta = ResourceMeta(
model=m.Tag,
name="tag",
methods=(CREATE, READ, UPDATE, BULK_UPDATE, DELETE),
disable_total=True,
select_from=sa.outerjoin(
m.Tag, m.M2M_Book_Tag, m.Tag.id == m.M2M_Book_Tag.c.tag_id
).outerjoin(m.Book, m.M2M_Book_Tag.c.book_id == m.Book.id),
)
id = fields.Int(model_field=m.Tag.id)
name = fields.String(model_field=m.Tag.name)
books = custom_fields.ToMany(
fields.Int(), resource="book", model_field=m.M2M_Book_Tag.c.book_id
)
book_titles = fields.List(
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado.consts import READ
from awokado.meta import ResourceMeta
from awokado.resource import BaseResource
class StoreStatsResource(BaseResource):
Meta = ResourceMeta(
model=m.Store,
name="store_stats",
methods=(READ,),
select_from=sa.outerjoin(
m.Store, m.Book, m.Store.id == m.Book.store_id
),
)
name = fields.String(model_field=m.Store.name)
books_count = fields.Int(
dump_only=True, model_field=sa.func.count(m.Book.id)
)
return query
@classmethod
def can_update(cls, session, user_id: int, obj_ids: list, skip_exc=False):
return True
@classmethod
def can_delete(cls, session, user_id: int, obj_ids: list, skip_exc=False):
return True
@classmethod
def _get_read_query(cls, ctx, query: Selectable):
return query
class AuthorResource(BaseResource):
Meta = ResourceMeta(
model=m.Author,
name="author",
methods=(CREATE, READ, UPDATE, BULK_UPDATE, DELETE),
auth=AuthorAuth,
select_from=sa.outerjoin(
m.Author, m.Book, m.Author.id == m.Book.author_id
),
)
id = fields.Int(model_field=m.Author.id)
books = custom_fields.ToMany(
fields.Int(),
resource="book",
model_field=m.Book.id,
description="Authors Books",
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado import custom_fields
from awokado.consts import CREATE, READ, UPDATE, BULK_UPDATE, DELETE
from awokado.meta import ResourceMeta
from awokado.request import ReadContext
from awokado.resource import BaseResource
class BookResource(BaseResource):
Meta = ResourceMeta(
model=m.Book,
name="book",
methods=(CREATE, READ, UPDATE, BULK_UPDATE, DELETE),
select_from=sa.outerjoin(
m.Book, m.M2M_Book_Tag, m.Book.id == m.M2M_Book_Tag.c.book_id
).outerjoin(m.Author, m.Book.author_id == m.Author.id),
)
id = fields.Int(model_field=m.Book.id)
title = fields.String(model_field=m.Book.title, required=True)
description = fields.String(model_field=m.Book.description)
author = custom_fields.ToOne(
resource="author", model_field=m.Book.author_id
)
author_name = fields.Str(model_field=m.Author.first_name, dump_only=True)
from marshmallow import fields
import tests.test_app.models as m
from awokado.auth import BaseAuth
from awokado.consts import CREATE, READ, UPDATE, BULK_UPDATE, DELETE
from awokado.meta import ResourceMeta
from awokado.resource import BaseResource
class ForbiddenBookResource(BaseResource):
Meta = ResourceMeta(
model=m.Book,
name="forbidden_book",
methods=(CREATE, READ, UPDATE, BULK_UPDATE, DELETE),
auth=BaseAuth,
)
id = fields.Int(model_field=m.Book.id)
title = fields.String(model_field=m.Book.title, required=True)
description = fields.String(model_field=m.Book.description)
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado import custom_fields
from awokado.consts import CREATE, READ, BULK_CREATE
from awokado.meta import ResourceMeta
from awokado.request import ReadContext
from awokado.resource import BaseResource
STORE_OPEN = "open"
STORE_CLOSED = "closed"
class StoreResource(BaseResource):
Meta = ResourceMeta(
model=m.Store,
name="store",
methods=(CREATE, BULK_CREATE, READ),
select_from=sa.outerjoin(
m.Store, m.Book, m.Store.id == m.Book.store_id
),
)
id = fields.Int(model_field=m.Store.id)
book_ids = custom_fields.ToMany(
fields.Int(), resource="book", model_field=m.Book.id
)
name = fields.String(model_field=m.Store.name, required=True)
status = custom_fields.Choice(
model_field=m.Store.status,
import sqlalchemy as sa
from marshmallow import fields
import tests.test_app.models as m
from awokado.consts import READ
from awokado.meta import ResourceMeta
from awokado.resource import BaseResource
class TagStatsResource(BaseResource):
Meta = ResourceMeta(
model=m.Tag,
name="tag_stats",
methods=(READ,),
disable_total=True,
select_from=sa.outerjoin(
m.Tag, m.M2M_Book_Tag, m.Tag.id == m.M2M_Book_Tag.c.tag_id
).outerjoin(m.Book, m.M2M_Book_Tag.c.book_id == m.Book.id),
id_field="name",
)
name = fields.String(model_field=m.Tag.name)
books_count = fields.Int(
dump_only=True, model_field=sa.func.count(m.Book.id)
)