def post(self): try: uuid = request.json['uuid'] title = request.json['title'] cate = request.json['cate'] loc = request.json['loc'] point = request.json['point'] main_img = request.json['main_img'] buy_time = request.json['buy_time'] permission = request.json['permission'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 if permission != 9: return {'msg': 'permission_denied'}, 403 query_insert_item_info = 'insert into item (uuid, title, cate, loc, point, main_img, buy_time, write_time) ' \ f"values ({uuid}, '{title}', '{cate}', '{loc}', {point}, '{main_img}', '{buy_time}', '{datetime.datetime.now().strftime('%Y-%m-%d')}')" curs.execute(query_insert_item_info) query_update_user_info = f'update user set point = point + {point} where uuid = {uuid}' curs.execute(query_update_user_info) conn.commit() return {'msg': 'success'}, 200
def get(self): try: address = request.args['address'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_select_user_uuid = 'select uuid, name from user where address = %s' curs.execute(query_select_user_uuid, address) users = curs.fetchall() if not users: return {'msg': 'not_found'}, 404 refined_info = {} cnt = 0 for user in users: query_select_item_info = 'select uuid, status, cate, title, main_img, price, desired_item, write_time ' \ 'from item where user = %s order by write_time desc' curs.execute(query_select_item_info, user['uuid']) items = curs.fetchall() for item in items: item['write_time'] = item['write_time'].strftime( '%Y-%m-%d:%H:%M:%S') item['name'] = user['name'] refined_info[cnt] = item cnt += 1 return refined_info, 200
def post(self): try: item_id = request.json['item_id'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_update_item_info = 'update item set status = 0 where item_id = %s' curs.execute(query_update_item_info, item_id) conn.commit() return {'msg': 'success'}, 200
def patch(self): try: uuid = request.json['uuid'] status = request.json['status'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_update_item_info = 'update item set status = %s where uuid = %s' curs.execute(query_update_item_info, (status, uuid)) conn.commit() return {'msg': 'success'}, 200
def get(self): try: item_uuid = request.args['uuid'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_select_item = 'select user as u, title, content, cate, main_img, price, desired_item, write_time ,' \ ' (select name, tell, zonecode, address from user where uuid = u) from item where uuid = %s' curs.execute(query_select_item, item_uuid) detail_item = curs.fetchone() refined_detail_item = detail_item return refined_detail_item, 200
def delete(self): identity = get_jwt_identity() try: uuid = request.json['uuid'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_delete_item_info = 'delete from item where user = %s and uuid = %s' curs.execute(query_delete_item_info, (identity['uuid'], uuid)) conn.commit() return {'msg': 'success'}, 200
def post(self): try: uuid = request.json['uuid'] item_id = request.json['item_id'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_select_user_info = 'select point from user where uuid = %s' curs.execute(query_select_user_info, uuid) point = curs.fetchone()['point'] query_select_item_info = 'select point from item where item_id = %s' curs.execute(query_select_item_info, item_id) item_point = curs.fetchone()['point'] if point < item_point: return {'msg': 'low_point'}, 403 query_update_user_point = 'update user set point = point - %s where uuid = %s' curs.execute(query_update_user_point, (item_point, uuid)) query_update_item_info = 'update item set status = %s where item_id = %s' curs.execute(query_update_item_info, (uuid, item_id)) conn.commit() return {'msg': 'success'}, 200
def post(self): try: tel = request.json['tel'] pw = request.json['pw'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_select_user_info = 'select uuid, permission from user where tel = %s and pw = %s' curs.execute(query_select_user_info, (tel, pw)) existing_user_info = curs.fetchone() if not existing_user_info: return {'msg': 'invalid_account'}, 401 return existing_user_info, 200
def patch(self): try: uuid = request.json['uuid'] pw = request.json['pw'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_select_user_info = 'select pw from user where uuid = %s and pw = %s' curs.execute(query_select_user_info, (uuid, pw)) if not curs.fetchone(): return {'msg': 'invalid_pw'}, 403 try: name = request.json['name'] except KeyError or TypeError: name = None try: change_pw = request.json['change_pw'] except KeyError or TypeError: change_pw = None try: profile_img = request.json['profile_img'] except KeyError or TypeError: profile_img = None if not name and not change_pw and not profile_img: return {'msg': 'invalid_request'}, 400 query_update_user_info = 'update user set ' if name: query_update_user_info += f"name = '{name}', " if change_pw: query_update_user_info += f"pw = '{change_pw}', " if profile_img: query_update_user_info += f"profile_img = '{profile_img}', " query_update_user_info = query_update_user_info[:-2] + ' where uuid = %s' curs.execute(query_update_user_info, uuid) conn.commit() return {'msg': 'success'}, 200
def get(self): try: title = request.args['title'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_select_item_info = 'select item_id, uuid as u, (select name from user where uuid = u), ' \ 'title, cate, loc, main_img, buy_time, write_time, status, point' \ f" from item where title like '%{title}%' or cate like '%{title}%' order by item_id desc" curs.execute(query_select_item_info) item_infos = curs.fetchall() refined_info = {} cnt = 0 for item_info in item_infos: refined_info[cnt] = item_info cnt += 1 return refined_info
def post(self): try: tell = request.json['tell'] pw = request.json['pw'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_select_user_info = 'select tell, pw, uuid from user where tell = %s and pw = %s' curs.execute(query_select_user_info, (tell, pw)) existing_user_info = curs.fetchone() if not existing_user_info: return {'msg': 'invalid_info'}, 401 identity = {'uuid': existing_user_info['uuid']} return { 'access_token': create_access_token(identity=identity), 'refresh_token': create_refresh_token(identity=identity) }, 200
def post(self): try: tel = request.json['tel'] pw = request.json['pw'] name = request.json['name'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_select_user_info = 'select uuid from user where tel = %s' curs.execute(query_select_user_info, tel) existing_user = curs.fetchone() if existing_user: return {'msg': 'existing_user'}, 403 query_insert_user_info = 'insert into user (tel, pw, name, profile_img) values(%s, %s, %s, %s)' curs.execute(query_insert_user_info, (tel, pw, name, BASIC_PROFILE_IMAGE)) conn.commit() return {'msg': 'success'}, 200
def post(self): try: permission = request.json['permission'] item_id = request.json['item_id'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 if permission != 9: return {'msg': 'permission_denied'}, 403 query_select_item_info = 'select point, status from item where item_id = %s' curs.execute(query_select_item_info, item_id) item_infos = curs.fetchone() point = item_infos['point'] uuid = item_infos['status'] if uuid == 0 or uuid == -1: return {'msg': 'invalid_access'}, 403 query_select_user_info = 'select point from user where uuid = %s' curs.execute(query_select_user_info, uuid) existing_point = curs.fetchone()['point'] if point > existing_point: return {'msg': 'low_point'}, 403 query_update_item_info = 'update item set status = -1 where item_id = %s' curs.execute(query_update_item_info, item_id) conn.commit() return {'msg': 'success'}, 200
def get(self): try: uuid = request.args['uuid'] except KeyError or TypeError: return {'msg': 'valueless'}, 400 query_select_user_info = 'select tel, name, profile_img, point from user where uuid = %s' curs.execute(query_select_user_info, uuid) user_info = curs.fetchone() query_select_item_info = 'select title, main_img, item_id, write_time from item where status = %s' curs.execute(query_select_item_info, uuid) item_infos = curs.fetchall() refined_item_infos = {} cnt = 0 for item_info in item_infos: refined_item_infos[cnt] = item_info cnt += 1 return {'user_info': user_info, 'list': refined_item_infos}
def post(self): try: tell = request.json['tell'] pw = request.json['pw'] name = request.json['name'] email = request.json['email'] permission = request.json['permission'] zone_code = request.json['zone_code'] address = request.json['address'] detail_address = request.json['detail_address'] profile_img = BASIC_PROFILE_IMAGE except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_insert_user_info = 'insert into user (tell, pw, name, email, permission, zonecode, address, detailaddress, profileimg)' \ ' values (%s, %s, %s, %s, %s, %s, %s, %s, %s)' curs.execute(query_insert_user_info, (tell, pw, name, email, permission, zone_code, address, detail_address, profile_img)) conn.commit() return {'msg': 'success'}, 200
def get(self): identity = get_jwt_identity() query_select_user_info = 'select tell, name, email, zonecode, address, detailaddress from user where uuid = %s' curs.execute(query_select_user_info, identity['uuid']) existing_user_info = curs.fetchone() query_select_item_info = 'select uuid, status, cate, title, main_img, desired_item, write_time ' \ 'from item where user = %s order by write_time desc' curs.execute(query_select_item_info, identity['uuid']) items = curs.fetchall() item_info = {} cnt = 0 for item in items: item['write_time'] = item['write_time'].strftime( '%Y-%m-%d:%H:%M:%S') item_info[cnt] = item cnt += 1 return {'user': existing_user_info, 'item': item_info}
def post(self): try: tell = request.json['tell'] email = request.json['email'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_select_user_info = 'select tell from user where tell = %s' curs.execute(query_select_user_info, tell) existing_user_tell = curs.fetchone() if existing_user_tell: return {'msg': 'existing_telephone'}, 406 query_select_user_info = 'select email from user where email = %s' curs.execute(query_select_user_info, email) existing_user_email = curs.fetchone() if existing_user_email: return {'msg': 'existing_email'}, 406 smtp_connect = smtplib.SMTP('smtp.gmail.com', 587) smtp_connect.starttls() smtp_connect.login('*****@*****.**', 'epzuyfapmvrvxfib') cert_num = '' for i in range(6): cert_num += str(random.randrange(0, 10)) msg = MIMEText(f'인증번호 : {cert_num}\n인증번호는 10분이 지나면 만료됩니다.') msg['Subject'] = 'RE:MARKET에서 발송한 인증번호입니다.' smtp_connect.sendmail('*****@*****.**', email, msg.as_string())\ smtp_connect.quit() return { 'cert_num': cert_num, 'timestamp': datetime.now().timestamp() }, 200
def post(self): try: title = request.json['title'] content = request.json['content'] main_img = request.json['main_img'] price = request.json['price'] cate = request.json['cate'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 try: desired_item = request.json['desired_item'] except KeyError or TypeError: desired_item = None identity = get_jwt_identity() query_insert_item = 'insert into item (user, title, content, cate, main_img, price, desired_item, write_time)' \ ' values (%s, %s, %s, %s, %s, %s, %s, now())' curs.execute(query_insert_item, (identity['uuid'], title, content, cate, main_img, price, desired_item)) conn.commit() return {'msg': 'success'}, 200
def patch(self): identity = get_jwt_identity() try: pw = request.json['pw'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 try: change_pw = request.json['change_pw'] except KeyError or TypeError: change_pw = None try: name = request.json['name'] except KeyError or TypeError: name = None try: profile_img = request.json['profile_img'] except KeyError or TypeError: profile_img = None query_select_info = 'select pw from user where pw = %s' curs.execute(query_select_info, pw) present_pw = curs.fetchone() if not present_pw: return {'msg': 'pw_incorrect'}, 401 if change_pw: query_update_info = 'update user set pw = %s where uuid = %s' curs.execute(query_update_info, (change_pw, identity['uuid'])) if name: query_update_info = 'update user set name = %s where uuid = %s' curs.execute(query_update_info, (name, identity['uuid'])) if profile_img: query_update_info = 'update user set profileimg = %s where uuid = %s' curs.execute(query_update_info, (profile_img, identity['uuid'])) conn.commit() return {'msg': 'success'}, 200
def delete(self): identity = get_jwt_identity() try: pw = request.json['pw'] except KeyError or TypeError: return {'msg': 'value_skipped'}, 400 query_select_user_info = 'select pw from user where pw = %s' curs.execute(query_select_user_info, pw) existing_password = curs.fetchone() if not existing_password: return {'msg': 'invalid_pw'}, 401 query_delete_user_info = 'delete from user where uuid = %s' curs.execute(query_delete_user_info, identity['uuid']) query_delete_item_info = 'delete from item where user = %s' curs.execute(query_delete_item_info, identity['uuid']) conn.commit() return {'msg': 'bye'}, 200