def put(): """ 서버에서 해당 ID 의 새로운 유저 정보를 받아온다. 정보를 토대로 해당 ID 유저의 정보를 바꿔서 정보를 서버에 보내준다. parameter: 유저 아이디를 받아온다 return: 새로운 유저 데이터를 리턴 한다 """ # 유저이름 혹은 주문번호에 대한 주문 정보 수정 parser.add_argument('order_no', type=str, required=True, help='This is order_no field') parser.add_argument('user_id', type=str, required=True, help='This is user_id field') parser.add_argument('cheese_id', type=str, required=True, help='This is cheese_id field') parser.add_argument('buy_count', type=str, required=True, help='This is buy_count field') parser.add_argument('total_price', type=str, required=True, help='This is total_price field') print("argument added") # def __init__(self, user_id, password,fname, lname, age, gender,email): args = parser.parse_args() # print(f'User {args["user_id"]} updated') # print(f'User {args["password"]} updated') # user = OrderDto(args.user_id, args.password, args.gender, args.age_group) user = OrderDto(args.order_no, args.user_id, args.cheese_id, args.buy_count, args.total_price) print("user created") OrderDao.update(args) data = user.json() return data, 200
def post(): print(f'[User Signup Resource Enter]') body = request.get_json() user = OrderDto(**body) OrderDao.save(user) user_id = user.user_id return {'user_id': str(user_id)}, 200
def post(): print(f'[ ========= Orders POST() ========= ]') order_count = OrderDao.count() if order_count[0] == 0: OrderDao.bulk() else: print("Orders Data exists...")
def post(): print(f' =========== Order POST()!!! =========== \n') body = request.get_json() order = OrderDto(**body) OrderDao.save(order) # user_id = order.user_id order_no = order.order_no # return {'user_id': str(user_id)}, 200 return {'order_no': str(order_no)}, 200
def delete(): """ 주문번호에 맞는 데이터를 삭제한다. Parameter: 파라미터 """ # UserDao.delete(id) # print(f'User {id} Deleted') print(f'[ ========= Order DELETE() ========= ]') args = parser.parse_args() parmas = json.loads(request.get_data(), encoding='utf-8') OrderDao.delete(parmas['order_no']) # print(f'User {args["user_id"]} deleted') print(f'\n=======Order delete!!') return {'code': 0, 'message': 'SUCCESS'}, 200
def put(user_id: str): """ 서버에서 해당 ID 의 새로운 유저 정보를 받아온다. 정보를 토대로 해당 ID 유저의 정보를 바꿔서 정보를 서버에 보내준다. parameter: 유저 아이디를 받아온다 return: 새로운 유저 데이터를 리턴 한다 """ parser = reqparse.RequestParser( ) # only allow price changes, no name changes allowed parser.add_argument('user_id', type=str, required=True, help='This field should be a user_id') parser.add_argument('password', type=str, required=True, help='This field should be a password') parser.add_argument('gender', type=str, required=True, help='This field should be a gender') parser.add_argument('age_group', type=str, required=True, help='This field should be a age_group') print("argument added") # def __init__(self, user_id, password,fname, lname, age, gender,email): args = parser.parse_args() print(f'User {args["user_id"]} updated') print(f'User {args["password"]} updated') user = OrderDto( args.user_id, args.password, args.gender, args.age_group, ) print("user created") OrderDao.update(user) data = user.json() return data, 200
def get(): print("best.py, AgeBest GET()") # print(f'성별: {gender}') # print(f'나이: {age}') # print(f'치즈 카테고리: {cheese_category}') # print(f'치즈 이름: {cheese_name}') best = OrderDao.find_cheese_by_age_count() print(f'Age Best List : {best}') print(type(best)) print(f'Age Best json : {jsonify(best)}') # itemList = [] # for item in best: # print(f'for문 결과: ', item) # itemList.append(item) # print(f'Best List : {itemList}') # print(type(itemList)) # return jsonify([item.json for item in best]) return jsonify(best) # class OrderBest(Resource): # @staticmethod # def get(): # print("best.py, OrderBest GET()") # # print(f'성별: {gender}') # # print(f'나이: {age}') # # print(f'치즈 카테고리: {cheese_category}') # # print(f'치즈 이름: {cheese_name}') # best = OrderDao.find_cheese_by_gender_count() # print(f'Best List : {best}') # print(type(best)) # print(f'Best json : {jsonify(best)}') # # itemList = [] # # for item in best: # # print(f'for문 결과: ', item) # # itemList.append(item) # # print(f'Best List : {itemList}') # # print(type(itemList)) # # return jsonify([item.json for item in best]) # return jsonify(best)
def get(user_id: str): """ 유저 아이디를 받아와 해당 유저 객채를 리턴한다 Parameter: User ID 를 받아온다 return: 해당 아이디 유저 객체 """ print('===========user_id=============') print(user_id) try: print(f'User ID is {user_id}') user = OrderDao.find_by_id(user_id) if user: # return jsonify([user.json]) return jsonify([item.json for item in user]) except Exception as e: print(e) return {'message': 'User not found'}, 404
def get(): print("best.py, GenderBest GET()") # print(f'성별: {gender}') # print(f'나이: {age}') # print(f'치즈 카테고리: {cheese_category}') # print(f'치즈 이름: {cheese_name}') best = OrderDao.find_cheese_by_gender_count() print(f'Gender Best List : {best}') print(type(best)) print(f'Gender Best json : {jsonify(best)}') # itemList = [] # for item in best: # print(f'for문 결과: ', item) # itemList.append(item) # print(f'Best List : {itemList}') # print(type(itemList)) # return jsonify([item.json for item in best]) return jsonify(best)
def get(user_id): print("SEARCH 진입") print(f'User ID: {user_id}') order = OrderDao.find_by_id(user_id) print(f'order data: {order}') print(type(order)) # print(f'order jsonify : {json.dumps(order.json)}') # orderlist = [] # for lis in order: # orderlist.append(lis) # print(f'Review List : {orderlist}') # print(type(orderlist)) # return jsonify(order.json) # return jsonify([item.json for item in orderlist]) # return jsonify(order.json()) # for item in order: # print(item.json) return jsonify([item.json for item in order])
def get(user_id: str): """ 유저 아이디를 받아와 해당 유저 객체를 리턴한다 Parameter: User ID 를 받아온다 return: 해당 아이디 유저 객체 """ print('===========user_id=============') print(user_id) try: print(f'User ID is {user_id}') user = OrderDao.find_by_id(user_id) if user: print(f'======= user =======\n{user}\n') # return jsonify([user.json()]) print('===============') # print(user.json()) return jsonify([item.json() for item in user]) ''' [ { "buy_count": 1, "cheese_id": "p8", "order_no": 2, "total_price": 4600, "user_id": "1799897" } ] ''' # return jsonify([user.json]) # return json.dumps(user.json()) # return {'order': list(map(lambda order: order.json(), OrderDao.find_by_id))} except Exception as e: print(e) return {'message': 'User GET() Error!!'}, 404
def get(): print(f'[ ========= Orders GET() ========= ]') data = OrderDao.find_all() print(f'type========= {type(data)}') return jsonify([item.json for item in data])
# cheese_find_one = CheeseDao.find_by_cheese(cheese_id) # print(f'===== Cheese find one {cheese_find_one} =====') # cheese_all = CheeseDao.find_all() # print(f'========Cheese all {cheese_all} ==========') print(f'==========Cheeses Data Insert!!!==========') print(f'===== Cheeses Total Count is {cheese_count} =====') if cheese_count[0] == 0: CheeseDao.bulk() else: print("Cheeses Data exists...") # ================================= Order ================================= print(f'==========Orders Data Insert!!!==========') order_count = OrderDao.count() if order_count[0] == 0: OrderDao.bulk() else: print("Orders Data exists...") # ================================= Review ================================= print(f'==========Reviews Data Insert!!!==========') review_count = ReviewDao.count() if review_count[0] == 0: ReviewDao.bulk() else: print("Reviews Data exists...")
def get(): print(f'[ User List Resource Enter ]') data = OrderDao.find_all() return jsonify([item.json for item in data])
def post(): print(f'[ User Bulk Resource Enter ]') OrderDao.bulk()