def update_child_attendance(event: dict, context: LambdaContext) -> dict: logger.info(f"in update_child_attendance, event: {event}") if "pathParameters" not in event or "child_id" not in event[ "pathParameters"]: return build_response(HTTPStatus.BAD_REQUEST, event) try: child_id: str = event["pathParameters"]["child_id"] now: Decimal = Decimal(datetime.now().timestamp()) body = event["body"] logger.debug(f"input body: {body}") attendance = Attendance.parse_raw(event["body"]) if attendance.attended and attendance.attended.upper() == "TRUE": logger.info( f"Setting attendance for chile_id: {child_id} at time: {now}") return build_response(HTTPStatus.OK, json.dumps("attendance updated")) # if for a reason the attended is false, there is notning to update. just return 200 OK return build_response( HTTPStatus.OK, json.dumps( "attendance not updated, FALSE is not currently supported")) except (ValidationError, TypeError) as err: logger.exception( "Failed to update child attendance, retuning bad request", err) return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: logger.exception("Failed to update child attendance, returning error", err) return build_error_response(err)
def get_child_reports(event: dict, context: LambdaContext) -> dict: if "pathParameters" not in event or "child_id" not in event[ "pathParameters"]: return build_response(HTTPStatus.BAD_REQUEST, event) try: child_id: str = event["pathParameters"]["child_id"] daily_reports_dtos = [] query_results = execute_query( f"CALL get_daily_reports_per_child_id ('{child_id}');") for report in query_results: daily_report = DailyReport(*report) daily_report_dto = DailyReportGetDto( child_id=child_id, value=daily_report.report_value, category_id=daily_report.category_id, subcategory_id=daily_report.subcategory_id, sender_id=daily_report.sender_id, timestamp=daily_report.report_date.strftime( "%m/%d/%Y, %H:%M:%S")) daily_reports_dtos.append(daily_report_dto.dict()) if daily_reports_dtos is None: return build_response(HTTPStatus.NOT_FOUND, body="") body = json.dumps({'daily_reports': daily_reports_dtos}) return build_response(HTTPStatus.OK, body) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def add_child_report(event: dict, context: LambdaContext) -> dict: if "pathParameters" not in event or "child_id" not in event[ "pathParameters"]: return build_response(HTTPStatus.BAD_REQUEST, "") try: child_id: str = event["pathParameters"]["child_id"] daily_report = DailyReportAddDto.parse_raw(event["body"]) # TODO get from DB return build_response(http_status=HTTPStatus.CREATED, body=daily_report.json()) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def get_kesher(event: dict, context: LambdaContext) -> dict: if "pathParameters" not in event or "name" not in event["pathParameters"]: return build_response(HTTPStatus.BAD_REQUEST, "") try: name: str = event["pathParameters"]["name"] # Note: dates should be read from the database now: Decimal = Decimal(datetime.now().timestamp()) item: Kesher = Kesher(name=name, created_date=now, updated_date=now) if item is None: return build_response(HTTPStatus.NOT_FOUND, body="{ 'message': 'item was not found' }") body = item.json() return build_response(HTTPStatus.OK, body) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def update_kesher(event: dict, context: LambdaContext) -> dict: if "pathParameters" not in event or "name" not in event["pathParameters"]: return build_response(HTTPStatus.BAD_REQUEST, "") try: # pylint: disable=unused-variable name: str = event["pathParameters"]["name"] kesher_dto: KesherDto = KesherDto.parse_raw(event["body"]) now: Decimal = Decimal(datetime.now().timestamp()) kesher: Kesher = Kesher( name=kesher_dto.name, created_date=now - 1000, # Note 'created_date' should be read from the database updated_date=now) return build_response(HTTPStatus.OK, kesher.json()) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def get_user_profile(event: dict, context: LambdaContext) -> dict: try: user_profile = UserProfile(role_type=3) body = json.dumps(user_profile.json()) return build_response(HTTPStatus.OK, body) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def create_kesher(event: dict, context: LambdaContext) -> dict: try: kesher_dto: KesherDto = KesherDto.parse_raw(event["body"]) now: Decimal = Decimal(datetime.now().timestamp()) kesher: Kesher = Kesher(name=kesher_dto.name, created_date=now, updated_date=now) return build_response(http_status=HTTPStatus.CREATED, body=kesher.json()) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def get_children(event: dict, context: LambdaContext) -> dict: try: children = [ Child(id='12345', first_name='Yeled', last_name='One').dict(), Child(id='436346', first_name='Kid', last_name='Two').dict() ] body = json.dumps({'children': children}) return build_response(HTTPStatus.OK, body) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)
def get_report_categories_list(event: dict, context: LambdaContext) -> dict: try: logger.debug("in get_report_categories_list") query_results = execute_query(f"CALL get_categories_and_subcategories();") sub_categories = [] for record in query_results: sub_categories.append(SubCategory(*record)) category_dtos = _sub_categories_models_to_dtos(sub_categories) body = json.dumps({'categories': category_dtos}) return build_response(http_status=HTTPStatus.OK, body=body) except (ValidationError, TypeError) as err: return build_error_response(err, HTTPStatus.BAD_REQUEST) except Exception as err: return build_error_response(err)