示例#1
0
    def test_search_from_db_project_success(self):
        """
        1.測試 VersionInfoService 的 search_from_db function - project
        2.search_from_db, 正常回傳

        """
        objectType = "project"
        page = 1
        page_size = 10
        request = request_project_data(full=True)
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="search")
        version_vo.validate(objectType, api_type="search")
        service = VersionInfoService(app_context)
        result, cost_time, page_object = service.search_from_db(
            objectType, version_vo, page, page_size)
示例#2
0
def search_func(objectType):
    app_context = current_app.config["app_context"]
    response_payload = ReponsePayloadBulider(app_context.messages)

    if request.method == "POST":
        req_data = request.get_json()
        versionVo = VersionInfoVo()
        versionVo.value_of_import(req_data, objectType, api_type="search")
        if not req_data:
            logger.error("json body is empty")
            return json.jsonify(response_payload.bulid("999900001"))

    try:
        if req_data.get("page") is not None:
            page = req_data["page"]
        else:
            page = 1
        if req_data.get("pageSize") is not None:
            page_size = req_data["pageSize"]
        else:
            page_size = 20
        versionVo.validate(objectType, api_type="search")
        service = VersionInfoService(app_context)
        result, cost_time, page_object = service.search_from_db(
            objectType, versionVo, page, page_size)
        return json.jsonify(
            response_payload.bulid("996600001",
                                   cost_time=cost_time,
                                   data=result,
                                   paging=page_object))
    except CommonRuntimeException as crex:
        logger.error(traceback.format_exc())
        return json.jsonify((response_payload.bulid_from_exception(crex)))
    except AssertionError as ae:
        return json.jsonify((response_payload.bulid(ae.args[0])))
    except:
        logger.error(traceback.format_exc())
        return json.jsonify(response_payload.bulid("999999999"))