def list_sellers(*args):
        db_connection = None
        user = g.token_info
        filter_info = {
            'seller_id': args[0],
            'account_id': args[1],
            'email': args[2],
            'seller_en': args[3],
            'seller_kr': args[4],
            'user_id': args[5],
            'manager_name': args[6],
            'manager_email': args[7],
            'seller_status': args[8],
            'manager_phone': args[9],
            'seller_category': args[10],
            'created_upper': args[11],
            'created_lower': args[12],
            'excel': args[13],
            'page': args[14] if args[14] else 1,
            'limit': args[15] if args[15] else 10,
            'order_by': args[16]
        }
        try:
            connection = connect_db()
            account_service = AccountService()
            seller_list = account_service.filter_seller(filter_info, user, connection)
            return jsonify({'seller_list': seller_list}), 200

        except Exception as e:
            return jsonify({'MESSAGE': f'{e}'}), 400
        finally:
            connection.close()
 def edit_seller(*args):
     connection = None
     change_info = {
         'subcategory_id': args[0],
         'seller_status_id': args[1],
         'seller_name_kr': args[2],
         'seller_name_en': args[3],
         'seller_number': args[4],
         'profile_pic_url': args[5],
         'short_desc': args[6],
         'long_desc': args[7],
         'open_time': args[8],
         'close_time': args[9],
         'delivery_policy': args[10],
         'return_policy': args[11],
         'zip_code': args[12],
         'address_1': args[13],
         'address_2': args[14],
         'is_open_weekend': args[15],
         'seller_id': args[16]
     }
     connection = connect_db()
     user = g.token_info
     if connection:
         account_service = AccountService()
         try:
             change_account = account_service.change_seller_info(change_info, user, connection)
             connection.commit()
             return change_account
         except Exception as e:
             connection.rollback()
             return jsonify({'MESSAGE': f'{e}'}), 400
         finally:
             connection.close()
    def sign_up_master(*args):
        connection = None
        account_info = {
            'email': args[0],
            'password': args[1],
            'account_type_id': args[2],
            'name': args[4],
            'master_code': args[5]
        }

        connection = connect_db()
        if connection:
            account_service = AccountService()
            try:
                account_service.signup_account(account_info, connection)
                if account_info['master_code'] != 'brandi_team1':
                    connection.rollback()
                    return jsonify({'MESSAGE': 'WRONG_MASTER_CODE'})
                connection.commit()
                return jsonify({'MESSAGE': 'ACCOUNT_CREATED', }), 200
            except Exception as e:
                connection.rollback()
                return jsonify({'MESSAGE': f'{e}'}), 400
            finally:
                if connection:
                    connection.close()
    def sign_up_seller(*args):
        connection = None
        try:
            account_info = {
                'email': args[0],
                'password': args[1],
                'account_type_id': args[2],
                'name': '미설정',
                'service_number': args[4],
                'seller_name_kr': args[5],
                'seller_name_en': args[6],
                'subcategory_id': args[7],
                'seller_status_id': 1
            }
            print(account_info)
            connection = connect_db()
            account_service = AccountService()
            account_service.signup_seller(account_info, connection)
            connection.commit()

            return jsonify({'MESSAGE': 'SUCCESS'}), 200
        except Exception as e:
            connection.rollback()
            return jsonify({'MESSAGE': f'{e}'}), 400
        finally:
            if connection:
                connection.close()
def signup(request):
    signup_html_page = loader.get_template('../ui/signup.html')
    context = {}
    if request.method == 'POST':
        full_name = request.POST["txtFullname"]
        email = request.POST["txtEmail"]
        password = request.POST["txtPassword"]
        cpassword = request.POST["txtCPassword"]
        user = User()
        user.full_name = full_name
        user.email = email
        user_register = UserRegister()
        user_register.user = user
        user_register.password = password
        user_register.cpassword = cpassword
        context["user_register"] = user_register
        if not full_name or len(str(full_name).strip(' ')) <= 4:
            context["error_msg"] = "Invalid full name."
        elif not email:
            context["error_msg"] = "Invalid email."
        elif not password or len(str(password).strip(' ')) <= 7:
            context["error_msg"] = "Password must be 8 character long."
        elif not cpassword or cpassword != password:
            context["error_msg"] = "Password don't match."
        else:
            account_service = AccountService()
            service_response = account_service.signup(user_register)
            if service_response is None:
                context["error_msg"] = "Could not save user."
            else:
                context["success_msg"] = "User saved successfully."

    return HttpResponse(signup_html_page.render(context, request))
Exemplo n.º 6
0
    def delete_client_account_id(client_id, account_id):
        try:
            ClientService.get_client_by_id(int(client_id))
            AccountService.get_account_by_id(int(account_id))

            AccountService.delete_account(int(account_id))
            return 'Successfully Deleted', 205
        except ResourceNotFound as r:
            return r.message, 404
def compare(smart_meter_id):
    price_plan_service = PricePlanService(readings_repository)
    account_service = AccountService()
    list_of_spend_against_price_plans = price_plan_service.get_list_of_spend_against_each_price_plan_for(
        smart_meter_id)

    if len(list_of_spend_against_price_plans) < 1:
        abort(404)
    else:
        return {
            "pricePlanId": account_service.get_price_plan(smart_meter_id),
            "pricePlanComparisons": list_of_spend_against_price_plans
        }
