Skip to content

Commit

Permalink
Merge pull request #64 from lsst-sqre/u/jsickcodes/v2-tables
Browse files Browse the repository at this point in the history
New model definitions for version 2 API
  • Loading branch information
jonathansick authored Jul 13, 2021
2 parents de938a3 + b92770f commit d8b40e3
Show file tree
Hide file tree
Showing 18 changed files with 682 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ redis:

.PHONY: worker
worker:
celery -A keeper.celery.celery_app worker -E -l DEBUG
FLASK_APP=keeper LTD_KEEPER_PROFILE=development LTD_KEEPER_DEV_DB_URL="postgresql+psycopg2://user:password@localhost:3308/db" celery -A keeper.celery.celery_app worker -E -l DEBUG

.PHONY: flower
flower:
Expand Down
8 changes: 4 additions & 4 deletions keeper/api/errorhandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def bad_request(e: Exception) -> Response:
"""Handler for ValidationError exceptions."""
logger = structlog.get_logger()
logger.error(status=400, message=e.args[0])
logger.error("bad request", status=400, message=e.args[0])

response = jsonify(
{"status": 400, "error": "bad request", "message": e.args[0]}
Expand All @@ -43,7 +43,7 @@ def bad_request(e: Exception) -> Response:
def not_found(e: Exception) -> Response:
"""App-wide handler for HTTP 404 errors."""
logger = structlog.get_logger()
logger.error(status=400)
logger.error("not found", status=400)

response = jsonify(
{
Expand All @@ -60,7 +60,7 @@ def not_found(e: Exception) -> Response:
def method_not_supported(e: Exception) -> Response:
"""Handler for HTTP 405 exceptions."""
logger = structlog.get_logger()
logger.error(status=405)
logger.error("method not support", status=405)

response = jsonify(
{
Expand All @@ -77,7 +77,7 @@ def method_not_supported(e: Exception) -> Response:
def internal_server_error(e: Exception) -> Response:
"""App-wide handler for HTTP 500 errors."""
logger = structlog.get_logger()
logger.error(status=500, message=e.args[0])
logger.error("internal server error", status=500, message=e.args[0])

response = jsonify(
{"status": 500, "error": "internal server error", "message": e.args[0]}
Expand Down
5 changes: 4 additions & 1 deletion keeper/api/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from keeper.api import api
from keeper.auth import permission_required, token_auth
from keeper.logutils import log_route
from keeper.models import Edition, Permission, Product, db
from keeper.models import Edition, Organization, Permission, Product, db
from keeper.taskrunner import (
append_task_to_chain,
insert_task_url_in_response,
Expand Down Expand Up @@ -216,8 +216,11 @@ def new_product() -> Tuple[str, int, Dict[str, str]]:
"""
product = Product()
try:
# Get default organization (v1 API adapter for organizations)
org = Organization.query.order_by(Organization.id).first_or_404()
request_json = request.json
product.import_data(request_json)
product.organization = org
db.session.add(product)
db.session.flush() # Because Edition._validate_slug does not autoflush

Expand Down
3 changes: 3 additions & 0 deletions keeper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import structlog

from keeper.models import EditionKind

if TYPE_CHECKING:
from flask import Flask

Expand Down Expand Up @@ -42,6 +44,7 @@ class Config(abc.ABC):
CELERY_RESULT_URL: str = os.getenv("REDIS_URL", "redis://localhost:6379")
CELERY_BROKER_URL: str = os.getenv("REDIS_URL", "redis://localhost:6379")
LTD_EVENTS_URL: Optional[str] = os.getenv("LTD_EVENTS_URL", None)
DEFAULT_EDITION_KIND: EditionKind = EditionKind.draft

# Suppresses a warning until Flask-SQLAlchemy 3
# See http://stackoverflow.com/a/33790196
Expand Down
Loading

0 comments on commit d8b40e3

Please sign in to comment.