Exemple #1
0
def get_material_controller(pg_db, request):
    try:
        material_rp = repository.MaterialRepository(pg_db)
        material_sv = services.MaterialServices(material_rp)
        result, data = material_sv.get_material_sv(request)
        if result is False:
            return jsonify(
                model.ErrorResponseDto(HTTPStatus.BAD_REQUEST,
                                       data).__dict__), HTTPStatus.BAD_REQUEST
        return jsonify(model.SuccessResponseDto(HTTPStatus.OK, data).__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
def update_info_food_controller(request, pg_db, food_id):
    try:
        result, message = services.update_info_food(pg_db, request, food_id)
        if result:
            return jsonify(
                model.SuccessResponseDto(HTTPStatus.OK,
                                         "Update Food Success").__dict__)
        else:
            return jsonify(
                model.ErrorResponseDto(
                    HTTPStatus.BAD_REQUEST,
                    message).__dict__), HTTPStatus.BAD_REQUEST
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #3
0
def add_file_food_controller(pg_db, mq_channel_connect, request):
    try:
        food_rp = repository.FoodRepository(pg_db)
        mq_channel_manager = MQChannelManager(mq_channel_connect)
        food_file_sv = services.FoodFileServices(food_rp, mq_channel_manager)
        result, data = food_file_sv.add_food_by_file(request)
        if result is False:
            return jsonify(
                model.ErrorResponseDto(HTTPStatus.BAD_REQUEST,
                                       data).__dict__), HTTPStatus.BAD_REQUEST
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #4
0
def add_file_material_controller(pg_db, mq_channel, request):
    try:
        material_rp = repository.MaterialRepository(pg_db)
        mq_channel_manager = MQChannelManager(mq_channel)
        material_file_services = services.MaterialFileServices(
            material_rp, mq_channel_manager)
        result, data = material_file_services.add_file_list_material(request)
        if result is False:
            return jsonify(
                model.ErrorResponseDto(HTTPStatus.BAD_REQUEST,
                                       data).__dict__), HTTPStatus.BAD_REQUEST
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
def add_material_type_controller(pg_db, redis_connect, request):
    try:
        material_type_rp = repository.MaterialTypeRepository(pg_db)
        material_type_sv = services.MaterialTypeServices(material_type_rp)
        redis_manager = provider.RedisManager(redis_connect)
        material_type_sv.set_redis_manager(redis_manager)
        result, data = material_type_sv.add_material_type_sv(request)
        if result is False:
            return jsonify(
                model.ErrorResponseDto(HTTPStatus.BAD_REQUEST,
                                       data).__dict__), HTTPStatus.BAD_REQUEST
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
def get_food_filter_controller():
    try:
        result = services.food_filter()
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, result).__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
def add_food_controller(request, pg_db):
    try:
        services.add_food(pg_db, request)
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK,
                                     "Add Food Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #8
0
def init_index_elasticsearch_controller(es):
    try:
        elasticsearch_manager = ElasticsearchManager(es)
        elasticsearch_manager.init_index(IndexElasticEnum.Food.value,
                                         IndexElasticMappingEnum.Food.value)
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
def get_all_food_controller(pg_db, es, request):
    try:
        food_rp = repository.FoodRepository(pg_db)
        elasticsearch_manager = provider.ElasticsearchManager(es)
        food_sv = services.FoodServices(food_rp, elasticsearch_manager)
        result = food_sv.search_food_elasticsearch(request)
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, result).__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #10
0
def download_file_food_controller(pg_db, mq_channel_connect, request):
    try:
        food_rp = repository.FoodRepository(pg_db)
        mq_channel_manager = MQChannelManager(mq_channel_connect)
        food_file_sv = services.FoodFileServices(food_rp, mq_channel_manager)
        food_file_sv.download_file_food(request)
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #11
0
def download_file_material_controller(pg_db, mq_channel, request):
    try:
        material_rp = repository.MaterialRepository(pg_db)
        mq_channel_manager = MQChannelManager(mq_channel)
        material_file_services = services.MaterialFileServices(
            material_rp, mq_channel_manager)
        material_file_services.download_file_csv_material(request)
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #12
0
def sync_es_food_controller(pg_db, mq_channel_connect, request):
    try:
        food_rp = repository.FoodRepository(pg_db)
        mq_channel_manager = MQChannelManager(mq_channel_connect)
        sync_food_es_services = services.SyncESFoodServices(
            food_rp, mq_channel_manager)
        sync_food_es_services.sync_by_list_id(request)
        return jsonify(
            model.SuccessResponseDto(HTTPStatus.OK, "Success").__dict__)
    except Exception as e:
        print(e)
        return jsonify(
            model.ErrorResponseDto(
                HTTPStatus.INTERNAL_SERVER_ERROR,
                "Internal Error").__dict__), HTTPStatus.INTERNAL_SERVER_ERROR
Exemple #13
0
 def page_not_found(e):
     result = model.ErrorResponseDto(HTTPStatus.NOT_FOUND, "Api Not Found")
     return jsonify(result.__dict__), HTTPStatus.NOT_FOUND