def on_post(self, request, response): year = request.media.get('year') month = request.media.get('month') converter = ToNum() year = converter.to_num(year) month = converter.to_num(month) time_sheets = self.use_case.get_for_all_employees(year, month) response.body = json.dumps(time_sheets)
def on_patch(self, request, response, time_sheet_id, day): converter = ToNum() time_sheet_id = converter.to_num(time_sheet_id) day_value = converter.to_num(request.media.get('value')) day = converter.to_num(day) self.use_case_update.update_day_mark(time_sheet_id, day, day_value) time_sheet = self.use_case_get.get_by_id(time_sheet_id) response.body = json.dumps(time_sheet)
def on_patch(self, request, response, time_sheet_id): converter = ToNum() time_sheet_id = converter.to_num(time_sheet_id) norm = converter.to_num(request.media.get('norm')) sheet = converter.to_num(request.media.get('sheet')) self.use_case_update.update_time_sheet(time_sheet_id, norm, sheet) time_sheet = self.use_case_get.get_by_id(time_sheet_id) response.body = json.dumps(time_sheet)
def __validate_expired_date(cls, credentials, date): exp_date_year, exp_date_month, exp_date_day = credentials[ 'exp_date'].split('-') converter = ToNum() expired_date = datetime(converter.to_num(exp_date_year), converter.to_num(exp_date_month), converter.to_num(exp_date_day)) if expired_date <= date: raise TokenExpiredError()
def on_post(self, request, response, employee_id): self.check_admin_use_case.check_rights(self.user_email) date = datetime.strptime(request.media.get('employment_date'), '%Y.%m.%d') converter = ToNum() vacation = converter.to_num(request.media.get('vacation')) employee_id = converter.to_num(employee_id) self.accept_use_cage.register_employee(employee_id, date, vacation) response.status = falcon.HTTP_201
def on_post(self, request, response): # TODO: добавил для примера, необходимо дописать тесты и проверить на скачивание файла # TODO, возможно изменить способ прикрепления файла к response # TODO: http://falcon.readthedocs.io/en/stable/user/tutorial.html#creating-resources year = request.media.get('year') month = request.media.get('month') converter = ToNum() year = converter.to_num(year) month = converter.to_num(month) report_path = self.use_case.get_formed_report_by_date( date=datetime(year, month, 1)) report = {'report': report_path} response.data = msgpack.packb(report, use_bin_type=True) report.content_type = falcon.MEDIA_MSGPACK
def on_patch(self, request, response): converter = ToNum() employee = self.get_use_case.get_employee_by_email(self.user_email) employee_id = converter.to_num(employee['id']) email = request.media.get('email') name = request.media.get('name') old_password = request.media.get('old_password') new_password = request.media.get('new_password') self.update_use_case.update_employee(employee_id, name=name, email=email, old_password=old_password, new_password=new_password) employee = self.get_use_case.get_employee(employee_id) token = self.check_use_case.get_new_token(employee['email']) response.body = json.dumps({'profile': employee, 'token': token})
def on_patch(self, request, response, employee_id): year = request.media.get('year') month = request.media.get('month') sheet = request.media.get('sheet') converter = ToNum() year = converter.to_num(year) month = converter.to_num(month) employee_id = converter.to_num(employee_id) if None in [employee_id, year, month, sheet]: response.status = falcon.HTTP_400 return self.update_use_case.update_time_sheet_for(employee_id, year, month, sheet) time_sheet = self.get_use_case.get_for_employee( employee_id, year, month)[0] response.body = json.dumps(time_sheet)
def on_post(self, request, response, employee_id): year = request.media.get('year') month = request.media.get('month') norm = request.media.get('norm') converter = ToNum() year = converter.to_num(year) month = converter.to_num(month) norm = converter.to_num(norm) employee_id = converter.to_num(employee_id) employee = self.use_case.calculate_vacation_for( employee_id, year, month, norm) response.body = json.dumps(employee)
def test_to_int(self): converter = ToNum() str_num = '1' int_num = converter.to_int(str_num) self.assertEqual(int_num, 1) str_num = '0' int_num = converter.to_int(str_num) self.assertEqual(int_num, 0) str_num = '01' int_num = converter.to_int(str_num) self.assertEqual(int_num, 1) str_num = '001' int_num = converter.to_int(str_num) self.assertEqual(int_num, 1)
def test_to_float(self): converter = ToNum() str_num = '1' int_num = converter.to_float(str_num) self.assertEqual(int_num, 1.) str_num = '0' int_num = converter.to_float(str_num) self.assertEqual(int_num, 0.) str_num = '0.1' int_num = converter.to_float(str_num) self.assertEqual(int_num, .1) str_num = '00.01' int_num = converter.to_float(str_num) self.assertEqual(int_num, .01)
def on_get(self, request, response, employee_id): converter = ToNum() employee_id = converter.to_num(employee_id) employee = self.use_case.get_employee(employee_id) response.body = json.dumps(employee)
def on_get(self, request, response, time_sheet_id, day): converter = ToNum() time_sheet_id = converter.to_num(time_sheet_id) day = converter.to_num(day) time_sheet = self.use_case_get.get_by_id(time_sheet_id) response.body = json.dumps(time_sheet['sheet'][day - 1])
def test_to_num_with_none(self): converter = ToNum() str_num = None int_num = converter.to_num(str_num) self.assertEqual(int_num, None)