Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions annotation_api/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from boto3 import client
from flasgger import Swagger
from flask import Flask
from flask_cors import CORS
from werkzeug.exceptions import HTTPException
Expand All @@ -11,11 +10,9 @@
from config import s3_config
from config import FlaskConfig, cache_config, s3_config


def create_app():
app = Flask(__name__)
app.config.from_object(FlaskConfig)
swagger = Swagger(app)

CORS(app, resources={
r'/api/*': {
Expand All @@ -42,6 +39,9 @@ def create_app():
from app.routes import bp
app.register_blueprint(bp)

from app.routers.projects import projectBp
app.register_blueprint(projectBp)

from app.routers.models import modelBp
app.register_blueprint(modelBp)

Expand All @@ -54,5 +54,8 @@ def create_app():
from app.routers.herdunits import herdunitBp
app.register_blueprint(herdunitBp)

from app.routers.schemas import schemaBp
app.register_blueprint(schemaBp)

return app

3 changes: 1 addition & 2 deletions annotation_api/app/errors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from flask import jsonify

def handle_generic_http(error):
print(error)
print(f'uhoh: {error}')
return jsonify({'error': error.name,
'code': error.code,
'message': error.description}), error.code


def internal_service_error(error):
print(f'uhoh: {error}')
return jsonify({'error': 'Internal Server Error',
Expand Down
51 changes: 43 additions & 8 deletions annotation_api/app/routers/herdunits/herdunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

#---------------------------------------------------------------------------------------------------------------------------#

from flask import Blueprint, abort, request
from app.extensions import base
from uuid import UUID

from flask import Blueprint, abort
from flask_login import login_required
from flask_pydantic import validate
from psycopg.errors import DatabaseError

from app.extensions import base
from database import ObjectNotFound


from .herdunit_validators import CreateHerdUnit
from datetime import date, datetime
from flask_login import (
login_required,
)
from typing import cast, List
from uuid import UUID

herdunitBp = Blueprint('herd_units', __name__, url_prefix='/api/v1/herd-units')

Expand Down Expand Up @@ -46,6 +48,39 @@ def get_by_id(herd_unit_id: str):

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

@herdunitBp.get('/<string:herd_unit_id>/surveys')
@login_required
def get_surveys(herd_unit_id: str):
'''
Retrieve all surveys associated with a herd unit.
---
parameters:
- name: survye_id
in: path
type: string
required: true
responses:
200:
description: List of surveys.
400:
description: Invalid UUID format.
404:
description: No surveys found.
500:
description: Database error.
'''
try:
surveys = base.get_herd_unit_surveys(UUID(herd_unit_id))

except ValueError as e:
abort(400, str(e))
except ObjectNotFound as e:
abort(404, str(e))
except (DatabaseError, Exception) as e:
abort(500)

return [survey.serialize() for survey in surveys], 200

#---------------------------------------------------------------------------------------------------------------------------#
# POST

Expand Down
1 change: 1 addition & 0 deletions annotation_api/app/routers/images/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# images/__init__.py
from .image_validators import *
from .images import *
13 changes: 10 additions & 3 deletions annotation_api/app/routers/images/image_validators.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pydantic import BaseModel
from typing import Optional, List
from typing import Optional, List, Union

class CreateImage(BaseModel):
name: str
herd_unit_id: int
survey_id: int
herd_unit_id: Union[int, str]
survey_id: Union[int, str]
img_key: str
image_length_px: int
image_width_px: int
Expand All @@ -14,6 +14,13 @@ class CreateImage(BaseModel):
dem_name: Optional[str] = None
bbox_wsen: Optional[List[int]] = None

class CreatePresignedPut(BaseModel):
image_id: Union[str, int]
upload_id: str
part_number: int
chunk_size: int
chunk_md5: str

class UpdateImage(BaseModel):
name: Optional[str] = None
herd_unit_id: Optional[int] = None
Expand Down
Loading
Loading