diff --git a/api-documentation.md b/api-documentation.md index 55ef95f..8bd5b1d 100644 --- a/api-documentation.md +++ b/api-documentation.md @@ -898,11 +898,7 @@ response code will be **422** method: `GET` -*input*: - -Authorization Header: - -- Bearer \ +*input*: **None** *output*: @@ -955,10 +951,6 @@ method: `GET` pass query parametr in URL -Authorization Header: - -- Bearer \ - *output*: response code will be **200** @@ -969,7 +961,6 @@ response code will be **200** "author_fullname": "Mohammad Hossein Malekpour", "category": "recepie", "content": "who konws!", - "current_user_mail": "mohammadhossein.malekpour@gmail.com", "post_id": 2, "slug": "avaliwern-post-dailywrdiet", "summary": "pooof", @@ -1072,3 +1063,54 @@ response code will be **403** ``` ---------- + +### `/blog/posts/user` + +method: `GET` + +*input*: + +Authorization Header: + +- Bearer \ + +*output*: + +response code will be **200** + +```json +{ + "2": { + "author_email": "mohammadhossein.malekpour@gmail.com", + "author_fullname": "Mohammad Hossein Malekpour", + "category": "recepie", + "content": "who konws!", + "current_user_mail": "mohammadhossein.malekpour@gmail.com", + "slug": "avaliwern-post-dailywrdiet", + "summary": "pooof", + "title": "How To Get Diet?" + }, + "3": { + "author_email": "mohammadhossein.malekpour@gmail.com", + "author_fullname": "Mohammad Hossein Malekpour", + "category": "recepie", + "content": "who konws!", + "current_user_mail": "mohammadhossein.malekpour@gmail.com", + "slug": "dovomi-post-dailywrdiet", + "summary": "pooof", + "title": "How Toqwewe Get Diet?" + }, + "4": { + "author_email": "mohammadhossein.malekpour@gmail.com", + "author_fullname": "Mohammad Hossein Malekpour", + "category": "recepie", + "content": "who konws!", + "current_user_mail": "mohammadhossein.malekpour@gmail.com", + "slug": "dovomi-post-daasdilywrdiet", + "summary": "pooof", + "title": "How Toqwewdasde Get Diet?" + } +} +``` + +---------- diff --git a/blog/views.py b/blog/views.py index 01a00fe..68a9f1e 100644 --- a/blog/views.py +++ b/blog/views.py @@ -11,7 +11,6 @@ @blog.route('/', methods=['GET']) -@jwt_required def list_posts(): posts = Post.query.order_by(Post.id.desc()).all() result = dict() @@ -20,18 +19,33 @@ def list_posts(): tmp['id'] = p.id slug = p.slug.replace(' ', '-') print(p.writer.FullName) - tmp = {'slug': slug, 'title': p.title, 'summary': p.summary, 'content': p.content, 'category': p.category, 'author_fullname': p.writer.FullName, 'author_email': p.writer.Email, 'current_user_mail': get_jwt_identity()} + tmp = {'slug': slug, 'title': p.title, 'summary': p.summary, 'content': p.content, 'category': p.category, 'author_fullname': p.writer.FullName, 'author_email': p.writer.Email} result.update({f'{p.id}': tmp}) return jsonify(result), 200 @blog.route('/', methods=['GET']) -@jwt_required def single_post(slug): post = Post.query.filter(Post.slug == slug).first() if not post: return {'error': 'post not exist!'}, 404 - result = {'post_id':post.id, 'slug': post.slug, 'title': post.title, 'summary': post.summary, 'content': post.content, 'category': post.category, 'author_fullname': post.writer.FullName, 'author_email': post.writer.Email, 'current_user_mail': get_jwt_identity()} + result = {'post_id':post.id, 'slug': post.slug, 'title': post.title, 'summary': post.summary, 'content': post.content, 'category': post.category, 'author_fullname': post.writer.FullName, 'author_email': post.writer.Email} + return jsonify(result), 200 + + +@blog.route('/posts/user', methods=['GET']) +@jwt_required +def get_user_posts(): + ID = User.query.filter_by(Email=get_jwt_identity()).first().id + posts = Post.query.filter(Post.authorId == ID).all() + result = dict() + for p in posts: + tmp = dict() + tmp['id'] = p.id + slug = p.slug.replace(' ', '-') + print(p.writer.FullName) + tmp = {'slug': slug, 'title': p.title, 'summary': p.summary, 'content': p.content, 'category': p.category, 'author_fullname': p.writer.FullName, 'author_email': p.writer.Email, 'current_user_mail': get_jwt_identity()} + result.update({f'{p.id}': tmp}) return jsonify(result), 200 diff --git a/requirements.txt b/requirements.txt index 9c5a42e..7793e2c 100644 Binary files a/requirements.txt and b/requirements.txt differ