def update_total_days_by_id(id, body): # noqa: E501 """Updates a TotalDays in the system with form data. Role write:total_days must be granted # noqa: E501 :param id: ID of TotalDays to return :type id: int :param body: TotalDays object that needs to be updated in the system :type body: dict | bytes :rtype: TotalDays """ found = dao.get(id) if found is None: return ErrorApiResponse.TotalDaysNotFoundError(id=id), 404 if connexion.request.is_json: body = TotalDays.from_dict(connexion.request.get_json()) # noqa: E501 employee = employee_dao.get(body.employee_id) if employee is None: return ErrorApiResponse.EmployeeNotFoundError(body.employee_id), 404 # check already exists duplicate = dao.find_by_year(body.employee_id, body.year) if duplicate is not None and duplicate.id != id: return ErrorApiResponse.TotalDaysExistError(body.employee_id, body.year), 409 found.employee_id = body.employee_id found.year = body.year found.total_days = body.total_days try: dao.persist(found) return get_total_days_by_id(id) except Exception as ex: return ErrorApiResponse.InternalServerError(ex, type='total days'), 500
def add_total_days(body): # noqa: E501 """Add a employee total days to the system. Role write:total_days must be granted # noqa: E501 :param body: TotalDays object that needs to be added to the system :type body: dict | bytes :rtype: TotalDays """ if connexion.request.is_json: body = TotalDays.from_dict(connexion.request.get_json()) # noqa: E501 # check already exists found = dao.find_by_year(body.employee_id, body.year) if found is not None: return ErrorApiResponse.TotalDaysExistError(body.employee_id, body.year), 409 employee = employee_dao.get(body.employee_id) if employee is None: return ErrorApiResponse.EmployeeNotFoundError(body.employee_id), 404 orm = TotalDays_orm(employee_id=body.employee_id, total_days=body.total_days, year=body.year) try: dao.persist(orm) return find_total_days_by_year(body.employee_id, body.year) except Exception as ex: return ErrorApiResponse.InternalServerError(ex, type='total days'), 500