Delete metadata.jsonl
Browse files- metadata.jsonl +0 -59
metadata.jsonl
DELETED
@@ -1,59 +0,0 @@
|
|
1 |
-
{"file_name": "94977984-81b4-474d-8739-ae37897c0939.png", "code": "def create_like(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = Like(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id\r\n )\r\n db.add(like)\r\n db.commit()\r\n db.refresh(like)\r\n return like"}
|
2 |
-
{"file_name": "66166aa0-8b0e-4ea6-b35c-942dd167fe09.png", "code": "def create_like(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = Like(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id\r\n )\r\n db.add(like)\r\n db.commit()\r\n db.refresh(like)\r\n return like"}
|
3 |
-
{"file_name": "214cccaa-a48a-458c-9143-1808d6214029.png", "code": "def create_like(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = Like(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id\r\n )\r\n db.add(like)\r\n db.commit()\r\n db.refresh(like)\r\n return like"}
|
4 |
-
{"file_name": "d895922a-a590-4ce0-9306-5bceaadcb047.png", "code": "def create_like(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = Like(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id\r\n )\r\n db.add(like)\r\n db.commit()\r\n db.refresh(like)\r\n return like"}
|
5 |
-
{"file_name": "35862378-8b62-40c0-832c-3b91946265ab.png", "code": "def create_like(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = Like(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id\r\n )\r\n db.add(like)\r\n db.commit()\r\n db.refresh(like)\r\n return like"}
|
6 |
-
{"file_name": "6117b2bb-fd83-46e1-a589-703b0f419eaa.png", "code": "def delete_like(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = db.query(Like).filter(Like.author_id==activity.user_id, Like.post_id==activity.post_id).first()\r\n db.delete(like)\r\n db.commit()\r\n return like\r\n\r\ndef has_liked(session: Session, activity: CreateActivity) -> Like:\r\n with session() as db:\r\n like: Like = db.query(Like).filter(Like.author_id==activity.user_id, Like.post_id==activity.post_id).first()\r\n if like:\r\n return True\r\n return False"}
|
7 |
-
{"file_name": "6b4ff6ca-456c-478b-94f4-d0b8f23ed2ad.png", "code": "def list_user_likes(session: Session, user_data: GetUser) -> list[Like]:\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == user_data.user_id).first()\r\n likes: list[Like] = user.likes\r\n return likes\r\n\r\ndef list_post_likes(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post: Post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n likes: list[Like] = post.likes\r\n for like in likes:\r\n like.author\r\n return likes\r\n\r\ndef get_key_like(session: Session, post_data: GetPost):\r\n from random import choice\r\n with session() as db:\r\n post: Post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n likes: list[Like] = post.likes\r\n for like in likes:\r\n like.author\r\n return choice(likes).author if likes else None"}
|
8 |
-
{"file_name": "4d14a5de-ff1a-4a7e-8c0d-659dcb31d750.png", "code": "def list_user_likes(session: Session, user_data: GetUser) -> list[Like]:\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == user_data.user_id).first()\r\n likes: list[Like] = user.likes\r\n return likes\r\n\r\ndef list_post_likes(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post: Post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n likes: list[Like] = post.likes\r\n for like in likes:\r\n like.author\r\n return likes\r\n\r\ndef get_key_like(session: Session, post_data: GetPost):\r\n from random import choice\r\n with session() as db:\r\n post: Post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n likes: list[Like] = post.likes\r\n for like in likes:\r\n like.author\r\n return choice(likes).author if likes else None"}
|
9 |
-
{"file_name": "20caf41f-9ce4-4875-a023-aee89b324ea0.png", "code": "from sqlalchemy.orm import Session\r\nfrom ..models.post import Post\r\nfrom ..schemas.post import (\r\n CreatePost, GetPosts, GetPost, UpdatePost\r\n)\r\nfrom werkzeug.datastructures import FileStorage\r\nfrom flask import current_app\r\nfrom uuid import uuid4\r\nfrom werkzeug.utils import secure_filename\r\nimport os\r\nimport secrets\r\nfrom typing import Callable"}
|
10 |
-
{"file_name": "ea28d015-0623-4cea-a437-a5b2af247dbb.png", "code": "ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}\r\n\r\ndef get_file_extension(filename: str) -> str:\r\n if '.' in filename and filename.rsplit('.', 1)[1].lower():\r\n return filename.rsplit('.', 1)[1].lower()\r\n return ''\r\n\r\ndef allowed_file(filename: str) -> bool:\r\n file_extension: str = get_file_extension(filename)\r\n if file_extension and file_extension in ALLOWED_EXTENSIONS:\r\n return True\r\n return False\r\n\r\n\r\ndef save_post_photo_locally(post_image: dict) -> None:\r\n \"\"\"Save the uploadeded post image.\"\"\"\r\n file: FileStorage = post_image['post_image']\r\n upload_folder = os.path.join(current_app.root_path, 'static', 'img')\r\n if file and allowed_file(file.filename):\r\n filename = f'{secrets.token_hex(8)}.{get_file_extension(file.filename)}' \r\n # Use celery task\r\n file.save(os.path.join(upload_folder, filename))\r\n return filename\r\n return ''"}
|
11 |
-
{"file_name": "c9adde79-584b-47ba-ae7c-91f2a12ee0cb.png", "code": "def save_post_photo_aws_s3(post_image: dict) -> None:\r\n \"\"\"Save the uploadeded post image.\"\"\"\r\n file: FileStorage = post_image['post_image']\r\n if file and allowed_file(file.filename):\r\n filename = f'{secrets.token_hex(8)}.{get_file_extension(file.filename)}'\r\n # Use celery task\r\n return filename\r\n return ''\r\n\r\ndef no_save_post_photo(post_image: dict) -> None:\r\n \"\"\"Save the uploadeded post image.\"\"\"\r\n file: FileStorage = post_image['post_image']\r\n if file and allowed_file(file.filename):\r\n filename = f'{secrets.token_hex(8)}.{get_file_extension(file.filename)}'\r\n return filename\r\n return ''\r\n\r\n\r\ndef save_post_photo(post_image: dict, save_location: str = '') -> str:\r\n \"\"\"Save the uploadeded post image.\"\"\"\r\n save_photo_funcs: dict[str, Callable[[dict], str]] = {\r\n 'locally': save_post_photo_locally,\r\n 'aws_s3': save_post_photo_aws_s3,\r\n 'default': no_save_post_photo\r\n }\r\n if save_photo_funcs.get(save_location):\r\n filename: str = save_photo_funcs[save_location](post_image)\r\n else:\r\n filename: str = save_photo_funcs['default'](post_image)\r\n return filename"}
|
12 |
-
{"file_name": "b344b10d-8a13-46e1-ae86-5bdf5fae917f.png", "code": "def create_post(post_data: CreatePost, post_image: dict, session: Session):\r\n post_image_url: str = save_post_photo(post_image)\r\n post: Post = Post(\r\n id='Post_' + str(uuid4()),\r\n author_id=post_data.author_id,\r\n location=post_data.location,\r\n text=post_data.text,\r\n image_url=post_image_url\r\n )\r\n with session() as db:\r\n db.add(post)\r\n db.commit()\r\n db.refresh(post)\r\n return post"}
|
13 |
-
{"file_name": "889441e8-6314-4628-b0c0-f6e3115f951a.png", "code": "def create_post(post_data: CreatePost, post_image: dict, session: Session):\r\n post_image_url: str = save_post_photo(post_image)\r\n post: Post = Post(\r\n id='Post_' + str(uuid4()),\r\n author_id=post_data.author_id,\r\n location=post_data.location,\r\n text=post_data.text,\r\n image_url=post_image_url\r\n )\r\n with session() as db:\r\n db.add(post)\r\n db.commit()\r\n db.refresh(post)\r\n return post"}
|
14 |
-
{"file_name": "a4f6995c-8ab2-400a-bbdb-5cc6757d638d.png", "code": "def create_post(post_data: CreatePost, post_image: dict, session: Session):\r\n post_image_url: str = save_post_photo(post_image)\r\n post: Post = Post(\r\n id='Post_' + str(uuid4()),\r\n author_id=post_data.author_id,\r\n location=post_data.location,\r\n text=post_data.text,\r\n image_url=post_image_url\r\n )\r\n with session() as db:\r\n db.add(post)\r\n db.commit()\r\n db.refresh(post)\r\n return post"}
|
15 |
-
{"file_name": "b0558326-bfc4-4a67-8f1f-783c927f87ba.png", "code": "def create_post(post_data: CreatePost, post_image: dict, session: Session):\r\n post_image_url: str = save_post_photo(post_image)\r\n post: Post = Post(\r\n id='Post_' + str(uuid4()),\r\n author_id=post_data.author_id,\r\n location=post_data.location,\r\n text=post_data.text,\r\n image_url=post_image_url\r\n )\r\n with session() as db:\r\n db.add(post)\r\n db.commit()\r\n db.refresh(post)\r\n return post"}
|
16 |
-
{"file_name": "2a9a7201-5c02-448e-af76-4ca708d67d23.png", "code": "def create_post(post_data: CreatePost, post_image: dict, session: Session):\r\n post_image_url: str = save_post_photo(post_image)\r\n post: Post = Post(\r\n id='Post_' + str(uuid4()),\r\n author_id=post_data.author_id,\r\n location=post_data.location,\r\n text=post_data.text,\r\n image_url=post_image_url\r\n )\r\n with session() as db:\r\n db.add(post)\r\n db.commit()\r\n db.refresh(post)\r\n return post"}
|
17 |
-
{"file_name": "f010a565-b8f6-4a0c-ad90-7a50eb13c249.png", "code": "def update_post(post_data: UpdatePost, post_image: dict, session: Session):\r\n post_image_url: str = save_post_photo(post_image)\r\n with session() as db:\r\n post: Post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n if post_data.location:\r\n post.location = post_data.location\r\n if post_data.text:\r\n post.text = post_data.text\r\n if post_image_url:\r\n post.image_url = post_image_url\r\n db.commit()\r\n db.refresh(post)\r\n return post\r\n\r\ndef get_post(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n return post"}
|
18 |
-
{"file_name": "3668a7ea-5d72-42a8-b26c-bafba9f327cd.png", "code": "def get_posts(session: Session, post_data: GetPosts):\r\n with session() as db:\r\n posts: list[Post] = db.query(Post).offset(post_data.offset).limit(post_data.limit).all()\r\n for post in posts:\r\n post.author\r\n return posts\r\n\r\ndef delete_post(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n db.delete(post)\r\n db.commit()\r\n \r\n return post"}
|
19 |
-
{"file_name": "8bd9a171-5d31-41c0-8963-c49cda7ee71d.png", "code": "def get_posts(session: Session, post_data: GetPosts):\r\n with session() as db:\r\n posts: list[Post] = db.query(Post).offset(post_data.offset).limit(post_data.limit).all()\r\n for post in posts:\r\n post.author\r\n return posts\r\n\r\ndef delete_post(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n db.delete(post)\r\n db.commit()\r\n \r\n return post"}
|
20 |
-
{"file_name": "edba516f-516e-41d9-9d2f-7c788785b717.png", "code": "def get_posts(session: Session, post_data: GetPosts):\r\n with session() as db:\r\n posts: list[Post] = db.query(Post).offset(post_data.offset).limit(post_data.limit).all()\r\n for post in posts:\r\n post.author\r\n return posts\r\n\r\ndef delete_post(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n db.delete(post)\r\n db.commit()\r\n \r\n return post"}
|
21 |
-
{"file_name": "8a7cc60c-3f28-4fb6-81d6-535d7cdde5df.png", "code": "from ..schemas.user import UserCreate\r\nfrom sqlalchemy.orm import Session\r\nfrom ....extensions.extensions import bcrypt\r\nfrom ..models.user import User\r\nfrom ..schemas.user import User as Userschemas\r\nfrom ..schemas.user import (\r\n GetUser, GetUsers, ActivateUser, LoginUser, RequestPasswordReset, PasswordReset\r\n)\r\nfrom typing import Optional\r\nfrom jwt import ExpiredSignatureError, InvalidTokenError\r\nfrom uuid import uuid4\r\nfrom typing import Callable"}
|
22 |
-
{"file_name": "14f6a2a5-e984-4021-9f59-ec8bcd7d5ebd.png", "code": "def send_email_local(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef send_email_aws_ses(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef send_account_activation_email(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef send_password_reset_email(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef generate_account_activation_email(message: str) -> None:\r\n pass\r\n\r\ndef generate_password_reset_email(message: str) -> None:\r\n pass"}
|
23 |
-
{"file_name": "c6b7a3b6-1baf-44ea-888b-885f79aa62c8.png", "code": "def send_email_local(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef send_email_aws_ses(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef send_account_activation_email(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef send_password_reset_email(user_email_address: str, message: str) -> None:\r\n pass\r\n\r\ndef generate_account_activation_email(message: str) -> None:\r\n pass\r\n\r\ndef generate_password_reset_email(message: str) -> None:\r\n pass"}
|
24 |
-
{"file_name": "5b934805-79b7-4e7e-b776-ccdaf1c0ab59.png", "code": "def generate_email(user_email_address: str, email_type: str) -> str:\r\n email_types: dict[str, Callable] = {\r\n 'password_reset': send_password_reset_email,\r\n 'account_activation': send_account_activation_email\r\n }\r\n return email_types[email_type]\r\n\r\ndef send_email(user_email_address: str, email_sender: str) -> None:\r\n email_senders: dict[str, Callable] = {\r\n 'local': send_email_local,\r\n 'aws_ses': send_email_aws_ses\r\n }\r\n return email_sender[email_sender]"}
|
25 |
-
{"file_name": "680f1dde-379b-4424-ba03-6e91aa57d85d.png", "code": "def create_user(user_data: UserCreate, session: Session):\r\n hashed_password = User.hash_password(user_data.password)\r\n user = User(\r\n id='User_' + str(uuid4()),\r\n first_name=user_data.first_name,\r\n last_name=user_data.last_name,\r\n email_address=user_data.email_address,\r\n password=hashed_password\r\n )\r\n with session() as db:\r\n db.add(user)\r\n db.commit()\r\n db.refresh(user)\r\n return user\r\n\r\ndef get_user_by_email(session: Session, email: str):\r\n with session() as db:\r\n user = db.query(User).filter(User.email_address == email).first()\r\n return user"}
|
26 |
-
{"file_name": "346b7027-da81-442d-8b97-f14ffd644954.png", "code": "def get_random_user(session: Session):\r\n from random import choice\r\n with session() as db:\r\n user = choice(db.query(User).all())\r\n return user\r\n\r\ndef get_user(session: Session, user_data: GetUser):\r\n with session() as db:\r\n user = db.query(User).filter(User.id == user_data.user_id).first()\r\n return user\r\n\r\ndef get_users(session: Session, user_data: GetUsers):\r\n with session() as db:\r\n users = db.query(User).offset(user_data.offset).limit(user_data.limit).all()\r\n return users"}
|
27 |
-
{"file_name": "6d62e8bb-9325-4d04-a137-f61ea2a2e7f8.png", "code": "def delete_user(session: Session, user_data: GetUser):\r\n with session() as db:\r\n user = db.query(User).filter(User.id == user_data.user_id).first()\r\n db.delete(user)\r\n db.commit()\r\n \r\n return user\r\n\r\n\r\ndef user_account_active(session: Session, user_data: GetUser):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == user_data.user_id).first()\r\n return user.activated"}
|
28 |
-
{"file_name": "f2e1847d-9018-4789-8ea5-f2256daeb8a2.png", "code": "def delete_user(session: Session, user_data: GetUser):\r\n with session() as db:\r\n user = db.query(User).filter(User.id == user_data.user_id).first()\r\n db.delete(user)\r\n db.commit()\r\n \r\n return user\r\n\r\n\r\ndef user_account_active(session: Session, user_data: GetUser):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == user_data.user_id).first()\r\n return user.activated"}
|
29 |
-
{"file_name": "1f667095-97c3-4938-a1a2-1ed6ed57a2fd.png", "code": "def activate_user_account(session: Session, activation_data: ActivateUser):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == activation_data.user_id).first()\r\n if user.id == User.decode_auth_token(activation_data.activation_token):\r\n user.activated = True\r\n db.commit()\r\n return True\r\n raise InvalidTokenError('Invalid or Expired token.')\r\n\r\n\r\ndef loggin_user(session: Session, login_data: LoginUser):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.email_address == login_data.email_address).first()\r\n if user and user.check_password(login_data.password):\r\n return True\r\n raise ValueError('Invalid email address and or password.')\r\n"}
|
30 |
-
{"file_name": "572f77d2-f1d5-41e8-b6aa-4c7472c62ca3.png", "code": "def activate_user_account(session: Session, activation_data: ActivateUser):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == activation_data.user_id).first()\r\n if user.id == User.decode_auth_token(activation_data.activation_token):\r\n user.activated = True\r\n db.commit()\r\n return True\r\n raise InvalidTokenError('Invalid or Expired token.')\r\n\r\n\r\ndef loggin_user(session: Session, login_data: LoginUser):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.email_address == login_data.email_address).first()\r\n if user and user.check_password(login_data.password):\r\n return True\r\n raise ValueError('Invalid email address and or password.')\r\n"}
|
31 |
-
{"file_name": "41544d3f-b603-4392-a08d-1b2bedfb7e49.png", "code": "def generate_password_reset_token(session: Session, reset_password_request: RequestPasswordReset):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.email_address == reset_password_request.email_address).first()\r\n resp = {\r\n 'user_id': user.id,\r\n 'email_address': user.email_address,\r\n 'password_reset_token': user.generate_password_reset_token()\r\n }\r\n return resp\r\n\r\n\r\ndef password_repeated(session: Session, password_reset: PasswordReset):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.email_address == password_reset.email_address).first()\r\n return user.check_password(password_reset.password)"}
|
32 |
-
{"file_name": "7341b4b1-8719-4363-aa81-260d5b61e047.png", "code": "def reset_password(session: Session, password_reset: PasswordReset):\r\n with session() as db:\r\n user: User = db.query(User).filter(User.email_address == password_reset.email_address).first()\r\n email_address = user.decode_password_token(password_reset.password_reset_token)\r\n if email_address == user.email_address:\r\n user.password = user.hash_password(password_reset.password)\r\n db.commit()\r\n return True"}
|
33 |
-
{"file_name": "2540dfa6-3610-48b7-b05d-7191443304dd.png", "code": "from ..schemas.activity import CreateActivity, GetRepeatableActivity\r\nfrom sqlalchemy.orm import Session\r\nfrom ..models.view import View\r\nfrom ..models.user import User\r\nfrom ..models.post import Post\r\nfrom ..schemas.user import GetUser\r\nfrom ..schemas.post import GetPost\r\nfrom uuid import uuid4\r\n\r\n\r\ndef create_view(session: Session, activity: CreateActivity) -> View:\r\n with session() as db:\r\n view: View = View(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id,\r\n id='View_' + str(uuid4())\r\n )\r\n db.add(view)\r\n db.commit()\r\n db.refresh(view)\r\n return view"}
|
34 |
-
{"file_name": "5fd5ccd2-e48d-4dd8-979a-143e4525cefb.png", "code": "from ..schemas.activity import CreateActivity, GetRepeatableActivity\r\nfrom sqlalchemy.orm import Session\r\nfrom ..models.view import View\r\nfrom ..models.user import User\r\nfrom ..models.post import Post\r\nfrom ..schemas.user import GetUser\r\nfrom ..schemas.post import GetPost\r\nfrom uuid import uuid4\r\n\r\n\r\ndef create_view(session: Session, activity: CreateActivity) -> View:\r\n with session() as db:\r\n view: View = View(\r\n author_id=activity.user_id,\r\n post_id=activity.post_id,\r\n id='View_' + str(uuid4())\r\n )\r\n db.add(view)\r\n db.commit()\r\n db.refresh(view)\r\n return view"}
|
35 |
-
{"file_name": "22bf19c1-2192-40b6-bb33-df081156930d.png", "code": "def has_viewed(session: Session, activity: CreateActivity) -> View:\r\n with session() as db:\r\n view: View = db.query(View).filter(View.author_id==activity.user_id, View.post_id==activity.post_id).first()\r\n if view:\r\n return True\r\n return False\r\n\r\ndef list_user_views(session: Session, user_data: GetUser) -> list[View]:\r\n with session() as db:\r\n user: User = db.query(User).filter(User.id == user_data.user_id).first()\r\n views: list[View] = user.views\r\n return views\r\n\r\ndef list_post_views(session: Session, post_data: GetPost):\r\n with session() as db:\r\n post: Post = db.query(Post).filter(Post.id == post_data.post_id).first()\r\n views: list[View] = post.views\r\n return views"}
|
36 |
-
{"file_name": "bec2d9f6-8daa-4666-9b10-e1eb52f5284a.png", "code": "from .user import User\r\nfrom .post import Post\r\nfrom .like import Like\r\nfrom .bookmark import Bookmark\r\nfrom .view import View\r\nfrom .view import View\r\nfrom .comment import Comment"}
|
37 |
-
{"file_name": "50f83148-75cd-4f84-b660-8ca15b0472be.png", "code": "from datetime import datetime\r\nfrom sqlalchemy.orm import Mapped, mapped_column, relationship\r\nfrom ..database import Base\r\nfrom sqlalchemy import ForeignKey\r\n\r\n\r\nclass Bookmark(Base):\r\n __tablename__ = 'bookmarks'\r\n \r\n author_id: Mapped[str] = mapped_column(ForeignKey('users.id'), primary_key=True)\r\n post_id: Mapped[str] = mapped_column(ForeignKey('posts.id'), primary_key=True)\r\n bookmark_date: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)\r\n \r\n author = relationship('User', back_populates='bookmarks')\r\n post = relationship('Post', back_populates='bookmarks')"}
|
38 |
-
{"file_name": "992a1593-7731-43c3-84e3-d0b41fd9e31e.png", "code": "from datetime import datetime\r\nfrom sqlalchemy.orm import Mapped, mapped_column, relationship\r\nfrom ..database import Base\r\nfrom sqlalchemy import ForeignKey\r\n\r\n\r\nclass Comment(Base):\r\n __tablename__ = 'comments'\r\n \r\n id: Mapped[str] = mapped_column(primary_key=True)\r\n author_id: Mapped[str] = mapped_column(ForeignKey('users.id'))\r\n post_id: Mapped[str] = mapped_column(ForeignKey('posts.id'))\r\n comment_text: Mapped[str]\r\n comment_date: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)\r\n \r\n author = relationship('User', back_populates='comments')\r\n post = relationship('Post', back_populates='comments')"}
|
39 |
-
{"file_name": "2c1a40c3-6579-4a24-9a78-18274714569b.png", "code": "from datetime import datetime\r\nfrom sqlalchemy.orm import Mapped, mapped_column, relationship\r\nfrom ..database import Base\r\nfrom sqlalchemy import ForeignKey\r\n\r\n\r\nclass Like(Base):\r\n __tablename__ = 'likes'\r\n \r\n author_id: Mapped[str] = mapped_column(ForeignKey('users.id'), primary_key=True)\r\n post_id: Mapped[str] = mapped_column(ForeignKey('posts.id'), primary_key=True)\r\n like_date: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)\r\n \r\n author = relationship('User', back_populates='likes')\r\n post = relationship('Post', back_populates='likes')"}
|
40 |
-
{"file_name": "878e2470-d29d-454c-9641-b327191807fb.png", "code": "from datetime import datetime\r\nfrom sqlalchemy.orm import Mapped, mapped_column, relationship\r\nfrom sqlalchemy import ForeignKey\r\nfrom ..database import Base\r\n\r\n\r\nclass Post(Base):\r\n __tablename__ = 'posts'\r\n \r\n id: Mapped[str] = mapped_column(primary_key=True)\r\n author_id: Mapped[str] = mapped_column(ForeignKey('users.id'))\r\n location: Mapped[str]\r\n text: Mapped[str]\r\n image_url: Mapped[str]\r\n date_published: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)\r\n date_updated: Mapped[datetime] = mapped_column(onupdate=datetime.utcnow, default_factory=datetime.utcnow)\r\n \r\n author = relationship('User', back_populates='posts')\r\n bookmarks = relationship('Bookmark', back_populates='post')\r\n likes = relationship('Like', back_populates='post')\r\n comments = relationship('Comment', back_populates='post')\r\n views = relationship('View', back_populates='post')"}
|
41 |
-
{"file_name": "8a24871f-5c90-4a39-bdbd-bb012e491e2d.png", "code": "class User(Base):\r\n __tablename__ = 'users'\r\n \r\n id: Mapped[str] = mapped_column(primary_key=True)\r\n first_name: Mapped[str]\r\n last_name: Mapped[str]\r\n email_address: Mapped[str] = mapped_column(unique=True)\r\n password: Mapped[str]\r\n registration_date: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)\r\n role: Mapped[str] = mapped_column(default='user')\r\n activated: Mapped[bool] = mapped_column(default=False)\r\n profile_picture_url: Mapped[str] = mapped_column(default='default.jpeg')\r\n \r\n posts = relationship('Post', back_populates='author')\r\n bookmarks = relationship('Bookmark', back_populates='author')\r\n likes = relationship('Like', back_populates='author')\r\n comments = relationship('Comment', back_populates='author')\r\n views = relationship('View', back_populates='author')\r\n \r\n @staticmethod\r\n def hash_password(password: str) -> str:\r\n return bcrypt.generate_password_hash(password).decode(\"utf-8\")\r\n\r\n def check_password(self, password: str) -> bool:\r\n return bcrypt.check_password_hash(self.password, password)"}
|
42 |
-
{"file_name": "ce911e48-1315-4645-a9b6-52a33bdb475c.png", "code": "@staticmethod\r\n def hash_password(password: str) -> str:\r\n return bcrypt.generate_password_hash(password).decode(\"utf-8\")\r\n\r\n def check_password(self, password: str) -> bool:\r\n return bcrypt.check_password_hash(self.password, password)\r\n \r\n @staticmethod\r\n def encode_auth_token(user_id: int):\r\n try:\r\n payload = {\r\n \"exp\": datetime.utcnow() + timedelta(days=0, hours=2),\r\n \"iat\": datetime.utcnow(),\r\n \"sub\": user_id,\r\n }\r\n return jwt.encode(payload, current_app.config.get(\"SECRET_KEY\"), algorithm=\"HS256\")\r\n except Exception as e:\r\n return e\r\n \r\n @staticmethod\r\n def decode_auth_token(auth_token: str):\r\n try:\r\n payload = jwt.decode(auth_token, current_app.config.get(\"SECRET_KEY\"), algorithms=\"HS256\")\r\n return payload[\"sub\"]\r\n except (ExpiredSignatureError, InvalidTokenError) as e:\r\n raise e"}
|
43 |
-
{"file_name": "d5a1df5d-a94b-410b-b2b5-c2b763f8544e.png", "code": "@staticmethod\r\n def hash_password(password: str) -> str:\r\n return bcrypt.generate_password_hash(password).decode(\"utf-8\")\r\n\r\n def check_password(self, password: str) -> bool:\r\n return bcrypt.check_password_hash(self.password, password)\r\n \r\n @staticmethod\r\n def encode_auth_token(user_id: int):\r\n try:\r\n payload = {\r\n \"exp\": datetime.utcnow() + timedelta(days=0, hours=2),\r\n \"iat\": datetime.utcnow(),\r\n \"sub\": user_id,\r\n }\r\n return jwt.encode(payload, current_app.config.get(\"SECRET_KEY\"), algorithm=\"HS256\")\r\n except Exception as e:\r\n return e\r\n \r\n @staticmethod\r\n def decode_auth_token(auth_token: str):\r\n try:\r\n payload = jwt.decode(auth_token, current_app.config.get(\"SECRET_KEY\"), algorithms=\"HS256\")\r\n return payload[\"sub\"]\r\n except (ExpiredSignatureError, InvalidTokenError) as e:\r\n raise e"}
|
44 |
-
{"file_name": "0aecb918-dc95-40fe-b10a-6e4c39a730d4.png", "code": "from datetime import datetime\r\nfrom sqlalchemy.orm import Mapped, mapped_column, relationship\r\nfrom ..database import Base\r\nfrom sqlalchemy import ForeignKey\r\n\r\n\r\nclass View(Base):\r\n __tablename__ = 'views'\r\n \r\n id: Mapped[str] = mapped_column(primary_key=True)\r\n author_id: Mapped[str] = mapped_column(ForeignKey('users.id'))\r\n post_id: Mapped[str] = mapped_column(ForeignKey('posts.id'))\r\n view_date: Mapped[datetime] = mapped_column(default_factory=datetime.utcnow)\r\n \r\n author = relationship('User', back_populates='views')\r\n post = relationship('Post', back_populates='views')"}
|
45 |
-
{"file_name": "e600100c-90f9-4128-b594-4062e6d50670.png", "code": "from pydantic import BaseModel\r\nfrom typing import Optional\r\nfrom datetime import datetime\r\n\r\n\r\nclass CreateActivity(BaseModel):\r\n user_id: str\r\n post_id: str\r\n \r\n\r\nclass ActivityCreated(CreateActivity):\r\n date_created: datetime\r\n \r\nclass RepeatableActivityCreated(ActivityCreated):\r\n id: str\r\n \r\nclass GetRepeatableActivity(BaseModel):\r\n id: str\r\n \r\nclass CreateComment(CreateActivity):\r\n comment: str\r\n \r\nclass CommentCreated(CreateComment):\r\n comment_id: str\r\n date_created: datetime"}
|
46 |
-
{"file_name": "2c039ad7-70e8-4ecd-ad69-0dd6713187dc.png", "code": "from pydantic import BaseModel\r\nfrom .post import PostAuthor\r\n \r\nclass CommentSchema(BaseModel):\r\n author: PostAuthor\r\n text: str"}
|
47 |
-
{"file_name": "31cc3477-e7a8-4ed0-9004-c52b618822b4.png", "code": "from pydantic import BaseModel, Field\r\nfrom typing import Optional\r\nfrom datetime import datetime\r\n\r\n\r\nclass PostBase(BaseModel):\r\n location: str\r\n text: str\r\n author_id: str\r\n\r\n\r\nclass CreatePost(PostBase):\r\n pass\r\n\r\nclass UpdatePost(BaseModel):\r\n post_id: str\r\n author_id: str\r\n location: Optional[str]\r\n text: Optional[str]\r\n\r\nclass CreatedPost(PostBase):\r\n date_published: datetime\r\n id: str\r\n image_url: str\r\n likes: list\r\n \r\nclass GetPost(BaseModel):\r\n post_id: str"}
|
48 |
-
{"file_name": "6ad63eb1-acab-4dac-b73c-6e82790cc44e.png", "code": "class GetPosts(BaseModel):\r\n offset: Optional[int] = 0\r\n limit: Optional[int] = 10\r\n \r\nclass PostAuthor(BaseModel):\r\n id: str\r\n profile_picture: str\r\n name: str\r\n \r\nclass PostLike(BaseModel):\r\n liked: bool\r\n liked_by: Optional[list[PostAuthor]] = Field(default_factory=list)\r\n key_like: Optional[PostAuthor] = None\r\n likes_count: Optional[int] = Field(default=0)\r\n \r\nclass KeyComment(BaseModel):\r\n author: PostAuthor\r\n text: str\r\n comments_count: int\r\n \r\nclass PostSchema(BaseModel):\r\n id: str\r\n text: str\r\n image: str\r\n author: PostAuthor\r\n date_published: str\r\n location: str\r\n like: PostLike\r\n bookmarked: bool\r\n key_comment: Optional[KeyComment] = None"}
|
49 |
-
{"file_name": "0eb0fa3c-13a7-4d1a-8c58-20a963a110b8.png", "code": "class GetPosts(BaseModel):\r\n offset: Optional[int] = 0\r\n limit: Optional[int] = 10\r\n \r\nclass PostAuthor(BaseModel):\r\n id: str\r\n profile_picture: str\r\n name: str\r\n \r\nclass PostLike(BaseModel):\r\n liked: bool\r\n liked_by: Optional[list[PostAuthor]] = Field(default_factory=list)\r\n key_like: Optional[PostAuthor] = None\r\n likes_count: Optional[int] = Field(default=0)\r\n \r\nclass KeyComment(BaseModel):\r\n author: PostAuthor\r\n text: str\r\n comments_count: int\r\n \r\nclass PostSchema(BaseModel):\r\n id: str\r\n text: str\r\n image: str\r\n author: PostAuthor\r\n date_published: str\r\n location: str\r\n like: PostLike\r\n bookmarked: bool\r\n key_comment: Optional[KeyComment] = None"}
|
50 |
-
{"file_name": "e2e92910-b88e-4cde-9ebd-610b79a35f63.png", "code": "class GetPosts(BaseModel):\r\n offset: Optional[int] = 0\r\n limit: Optional[int] = 10\r\n \r\nclass PostAuthor(BaseModel):\r\n id: str\r\n profile_picture: str\r\n name: str\r\n \r\nclass PostLike(BaseModel):\r\n liked: bool\r\n liked_by: Optional[list[PostAuthor]] = Field(default_factory=list)\r\n key_like: Optional[PostAuthor] = None\r\n likes_count: Optional[int] = Field(default=0)\r\n \r\nclass KeyComment(BaseModel):\r\n author: PostAuthor\r\n text: str\r\n comments_count: int\r\n \r\nclass PostSchema(BaseModel):\r\n id: str\r\n text: str\r\n image: str\r\n author: PostAuthor\r\n date_published: str\r\n location: str\r\n like: PostLike\r\n bookmarked: bool\r\n key_comment: Optional[KeyComment] = None"}
|
51 |
-
{"file_name": "2b9c8a78-9e45-4917-836c-74c4d992389d.png", "code": "from pydantic import BaseModel\r\nfrom typing import Optional\r\n\r\n\r\nclass UserBase(BaseModel):\r\n first_name: str\r\n last_name: str\r\n email_address: str\r\n\r\n \r\nclass UserCreate(UserBase):\r\n password: str\r\n role: str = 'user'\r\n activated: bool = False\r\n \r\nclass UserCreated(UserBase):\r\n id: str\r\n activation_token: str\r\n\r\nclass User(UserBase):\r\n id: str\r\n \r\n class Config:\r\n from_attributes = True\r\n \r\nclass GetUser(BaseModel):\r\n user_id: str\r\n \r\nclass GetUsers(BaseModel):\r\n offset: Optional[int] = 0\r\n limit: Optional[int] = 10\r\n \r\nclass ActivateUser(BaseModel):\r\n user_id: str\r\n activation_token: str\r\n \r\nclass LoginUser(BaseModel):\r\n email_address: str\r\n password: str"}
|
52 |
-
{"file_name": "9d933d9e-56f5-4a86-a8f4-e4164058b6cc.png", "code": "class LoggedInUser(BaseModel):\r\n email_address: str\r\n access_token: str\r\n refresh_token: str\r\n \r\nclass RequestPasswordReset(BaseModel):\r\n user_id: str\r\n email_address: str\r\n \r\nclass RequestPasswordResetToken(RequestPasswordReset):\r\n password_reset_token: str\r\n \r\nclass PasswordReset(BaseModel):\r\n email_address: str\r\n password_reset_token: str\r\n password: str\r\n confirm_password: str"}
|
53 |
-
{"file_name": "ef24c797-843c-48ab-9ebb-98bb4f168daa.png", "code": "from sqlalchemy import create_engine\r\nfrom sqlalchemy.orm import DeclarativeBase, MappedAsDataclass\r\nfrom sqlalchemy.orm import sessionmaker\r\nfrom ...config.config import BaseConfig\r\nfrom contextlib import contextmanager\r\nfrom flask import current_app\r\n\r\n\r\nclass Base(MappedAsDataclass, DeclarativeBase):\r\n pass\r\n\r\nSQLALCHEMY_DATABASE_URI = BaseConfig().db_conn_string\r\nengine = create_engine(SQLALCHEMY_DATABASE_URI)\r\nSession = sessionmaker(bind=engine, autocommit=False, autoflush=False)\r\n\r\ndef create_all():\r\n Base.metadata.create_all(bind=engine)\r\n \r\ndef drop_all():\r\n Base.metadata.drop_all(bind=engine)\r\n\r\n@contextmanager\r\ndef get_db():\r\n try:\r\n db = Session()\r\n yield db\r\n finally:\r\n db.close()"}
|
54 |
-
{"file_name": "b84b4833-928e-4a28-b5ad-556b2d045a8e.png", "code": "from sqlalchemy import create_engine\r\nfrom sqlalchemy.orm import DeclarativeBase, MappedAsDataclass\r\nfrom sqlalchemy.orm import sessionmaker\r\nfrom ...config.config import BaseConfig\r\nfrom contextlib import contextmanager\r\nfrom flask import current_app\r\n\r\n\r\nclass Base(MappedAsDataclass, DeclarativeBase):\r\n pass\r\n\r\nSQLALCHEMY_DATABASE_URI = BaseConfig().db_conn_string\r\nengine = create_engine(SQLALCHEMY_DATABASE_URI)\r\nSession = sessionmaker(bind=engine, autocommit=False, autoflush=False)\r\n\r\ndef create_all():\r\n Base.metadata.create_all(bind=engine)\r\n \r\ndef drop_all():\r\n Base.metadata.drop_all(bind=engine)\r\n\r\n@contextmanager\r\ndef get_db():\r\n try:\r\n db = Session()\r\n yield db\r\n finally:\r\n db.close()"}
|
55 |
-
{"file_name": "042b0e58-929d-4d08-90b7-ef6ffd6f00fa.png", "code": "from sqlalchemy import create_engine\r\nfrom sqlalchemy.orm import DeclarativeBase, MappedAsDataclass\r\nfrom sqlalchemy.orm import sessionmaker\r\nfrom ...config.config import BaseConfig\r\nfrom contextlib import contextmanager\r\nfrom flask import current_app\r\n\r\n\r\nclass Base(MappedAsDataclass, DeclarativeBase):\r\n pass\r\n\r\nSQLALCHEMY_DATABASE_URI = BaseConfig().db_conn_string\r\nengine = create_engine(SQLALCHEMY_DATABASE_URI)\r\nSession = sessionmaker(bind=engine, autocommit=False, autoflush=False)\r\n\r\ndef create_all():\r\n Base.metadata.create_all(bind=engine)\r\n \r\ndef drop_all():\r\n Base.metadata.drop_all(bind=engine)\r\n\r\n@contextmanager\r\ndef get_db():\r\n try:\r\n db = Session()\r\n yield db\r\n finally:\r\n db.close()"}
|
56 |
-
{"file_name": "a7c4375a-4e69-4f0e-b986-a7610255307b.png", "code": "from sqlalchemy import create_engine\r\nfrom sqlalchemy.orm import DeclarativeBase, MappedAsDataclass\r\nfrom sqlalchemy.orm import sessionmaker\r\nfrom ...config.config import BaseConfig\r\nfrom contextlib import contextmanager\r\nfrom flask import current_app\r\n\r\n\r\nclass Base(MappedAsDataclass, DeclarativeBase):\r\n pass\r\n\r\nSQLALCHEMY_DATABASE_URI = BaseConfig().db_conn_string\r\nengine = create_engine(SQLALCHEMY_DATABASE_URI)\r\nSession = sessionmaker(bind=engine, autocommit=False, autoflush=False)\r\n\r\ndef create_all():\r\n Base.metadata.create_all(bind=engine)\r\n \r\ndef drop_all():\r\n Base.metadata.drop_all(bind=engine)\r\n\r\n@contextmanager\r\ndef get_db():\r\n try:\r\n db = Session()\r\n yield db\r\n finally:\r\n db.close()"}
|
57 |
-
{"file_name": "cb064bdf-6439-4fdd-b85d-85a3cee514ac.png", "code": "from ..database.crud.user import get_random_user\r\nfrom ..database.crud.post import get_posts\r\nfrom ..database.crud.like import list_post_likes, get_key_like, has_liked\r\nfrom ..database.crud.comment import get_key_comment, list_post_comments\r\nfrom ..database.crud.bookmark import has_bookmarked\r\nfrom ..database.database import get_db\r\nfrom ..database.models import (\r\n User, Post, Like, Bookmark, Comment\r\n)\r\nfrom ..database.schemas.post import (\r\n GetPosts, PostAuthor, GetPost, PostLike, KeyComment, PostSchema\r\n)\r\nfrom ..database.schemas.activity import CreateActivity\r\nfrom flask import url_for\r\nfrom pydantic import ValidationError\r\nfrom sqlalchemy.exc import OperationalError, IntegrityError\r\nfrom datetime import datetime"}
|
58 |
-
{"file_name": "ba2deb3e-56d9-45fd-9be8-a6b2c0956e69.png", "code": "\"\"\"This module contains routes for the app.\"\"\"\r\nfrom flask import Blueprint, render_template, jsonify, request, url_for\r\nfrom http import HTTPStatus\r\nfrom ..database.schemas.activity import (\r\n ActivityCreated, CreateActivity, RepeatableActivityCreated,\r\n CreateComment, CommentCreated)\r\nfrom ..database.models import (\r\n User, Post, Comment, Bookmark, Like, View\r\n)\r\nfrom ..database.schemas.user import GetUser\r\nfrom ..database.schemas.post import GetPost\r\nfrom ..database.database import get_db\r\nfrom ..database.crud.user import get_user, get_random_user\r\nfrom ..database.crud.post import get_post\r\nfrom ..database.crud.bookmark import (\r\n create_bookmark, delete_bookmark, list_user_bookmarks, has_bookmarked\r\n)\r\nfrom ..database.crud.view import (\r\n create_view, list_user_views, has_viewed\r\n)\r\nfrom ..database.crud.like import (\r\n create_like, delete_like, list_user_likes, has_liked, list_post_likes, \r\n get_key_like\r\n)\r\nfrom ..database.crud.comment import (\r\n create_comment, list_user_comments, list_post_comments\r\n)\r\nfrom pydantic import ValidationError\r\nfrom sqlalchemy.exc import OperationalError, IntegrityError\r\nfrom ..database.schemas.post import (\r\n CreatePost, CreatedPost, GetPost, GetPosts, UpdatePost, PostSchema, PostAuthor, \r\n PostLike, KeyComment\r\n)\r\nfrom ..database.crud.post import (\r\n create_post, get_post, get_posts, delete_post, update_post\r\n)\r\nfrom ..database.crud.comment import get_key_comment"}
|
59 |
-
{"file_name": "b1eb25ad-bf1e-4b8b-870b-18948d0a44e7.png", "code": "\"\"\"This module contains routes for the app.\"\"\"\r\nfrom flask import Blueprint, flash, jsonify, redirect, render_template, request, url_for\r\nfrom http import HTTPStatus\r\nfrom ..database.schemas.post import (\r\n CreatePost, CreatedPost, GetPost, GetPosts, UpdatePost, PostSchema, PostAuthor\r\n)\r\nfrom ..database.crud.post import (\r\n create_post, get_post, get_posts, delete_post, update_post\r\n)\r\nfrom ..database.models.post import Post\r\nfrom ..database.database import get_db\r\nfrom pydantic import ValidationError\r\nfrom sqlalchemy.exc import OperationalError, IntegrityError\r\nfrom ..database.models.user import User\r\nfrom ..database.crud.user import get_user\r\nfrom ..database.schemas.user import GetUser\r\nfrom ..database.models.bookmark import Bookmark\r\nfrom ..database.crud.bookmark import list_post_bookmarks\r\nfrom ..database.schemas.activity import ActivityCreated, RepeatableActivityCreated, CommentCreated\r\nfrom ..database.crud.like import list_post_likes\r\nfrom ..database.models.like import Like\r\nfrom ..database.models.comment import Comment\r\nfrom ..database.models.view import View\r\nfrom ..database.schemas.comment import CommentSchema\r\nfrom ..database.crud.view import (\r\n list_post_views\r\n)\r\nfrom ..database.crud.comment import list_post_comments\r\nfrom ..home.helpers import load_posts\r\n\r\npost = Blueprint(\"post\", __name__)"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|