def delete(self, id):
     get_tag = TagModel.query.get(id)
     if get_tag:
         db.session.delete(get_tag)
         db.session.commit()
         result = self.schema.dump(get_tag)
         logger.info('Tag deleted successfully')
         return api_response(data=result, code=HTTPCode.HTTP_200_STATUS_OK)
     else:
         return api_response(msg='Tag does not exist',
                             code=HTTPCode.HTTP_400_BAD_REQUEST)
Beispiel #2
0
 def delete(self, id):
     candidate = CandidateModel.query.get(id)
     if candidate:
         db.session.delete(candidate)
         db.session.commit()
         result = self.schema.dump(candidate)
         logger.info('Record deleted successfully')
         return api_response(code=HTTPCode.HTTP_200_STATUS_OK, data=result)
     else:
         return api_response(code=HTTPCode.HTTP_200_STATUS_OK,
                             msg='Candidate Does not exist.')
Beispiel #3
0
 def post(self):
     tag_ids = request.json['tags']
     candidate_id = request.json['candidate_id']
     tags = Tag.query.filter(Tag.id.in_(tag_ids)).all()
     candidate = CandidateModel.query.get(candidate_id)
     if not candidate:
         return api_response(msg='Candidate does not exist',
                             code=HTTPCode.HTTP_200_STATUS_OK)
     candidate.addTags = tags
     db.session.commit()
     return api_response(msg='Tag added to candidate successfully',
                         code=HTTPCode.HTTP_200_STATUS_OK)
 def post(self):
     request_data = request.json
     try:
         records = TagSchema(many=True).load(request_data, unknown=EXCLUDE)
     except ValidationError as ex:
         logger.exception(ex.messages)
         return api_response(data=ex.messages,
                             code=HTTPCode.HTTP_400_BAD_REQUEST)
     db.session.add_all(records)
     db.session.commit()
     logger.info('Tags created successfully')
     return api_response(data=self.schema.dump(records, many=True),
                         code=HTTPCode.HTTP_200_STATUS_OK)
 def put(self, id):
     get_tag = TagModel.query.get(id)
     if get_tag:
         name = request.json['name']
         color = request.json['color']
         get_tag.name = name
         get_tag.color = color
         logger.info('Tag updated successfully')
         return api_response(data=self.schema.dump(get_tag),
                             code=HTTPCode.HTTP_200_STATUS_OK)
     else:
         return api_response(msg='Tag does not exist',
                             code=HTTPCode.HTTP_400_BAD_REQUEST)
Beispiel #6
0
 def put(self, id):
     candidate = CandidateModel.query.filter_by(uid=id).first()
     if candidate:
         try:
             update_candidate = self.schema.load(request.json)
         except ValidationError as ex:
             logger.exception(ex.messages)
             return api_response(code=HTTPCode.HTTP_400_BAD_REQUEST,
                                 msg=ex.__str__())
         candidate = update_candidate
         db.session.commit()
         logger.info('Record updated successfully')
         return api_response(code=HTTPCode.HTTP_200_STATUS_OK,
                             data=self.schema.jsonify(candidate))
     else:
         return api_response(code=HTTPCode.HTTP_200_STATUS_OK,
                             msg='Candidate Does not exist.')
Beispiel #7
0
def handle_exception(error):
    logger.exception(traceback.print_stack())
    response = {
        "message": error.__str__()
    }
    if app.debug:
        response['traceback'] = traceback.format_exc()
    return api_response(data=response, code=HTTPCode.HTTP_500_INTERNAL_SERVER_ERROR)
 def post(self):
     # get_data=request.json['data']
     if len(request.json['username']) == 0 or len(
             request.json['password']) == 0:
         return jsonify({'error': 'Username or password can not be  null.'})
     user = User.query.filter_by(username=request.json['username']).first()
     password = request.json['password']
     if user:
         check_pass = bcrypt.check_password_hash(user.password, password)
     else:
         return api_response(msg='Username does not exist.',
                             code=HTTPCode.HTTP_400_BAD_REQUEST)
     if user and check_pass:
         logger.info('User retrieved successfully')
         auth_response = get_auth(user_id=user.id, fresh=True)
         return api_response(data=auth_response,
                             code=HTTPCode.HTTP_200_STATUS_OK)
     return api_response(msg='Invalid username or password.',
                         code=HTTPCode.HTTP_400_BAD_REQUEST)
 def post(self):
     if len(request.json['username']) == 0 and len(
             request.json['password']) == 0 and len(
                 request.json['email']) == 0:
         return jsonify({'error': 'Every fields are required.'})
     username = request.json['username']
     password = bcrypt.generate_password_hash(
         request.json['password']).decode('utf-8')
     check_user = User.query.filter_by(username=username).first()
     if not check_user:
         user = User(username=username,
                     email=request.json['email'],
                     password=password,
                     data='')
         db.session.add(user)
         db.session.commit()
         logger.info('User created successfully')
         return api_response(data=self.schema.dump(user),
                             code=HTTPCode.HTTP_200_STATUS_OK)
     else:
         return api_response(msg='Username is already in use.',
                             code=HTTPCode.HTTP_400_BAD_REQUEST)
Beispiel #10
0
 def get(self):
     candidates = CandidateModel.query.all()
     result = self.schema.dump(candidates, many=True)
     return api_response(data=result, code=HTTPCode.HTTP_200_STATUS_OK)
Beispiel #11
0
 def get(self):
     get_tag = TagModel.query.all()
     result = self.schema.dump(get_tag, many=True)
     logger.info('Tag retrieved successfully')
     return api_response(data=result, code=HTTPCode.HTTP_200_STATUS_OK)
def handle_signature_expiration_exception(error):
    logger.exception(traceback.print_stack())
    return api_response(msg=error.__str__(),
                        code=HTTPCode.HTTP_401_UNAUTHORIZED)
Beispiel #13
0
 def post(self):
     current_user = get_jwt_identity()
     ret = {'access': create_access_token(identity=current_user)}
     return api_response(data=ret, code=HTTPCode.HTTP_200_STATUS_OK)