1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| class Setting(Args): def show_add_restaurant(self): fs.collection(Const.COL_USER).document(self.user_key).update({ Const.FIELD_STATE: Const.STATE_ADD_RESTAURANT }, firestore.CreateIfMissingOption(True))
rst = { "message": { "text": '음식점 이름을 입력해 주세요' } }
return Util.send_response(rst) def show_add_restaurant_desc(self): fs.collection(Const.COL_USER).document(self.user_key).update({ Const.FIELD_STATE: Const.STATE_ADD_RESTAURANT_DESC }, firestore.CreateIfMissingOption(True))
fs.collection(Const.COL_USER).document(self.user_key).update({ Const.FIELD_ADD_RESTAURANT_TITLE: self.content })
rst = { "message": { "text": '음식점 사진을 추가해 주세요' } }
return Util.send_response(rst) def show_add_restaurant_confirm(self): fs.collection(Const.COL_USER).document(self.user_key).update({ Const.FIELD_STATE: Const.STATE_ADD_RESTAURANT_CONFIRM }, firestore.CreateIfMissingOption(True))
fs.collection(Const.COL_USER).document(self.user_key).update({ Const.FIELD_ADD_RESTAURANT_DESC: self.content }, firestore.CreateIfMissingOption(True))
user = fs.collection(Const.COL_USER).document(self.user_key).get() title = user.get(Const.FIELD_ADD_RESTAURANT_TITLE) desc = self.content
if Util.is_img(desc): rst = { "message": { "text": '입력하신 음식점은 다음과 같습니다.\n\n이름:{}\n\n등록하시겠습니까?'.format(title), "photo": { "url": desc, "width": 640, "height": 480 } }, "keyboard": { "type": "buttons", "buttons": [ Const.BTN_ADD_RESTAURANT_CONFIRM, Const.BTN_GOTO_START ] } } else: rst = { "message": { "text": '입력하신 음식점은 다음과 같습니다.\n\n이름:{}\n설명:{}\n\n등록하시겠습니까?'.format(title, desc) }, "keyboard": { "type": "buttons", "buttons": [ Const.BTN_ADD_RESTAURANT_CONFIRM, Const.BTN_GOTO_START ] } }
return Util.send_response(rst) def add_restaurant(self): user = fs.collection(Const.COL_USER).document(self.user_key).get() group = user.get(Const.FIELD_GROUP) title = user.get(Const.FIELD_ADD_RESTAURANT_TITLE) desc = user.get(Const.FIELD_ADD_RESTAURANT_DESC)
try: ref = fs.collection(Const.COL_GROUP).document(group).get() restaurant = ref._data.get(Const.FIELD_RESTAURANT) except: restaurant = {}
if restaurant is None: restaurant = {}
restaurant[title] = { 'desc': desc, 'user': self.user_key, 'added': Util.get_day_str() }
if Util.is_img(desc): restaurant[title][Const.FIELD_IMG_SRC] = desc
fs.collection(Const.COL_GROUP).document(group).update({Const.FIELD_RESTAURANT: restaurant}, firestore.CreateIfMissingOption(True))
if Util.is_img(desc): msg = '[{}] 이(가) 등록되었습니다'.format(title) return Util.show_start_menu(msg, desc)
msg = '이름:{}\n설명:{}\n등록되었습니다'.format(title, desc) return Util.show_start_menu(msg)
|