def add_project(): try: fetched = request.get_json() project_schema = ProjectSchema() project, error = project_schema.load(fetched) data = project_schema.dump(project.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def add_info(): try: fetched = request.get_json() info_schema = InfoSchema() info, error = info_schema.load(fetched) data = info_schema.dump(info.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def add_client(): try: fetched = request.get_json() client_schema = ClientSchema() client, error = client_schema.load(fetched) data = client_schema.dump(client.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def add_ref(): try: fetched = request.get_json() ref_schema = RefSchema() ref, error = ref_schema.load(fetched) data = ref_schema.dump(ref.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def add_sequence_size(): try: fetched = request.get_json() sequence_size_schema = SequenceSizeSchema() sequence_size, error = sequence_size_schema.load(fetched) data = sequence_size_schema.dump(sequence_size.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def add_position(): try: fetched = request.get_json() position_schema = PositionSchema() position, error = position_schema.load(fetched) data = position_schema.dump(position.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def add_library(): try: fetched = request.get_json() library_schema = LibrarySchema() library, error = library_schema.load(fetched) data = library_schema.dump(library.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def update(self, sample_id): fetched = request.get_json() sample = Sample.query.get_or_404(sample_id) if sample not None: for key, value in fetched.items(): setattr(sample, key, value) data = sample_schema.dump(sample.update()).data response_with(resp.SUCCESS_200, value={ 'sample': data })
def create_agency(): try: fetched = request.get_json() agency_schema = AgencySchema() agency, error = agency_schema.load(fetched) return str(type(agency)) data = agency_schema.dump(agency.create()).data return response_with(resp.SUCCESS_200, value={"data": data}) except: return response_with(resp.INVALID_INPUT_422)
def add_user(): # fetched = request.get_json() # import json # return json.dumps(fetched) try: fetched = request.get_json() user_schema = UserSchema() user, error = user_schema.load(fetched) data = user_schema.dump(user.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)
def login(): fetched = request.get_json() try: user = User.query.filter_by(email=fetched['email']).first() if user and user.password_is_valid(fetched['password']): access_token = {'token': str(user.generate_token(user.id))} if access_token: return response_with(resp.SUCCESS_200, value={'data': access_token}) else: return response_with(resp.INVALID_INPUT_422) except Exception as e: return response_with(resp.INVALID_INPUT_422)
def registe(): fetched = request.get_json() user = User.query.filter_by(email=fetched['email']).first() if not user: try: user_schema = UserSchema() user, error = user_schema.load(fetched) user = user_schema.dump(user.create()).data return response_with(resp.SUCCESS_200) except Exception as e: return response_with(resp.SERVER_ERROR_500) else: return response_with(resp.INVALID_INPUT_422)
def get_agency_contacts(agency_id): resource = Contact.query.filter_by(agency_id=agency_id) contact_schema = ContactSchema() data = contact_schema.dump(resource, many=True).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def get_primers(): resource = Primer.query.all() primer_schema = PrimerSchema(many=True) data = primer_schema.dump(resource).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def get_author_list(): """ Get author list --- responses: 200: description: Returns author list schema: id: AuthorList properties: code: type: string message: type: string authors: type: array items: schema: id: AuthorSummary properties: name: type: string surname: type: string """ fetched = Author.query.all() author_schema = AuthorSchema(many=True, only=['name', 'surname']) authors, error = author_schema.dump(fetched) return response_with(resp.SUCCESS_200, value={"authors": authors})
def get_project_subprojects(project_id): resource = Subproject.query.filter_by(project_id=project_id) subproject_schame = SubprojectSchema(many=True, exclude=('pmid', 'ori_num', 'type', 'amount')) data = subproject_schame.dump(resource).data return response_with(resp.SUCCESS_200, value={'data': data})
def new_group(): id = str(uuid.uuid4()) pg = ParamGroup(id) result = ParamGroupSchema().dump(pg.create()) print(result) ret = response_with(SUCCESS_201, result) return ret
def get_agency_batches(agency_id): resource = Batch.query.filter_by(agency_id=agency_id) batch_schema = BatchSchema(many=True) data = batch_schema.dump(resource).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def get_sequence_areas(): resource = SequenceArea.query.all() sequence_area_schema = SequenceAreaSchema(many=True) data = sequence_area_schema.dump(resource).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def get_roadmaps(): resource = Roadmap.query.all() roadmap_schema = RoadmapSchema(many=True) data = roadmap_schema.dump(resource).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def get_contracts(): resource = Contract.query.all() contract_schema = ContractSchema(many=True) data = contract_schema.dump(resource).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def add_contact(): fetched = request.get_json() contact_schema = ContactSchema() contact, error = contact_schema.load(fetched) data = contact_schema.dump(contact.create()).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def get(self, client_id=None): if sample_id not None: sample = Sample.query.get_or_404(sample_id) if sample not None: data = sample_schema.dump(sample).data return response_with(resp.SUCCESS_200, value={ 'sample': data })
def get_batches(): resource = Batch.query.all() batch_schema = BatchSchema(many=True, exclude=('agency_id', 'contact_id', 'store_time', 'position_id', 'subproject_id', 'roadmap_id', 'remark', 'samples')) # return type(batch_schema) data = batch_schema.dump(resource).data return response_with(resp.SUCCESS_200, value={ 'data': data })
def post(self): fetched = request.get_json() if len(fetched) > 0: sample, error = sample_schema.load(fetched) data = sample_schema.dump(sample.add()).data return response_with(resp.SUCCESS_200, value={ 'sample': data })
def update_sample(id): fetched = request.get_json() resource = Sample.query.get_or_404(id) for key, value in fetched: setattr(resource, key, value) sample_schema = SampleSchema() data = sample_schema.dump(resource.update()).data return response_with(resp.SUCCESS_200, value={'data': data})
def update_info(id): fetched = request.get_json() resource = Info.query.get_or_404(id) for key, value in fetched.items(): setattr(resource, key, value) info_schema = InfoSchema() data = info_schema.dump(resource.update()).data return response_with(resp.SUCCESS_200, value={'data': data})
def update_agency(id): fetched = request.get_json(force=True) resource = Agency.query.get_or_404(id) for key, value in fetched.items(): setattr(resource, key, value) agency_schema = AgencySchema() data = agency_schema.dump(resource.update()).data return response_with(resp.SUCCESS_200, value={"data": data})
def update_sequence_size(id): fetched = request.get_json() resource = SequenceSize.query.get_or_404(id) for key, value in fetched.items(): setattr(resource, key, value) sequence_size_schema = SequenceSizeSchema() data = sequence_size_schema.dump(resource.update()).data return response_with(resp.SUCCESS_200, value={'data': data})
def add_sample(): fetched = request.get_json() # import json # return json.dumps(fetched) sample_schema = SampleSchema() sample, error = sample_schema.load(fetched) data = sample_schema.dump(sample.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) try: fetched = request.get_json() import json return josn.dumps(fetched) sample_schema = SampleSchema() sample, error = sample_schema.load(fetched) data = sample_schema.dump(sample.create()).data return response_with(resp.SUCCESS_200, value={'data': data}) except: return response_with(resp.INVALID_INPUT_422)