Пример #1
0
    def get(self):
        post_id = request.args.get("post-id", None)
        username = request.args.get("username", None)
        page = request.args.get("page", default=1, type=int)
        per_page = request.args.get("per-page", default=20, type=int)

        if post_id is not None and username is not None:
            abort(
                400,
                "post_id and username cant be given together, u must give one of both"
            )
        elif post_id is None and username is None:
            abort(400, "Parameter missed")

        post = None
        user = None

        if post_id:
            post = PostService.get_post_by_post_id(post_id)
        if username:
            user = UserService.get_user_by_username(username)

        paged_comments = CommentListService.get_paginated_comments(
            post=post, user=user, page=page, per_page=per_page)

        return {
            "comments": comments_schema.dump(paged_comments.items),
            "number_of_pages": paged_comments.pages,
        }, 200
Пример #2
0
    def delete(self, username):
        RequestValidator.validate_request(DeleteUserSchema(), request.json)

        user = UserService.get_user_by_username(username)
        password = request.json.get("password")

        UserService.raise_401_if_not_password_verified(user, password=password)
        user.delete_user()

        return {}, 200
Пример #3
0
    def put(self, username):
        RequestValidator.validate_request(AccountChangePasswordInputSchema(),
                                          request.json)

        json = request.json
        user = UserService.get_user_by_username(username)
        password = json["password"]
        new_password = json["new_password"]

        UserService.raise_401_if_not_password_verified(user, password)
        AccountService.change_account_password(user, new_password)

        return {}, 200
Пример #4
0
    def put(self, username):
        user = UserService.get_user_by_username(username)
        json = request.json

        RequestValidator.validate_request(UserPutInputSchema(), json)
        AccountService.check_exist_same_username(json["username"])

        UserService.update_user(
            user=user,
            username=json["username"],
            explain=json["user_explain"],
            email=user.email,
            profile_image=user.profile_image,
            password_hash=user.password_hash,
        )

        return {}, 200
Пример #5
0
    def get(self):
        RequestValidator.validate_request(
            PostGetQueryParameterValidateSchema(), request.args)

        gallery_id = request.args.get(key="gallery-id", default=None, type=str)
        username = request.args.get(key="username", default=None, type=str)
        page = request.args.get(key="page", default=1, type=int)
        per_page = request.args.get(key="per-page", default=20, type=int)

        gallery = GalleryService.get_gallery_by_id(
            gallery_id) if gallery_id else None
        user = UserService.get_user_by_username(username) if username else None

        paged_posts = PostListService.get_paginated_posts(gallery=gallery,
                                                          user=user,
                                                          page=page,
                                                          per_page=per_page)

        return {
            "posts": posts_schema.dump(paged_posts.items),
            "number_of_pages": paged_posts.pages,
        }, 200
Пример #6
0
 def get(self, username):
     return (
         user_schema.dump(UserService.get_user_by_username(username)),
         200,
     )
Пример #7
0
 def get(self, username):
     user = UserService.get_user_by_username(username)
     return account_schema.dump(user), 200