コード例 #1
0
    def post(self):
        claims = get_jwt_claims()
        if claims['role'] != 'user':
            data = picture_schema.load(request.get_json())

            creator_id = get_jwt_identity()
            creator = VendorModule(id=creator_id).find_by_id()

            pic = PictureModule(creator_name=creator["username"], **data)

            pic.id = pic.get_maxium_pics

            trigger_data = {
                "id": pic.id,
                "title": pic.title,
                "creator_name": pic.creator_name,
                "status": pic.status,
                "price": pic.price,
                "category": pic.category,
                "admin_confirmation": pic.admin_confirmation,
                "created_at": pic.created_at,
                "artist": pic.artist
            }

            response_pic = picture_schema.dump(pic)
            pic_creation = pic.save_pic_to_db(response_pic, trigger_data)
        else:
            return {"msg": "Forbidden"}, 403
コード例 #2
0
 def get(self, artist):
     pic_list = []
     pic = PictureModule(artist=artist)
     pics = list(pic.find_by_artist_name())
     for pic in pics:
         pic_list.append(pic)
     return make_response(json_util.dumps(pic_list, ensure_ascii=False).encode('utf8'), 200)
コード例 #3
0
 def get(self):
     pic_list = []
     role = get_jwt_claims()['role']
     if role != 'user':
         vendor = VendorModule(id=get_jwt_identity())
         creator_name = vendor.find_by_id()['username']
         picObj = PictureModule(creator_name=creator_name)
         pics = list(picObj.find_by_creator_name())
         for pic in pics:
             pic_list.append(pic)
         return make_response(json_util.dumps(pic_list, ensure_ascii=False).encode('utf8'), 200)
     else:
         return {"msg": "Forbidden"}, 403
コード例 #4
0
    def post(self):
        reply_info = request.get_json()
        pic = PictureModule(id=reply_info["pic_id"])
        pic_data = pic.find_by_id()
        print(reply_info)
        reply_channel = "reply-channel_%s" % (reply_info["commenter_id"])
        print(reply_channel)
        reply_status = ReplyModule.create_reply(reply_info)

        notification = {
            "pic_id":reply_info["pic_id"],
            "pic_title": pic_data["title"],
            "created_at": reply_info["created_at"],
            "commenter_username": reply_info["username"],
            "pic_category": pic_data["category"]
        }

        NotificationModule.save_notification_to_db(notification)
        pusher.trigger(reply_channel,'reply', json_util.dumps(notification))
        return make_response(json_util.dumps(reply_info, ensure_ascii=False).encode('utf8'), 200) if reply_status else None
コード例 #5
0
    def post(self):
        cmt_data = request.get_json()

        _id = CommentModule.create_comment_id()

        pic = PictureModule(id=cmt_data["pic_id"])
        pic_data = pic.find_by_id()
        pic_title = pic_data["title"]
        pic_category = pic_data["category"]
        creator_name = cmt_data["creator_name"]
        creator = UserModule(username=creator_name)
        creator_id = creator.find_by_username()["id"]

        comment = {
            "id": _id,
            "username": cmt_data["username"],
            "pic_id": cmt_data["pic_id"],
            "content": cmt_data["content"],
            "user_id": cmt_data["user_id"],
            "star": cmt_data["star"],
            "avatarURL": cmt_data["avatarURL"]
        }

        notification = {
            "pic_id": cmt_data["pic_id"],
            "pic_title": pic_title,
            "created_at": cmt_data["created_at"],
            "commenter_username": cmt_data["username"],
            "creator_id": creator_id,
            "pic_category": pic_category
        }

        comment_channel = "comment-channel_%s" % (creator_id)
        status = CommentModule.create_comment(comment)
        NotificationModule.save_notification_to_db(notification)
        pusher.trigger(comment_channel, 'comment',
                       json_util.dumps(notification))
        return make_response(
            json_util.dumps(comment, ensure_ascii=False).encode('utf8'),
            200) if status else None
コード例 #6
0
 def put(self):
     claims = get_jwt_claims()
     creator_id = get_jwt_identity()
     if claims["role"] != 'user':
         data = picture_schema.load(request.get_json())
         creator = VendorModule(id=creator_id).find_by_id()
         picture = PictureModule(**data)
         picture.creator_name = creator['username']
         pic_resource = picture.find_by_id()
         if picture.imageURL == '':
             picture.imageURL = pic_resource['imageURL']
         result = picture_schema.dump(picture)
         picture.update_picture_to_db(result, creator['role'])
         return {"msg": "Updated successfully"}, 200
     else:
         return {"msg": "Forbidden"}, 403
コード例 #7
0
 def post(self):
     pic = PictureModule(id=request.get_json()["id"])
     return make_response(json_util.dumps(pic.find_by_id()), 200)
コード例 #8
0
 def get(self):
     pic_list = []
     pics = list(PictureModule.get_all_pics())
     for pic in pics:
         pic_list.append(pic)
     return make_response(json_util.dumps(pic_list, ensure_ascii=False).encode('utf8'), 200)