Exemplo n.º 8
0
    def put_client_account_id(client_id, account_id):
        try:
            client_id = ClientService.get_client_by_id(int(client_id))
            AccountService.get_account_by_id(int(account_id))

            account = Account.json_parse(request.json)
            account.client_id = client_id

            account.account_id = int(account_id)
            account = AccountService.update_account(account)
            return jsonify(account.json()), 200
        except ResourceNotFound as r:
            return r.message, 404
 def sign_in():
     connection = None
     try:
         connection = connect_db()
         login_data = request.json
         account_service = AccountService()
         token = account_service.signin(login_data, connection)
         return token
     except Exception as e:
         return jsonify({'MESSAGE': f'{e}'}), 400
     finally:
         if connection:
             connection.close()
def signin(request):
    signup_html_page = loader.get_template('../ui/index.html')
    context = {}
    if request.method == 'POST':
        email = request.POST["txtEmail"]
        password = request.POST["txtPassword"]
        if not email:
            context["error_msg"] = "Invalid email or password."
        else:
            account_service = AccountService()
            user = account_service.signin(email, password)
            if user is None:
                context["error_msg"] = "Invalid email or password."
            else:
                request.session["login_user"] = user
                context["success_msg"] = "Login successful."
                return redirect("AdminDash/")
    return HttpResponse(signup_html_page.render(context, request))
Exemplo n.º 11
0
    def transfer_account(client_id, account_id, account_id2):
        action = request.json['action']
        if action == 'transfer':
            try:
                ClientService.get_client_by_id(int(client_id))
                account = AccountService.get_account_by_id(int(account_id))
                account2 = AccountService.get_account_by_id(int(account_id2))

                AccountService.transfer_money(int(account_id),
                                              int(account_id2))
                return (
                    f'Successfully transferred! First Account new balance: {account.balance} Second Account new balance: {account2.balance}'
                ), 200

            except ResourceUnavailable as e:
                return e.message, 422
            except ResourceNotFound as r:
                return r.message, 404
Exemplo n.º 12
0
    def get_client_account_id(client_id, account_id):
        try:
            client_id = ClientService.get_client_by_id(int(client_id))
            account = AccountService.get_account_by_id(int(account_id))

            return jsonify(account.json()), 200
        except ValueError:
            return "Not a valid ID", 400  # Bad Request
        except ResourceNotFound as r:
            return r.message, 404
 def seller_actions(*args):
     connection = None
     status = {
         'action_id': args[0],
         'status_id': args[1],
         'seller_id': args[2]
     }
     user = g.token_info
     connection = connect_db()
     if connection:
         try:
             account_service = AccountService()
             account_service.change_status(status, user, connection)
             connection.commit()
             return jsonify({'status_actions': 'SUCCESS'}), 200
         except Exception as e:
             connection.rollback()
             return jsonify({'MESSAGE': f'{e}'}), 400
         finally:
             connection.close()
Exemplo n.º 14
0
    def patch_account(client_id, account_id):

        action = request.json['action']
        if action == 'deposit':
            try:
                ClientService.get_client_by_id(int(client_id))
                AccountService.get_account_by_id(int(account_id))

                balance = AccountService.deposit_account(int(account_id))
                return (
                    f'Successfully deposited! New balance is: {balance}'), 200
            except ResourceNotFound as r:
                return r.message, 404

        elif action == 'withdraw':
            try:
                balance = AccountService.withdraw_account(int(account_id))
                return (
                    f'Successfully withdrawn! New balance is: {balance}'), 200
            except ResourceUnavailable as e:
                return e.message, 422
            except ResourceNotFound as r:
                return r.message, 404
Exemplo n.º 15
0
def signin(request):
    signup_html_page = loader.get_template('../ui/index.html')
    context = {}
    if request.method == 'POST':
        email = request.POST["txtEmail"]
        password = request.POST["txtPassword"]
        if email == "*****@*****.**" and password == "12345678":
            request.session["login_user"] = email
            context["success_msg"] = "Login successful."
            return redirect("/account/admindash/index/")
        if not email:
            context["error_msg"] = "Invalid email or password."
        else:
            # ph = password_hash(password)
            account_service = AccountService()
            user = account_service.signin(email, password)
            if user is None:
                context["error_msg"] = "Invalid email or password."
            else:
                request.session["login_user"] = email
                context["success_msg"] = "Login successful."
                return redirect("/account/viewerdash/index/")
    return HttpResponse(signup_html_page.render(context, request))
    def edit_account(*args):
        connection = None
        change_info = {
            'email': args[0],
            'password': args[1],
            'account_type_id': args[2],
            'name': args[4],
            'id': args[5],
            'is_active': args[6]
        }

        connection = connect_db()
        user = g.token_info
        if connection:
            account_service = AccountService()
            try:
                change_account = account_service.change_account_info(change_info, user, connection)
                connection.commit()
                return change_account
            except Exception as e:
                connection.rollback()
                return jsonify({'MESSAGE': f'{e}'}), 400
            finally:
                connection.close()
Exemplo n.º 17
0
 def post_account(client_id):
     account = Account.json_parse(request.json)
     account.client_id = client_id
     account = AccountService.create_account(account)
     return jsonify(account.json()), 201
Exemplo n.º 18
0
 def get_all_account(client_id):
     try:
         ClientService.get_client_by_id(int(client_id))
         return jsonify(AccountService.all_accounts(client_id)), 200
     except ResourceNotFound as r:
         return r.message, 404
Exemplo n.º 19
0
 def get(self, id):
     return jsonify(AccountService().get_account_details(id))