def patch(schema: ApplicationFeatureRequestSchema,
          name: str,
          dbcontext: DbContext = Depends(get_dbcontext),
          current_user: User = Depends(get_current_user)):
    try:
        data = schema.__dict__
        service = ApplicationService(dbcontext)
        application: Application = None
        if "all" in data.keys() and data["all"]:
            application = service.add_feature_all_environments(
                name, data, current_user)
        else:
            application = service.add_feature(name, data, current_user)
        features: List[ApplicationFeatureResponseSchema] = [
            ApplicationFeatureResponseSchema(
                environment_id=feature.environment_id,
                environment=feature.environment.name,
                name=feature.name,
                enable=feature.enable) for feature in application.features
        ]

        return features
    except IntegrityError:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail=f"The feature({schema.name}) already exists this environment"
        )
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
def delete(feature_name: str,
           name: str,
           environment_id: Optional[int] = 0,
           dbcontext: DbContext = Depends(get_dbcontext),
           current_user: User = Depends(get_current_user)):
    try:
        service = ApplicationService(dbcontext)
        application: Application = None
        if environment_id > 0:
            application = service.remove_feature(name, feature_name,
                                                 environment_id, current_user)
        else:
            application = service.remove_feature_all_environments(
                name, feature_name, current_user)
        features: List[ApplicationFeatureResponseSchema] = [
            ApplicationFeatureResponseSchema(
                environment_id=feature.environment_id,
                environment=feature.environment.name,
                name=feature.name,
                enable=feature.enable) for feature in application.features
        ]

        return features
    except IntegrityError as e:
        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST,
                            detail=str(e))
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))
Esempio n. 3
0
async def get(name: str,
              current_user: dict = Depends(get_current_user),
              service: ApplicationService = Depends(get_application_service)):
    try:
        features = await service.get_application_features(name, current_user)

        return [
            ApplicationFeatureResponseSchema(**feature) for feature in features
        ]
    except ValueError as e:
        return bad_request(str(e))
def get(name: str,
        dbcontext: DbContext = Depends(get_dbcontext),
        current_user: User = Depends(get_current_user)):
    try:
        application = ApplicationService(dbcontext).get_by_name(
            name, current_user)
        features: List[ApplicationFeatureResponseSchema] = [
            ApplicationFeatureResponseSchema(
                environment_id=feature.environment_id,
                environment=feature.environment.name,
                name=feature.name,
                enable=feature.enable) for feature in application.features
        ]

        return features
    except ValueError as e:
        raise HTTPException(status_code=status.HTTP_204_NO_CONTENT,
                            detail=str(e))