示例#1
0
def get_mesh(id: str) -> RespT:
    """Add or update mesh.
    ---
    get:
        tags:
            - Models
        summary: Gets mesh by id.
        parameters:
            - name: id
              in: path
              description: unique ID
              required: true
              schema:
                type: string
        responses:
            200:
              description: Ok
              content:
                application/json:
                    schema:
                        $ref: Mesh
            404:
              description: Model not found.
              content:
                application/json:
                  schema:
                    $ref: WebApiError
    """

    try:
        return jsonify(humps.camelize(MESHES[id].to_dict()))
    except KeyError:
        return common.WebApiError(f"Mesh {id} was not found.",
                                  PROJECT_SERVICE_NAME).to_json(), 404
示例#2
0
def get_cylinder(id: str) -> RespT:
    """Add or update cylinder.
    ---
    get:
        tags:
            - Models
        summary: Gets ServiceType by service id.
        parameters:
            - name: id
              in: path
              description: unique ID
              required: true
              schema:
                type: string
        responses:
            200:
              description: Ok
              content:
                application/json:
                    schema:
                        $ref: Cylinder
            404:
              description: Model not found.
              content:
                application/json:
                  schema:
                    $ref: WebApiError
    """

    try:
        return jsonify(humps.camelize(CYLINDERS[id].to_dict()))
    except KeyError:
        return common.WebApiError(f"Cylinder {id} was not found.",
                                  PROJECT_SERVICE_NAME).to_json(), 404
示例#3
0
def delete_object_type(id: str) -> RespT:
    """Deletes object type.
    ---
    delete:
        tags:
            - ObjectType
        summary: Deletes object type.
        parameters:
            - name: id
              in: path
              description: unique ID
              required: true
              schema:
                type: string
        responses:
            200:
              description: Ok
            404:
              description: ObjectType not found.
              content:
                application/json:
                  schema:
                    $ref: WebApiError
    """

    try:
        del OBJECT_TYPES[id]
    except KeyError:
        return common.WebApiError(f"ObjectType {id} was not found.",
                                  PROJECT_SERVICE_NAME).to_json(), 404

    return Response(status=200)
示例#4
0
def get_object_type(id: str) -> RespT:
    """Add or update object_type.
    ---
    get:
        tags:
            - ObjectType
        summary: Gets object_type by project id.
        parameters:
            - name: id
              in: path
              description: unique ID
              required: true
              schema:
                type: string
        responses:
          200:
            description: Ok
            content:
              application/json:
                schema:
                  $ref: ObjectType
          404:
            description: ObjectType not found.
            content:
              application/json:
                schema:
                  $ref: WebApiError
    """

    try:
        return jsonify(humps.camelize(OBJECT_TYPES[id].to_dict()))
    except KeyError:
        return common.WebApiError(f"ObjectType {id} was not found.",
                                  PROJECT_SERVICE_NAME).to_json(), 404
示例#5
0
def put_scene() -> RespT:
    """Add or update scene.
    ---
    put:
        tags:
            - Scene
        description: Add or update scene.
        requestBody:
              content:
                application/json:
                  schema:
                    $ref: Scene
        responses:
            200:
              description: Timestamp of last scene modification.
              content:
                application/json:
                  schema:
                    type: string
                    format: date-time
            404:
              description: Object type with specific id related to putted scene not exist.
              content:
                application/json:
                  schema:
                    $ref: WebApiError
    """

    if not isinstance(request.json, dict):
        raise FlaskException("Body should be a JSON dict containing Scene.",
                             error_code=400)

    scene = common.Scene.from_dict(humps.decamelize(request.json))

    for obj in scene.objects:
        if obj.type not in OBJECT_TYPES:
            return common.WebApiError(f"ObjectType {obj.type} does not exist.",
                                      PROJECT_SERVICE_NAME).to_json(), 404

    scene.modified = datetime.now(tz=timezone.utc)
    scene.int_modified = None

    if scene.id not in SCENES:
        scene.created = scene.modified
    else:
        scene.created = SCENES[scene.id].created

    SCENES[scene.id] = scene
    return jsonify(scene.modified.isoformat())
示例#6
0
def put_project() -> RespT:
    """Add or update project.
    ---
    put:
        tags:
            - Project
        description: Add or update project.
        requestBody:
              content:
                application/json:
                  schema:
                    $ref: Project
        responses:
            200:
              description: Timestamp of last project modification.
              content:
                application/json:
                  schema:
                    type: string
            404:
              description: Scene with specific id related to project not found.
              content:
                application/json:
                  schema:
                    $ref: WebApiError
    """

    if not isinstance(request.json, dict):
        raise FlaskException("Body should be a JSON dict containing Project.",
                             error_code=400)

    project = common.Project.from_dict(humps.decamelize(request.json))

    if project.scene_id not in SCENES:
        return common.WebApiError(f"Scene {id} does not exist.",
                                  PROJECT_SERVICE_NAME).to_json(), 404

    project.modified = datetime.now(tz=timezone.utc)
    project.int_modified = None

    if project.id not in PROJECTS:
        project.created = project.modified
    else:
        project.created = PROJECTS[project.id].created

    PROJECTS[project.id] = project
    return jsonify(project.modified.isoformat())
示例#7
0
def delete_model(id: str) -> RespT:
    """Deletes model.
    ---
    delete:
        tags:
            - Models
        summary: Deletes model.
        parameters:
            - name: id
              in: path
              description: unique ID
              required: true
              schema:
                type: string
        responses:
            200:
              description: Ok
            404:
              description: Not found.
              content:
                application/json:
                  schema:
                    $ref: WebApiError
    """

    try:
        del BOXES[id]
    except KeyError:
        try:
            del CYLINDERS[id]
        except KeyError:
            try:
                del SPHERES[id]
            except KeyError:
                try:
                    del MESHES[id]
                except KeyError:
                    return common.WebApiError(
                        f"Model {id} was not found.",
                        PROJECT_SERVICE_NAME).to_json(), 404

    return Response(status=200)