Ejemplo n.º 1
0
def signin(auth_service: AuthService, user_serivce: UserService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        return jsonify({"auth": AuthVo(auth).to_dict(), "user": UserVo(auth.user).to_dict()}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500
Ejemplo n.º 2
0
def delete(id: str, user_service: UserService, auth_service: AuthService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        user = user_service.delete(id)
        return jsonify({"user": UserVo(user).to_dict()}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500
Ejemplo n.º 3
0
def delete(id: str, note_service: NoteService, auth_service: AuthService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        note_model = note_service.delete(id)
        note = NoteVo(note_model).to_dict() if note_model else {}
        return jsonify({"note": note}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500
Ejemplo n.º 4
0
def logout(auth_service: AuthService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        auth = auth_service.delete(auth.id)

        return jsonify({"auth": AuthVo(auth).to_dict()}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500
Ejemplo n.º 5
0
def upload(file_service: FileService, auth_service: AuthService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        if not request.files:
            return jsonify({'message': 'Fail is not found ...'}), 400

        file_ = request.files.get('file')
        file_model = file_service.create(auth.user.id, file_)

        return jsonify({"file": FileVo(file_model).to_dict()}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500
Ejemplo n.º 6
0
def update(note_service: NoteService, auth_service: AuthService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        fields = json.loads(request.form["fields"])
        logger.error(fields["tags"])
        logger.error(type(fields["tags"]))
        fields = _convert_to_snake_case(fields)

        note = note_service.update(fields)

        return jsonify({"note": NoteVo(note).to_dict()}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500
Ejemplo n.º 7
0
def update(user_service: UserService, file_service: FileService,
           auth_service: AuthService):
    try:
        auth = auth_service.validate(request.headers["Authorization"])
        if not auth:
            return jsonify({"message": "Not authorized"}), 401

        fields = json.loads(request.form["fields"])

        if request.files:
            file_ = request.files.get('file')
            file_model = file_service.create(fields["id"], file_)
            fields["avatar"] = file_model.path

        user = user_service.update(fields)

        return jsonify({"user": UserVo(user).to_dict()}), 200
    except Exception as e:
        logger.error(e)
        return jsonify({'message': 'Failed ...'}), 500