From 7d69cf31488beb72f6dd93cf3bbdefaec4dfd9d1 Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Thu, 9 Jul 2020 16:25:41 -0700 Subject: [PATCH 1/6] Add my story to stories --- .../e96755d19f0c_add_my_story_to_stories.py | 28 +++++++++++++++ backend/stories/models.py | 3 +- backend/stories/schemas.py | 1 + frontend/src/routes/MyStory/index.js | 35 ++++++++++++++++--- 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 backend/alembic/versions/e96755d19f0c_add_my_story_to_stories.py diff --git a/backend/alembic/versions/e96755d19f0c_add_my_story_to_stories.py b/backend/alembic/versions/e96755d19f0c_add_my_story_to_stories.py new file mode 100644 index 00000000..74dd0417 --- /dev/null +++ b/backend/alembic/versions/e96755d19f0c_add_my_story_to_stories.py @@ -0,0 +1,28 @@ +"""add my story to stories + +Revision ID: e96755d19f0c +Revises: a31bfe8eba6b +Create Date: 2020-07-09 21:58:00.273763 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "e96755d19f0c" +down_revision = "a31bfe8eba6b" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("stories", sa.Column("my_story", sa.Text(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("stories", "my_story") + # ### end Alembic commands ### diff --git a/backend/stories/models.py b/backend/stories/models.py index 2016b76f..8d16aad2 100644 --- a/backend/stories/models.py +++ b/backend/stories/models.py @@ -1,6 +1,6 @@ import json -from sqlalchemy import JSON, Column, ForeignKey, Integer, String, Date +from sqlalchemy import JSON, Column, ForeignKey, Integer, String, Date, Text from sqlalchemy.orm import relationship from database import Base @@ -21,6 +21,7 @@ class Story(Base): _medical_conditions = Column(JSON) sickness_start = Column(String(64)) sickness_end = Column(String(64)) + my_story = Column(Text()) user = relationship("User", uselist=False, back_populates="story") symptoms = relationship("Symptom", secondary="story_symptoms") diff --git a/backend/stories/schemas.py b/backend/stories/schemas.py index 87b03adf..cec20f0e 100644 --- a/backend/stories/schemas.py +++ b/backend/stories/schemas.py @@ -65,6 +65,7 @@ class StoryCreate(BaseModel): sickness_start: str = None sickness_end: str = None close_contacts: List[CloseContact] = [] + my_story: str = None class Story(StoryCreate): diff --git a/frontend/src/routes/MyStory/index.js b/frontend/src/routes/MyStory/index.js index ce63f9e5..e189d9bb 100644 --- a/frontend/src/routes/MyStory/index.js +++ b/frontend/src/routes/MyStory/index.js @@ -1,14 +1,40 @@ -import React from "react"; +import React, { useEffect } from "react"; import { TextField, Fab } from "@material-ui/core"; import ArrowLeftIcon from "@material-ui/icons/ArrowLeft"; import classNames from "classnames"; import styles from "./styles.module.css"; +import { useSelector, useDispatch } from "react-redux"; +import { submitStory } from "actions/story"; export default function MyStory(props) { - const [story, setStory] = React.useState(""); + const [myStory, setMyStory] = React.useState(""); + const { story } = useSelector((state) => state.story); + const dispatch = useDispatch(); + + useEffect(() => { + if (!story || !story["myStory"]) { + setMyStory(""); + } else { + setMyStory(story["myStory"]); + } + }, [dispatch, story]); const handleChange = (event) => { - setStory(event.target.value); + setMyStory(event.target.value); + }; + + const handleSubmit = () => { + if (story["myStory"] !== myStory) { + story["myStory"] = myStory; + const dto = { + story, + travels: [], + closeContacts: [], + }; + dispatch(submitStory(dto)); + } + + props.history.push("/dashboard"); }; return ( @@ -20,7 +46,7 @@ export default function MyStory(props) { placeholder="Tell a little about yourself, how you think you got sick and what the experience has been like" multiline rowsMax={10} - value={story} + value={myStory} onChange={handleChange} className={classNames("textarea", styles.textarea)} variant="outlined" @@ -31,6 +57,7 @@ export default function MyStory(props) { size="medium" className="fab" variant="extended" + onClick={handleSubmit} > SHARE MY STORY From 8314c50801848f9bda09cba067a766019481e4d5 Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Tue, 13 Oct 2020 02:47:55 -0700 Subject: [PATCH 2/6] add table for like and dislike --- backend/alembic/env.py | 2 +- ...335fdfc2_add_table_for_like_and_dislike.py | 41 ++++++++++++ backend/likes/__init__.py | 0 backend/likes/crud.py | 43 +++++++++++++ backend/likes/models.py | 10 +++ backend/likes/schemas.py | 13 ++++ backend/router/api.py | 4 +- backend/router/likes.py | 64 +++++++++++++++++++ 8 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py create mode 100644 backend/likes/__init__.py create mode 100644 backend/likes/crud.py create mode 100644 backend/likes/models.py create mode 100644 backend/likes/schemas.py create mode 100644 backend/router/likes.py diff --git a/backend/alembic/env.py b/backend/alembic/env.py index fdc577c5..36eece60 100644 --- a/backend/alembic/env.py +++ b/backend/alembic/env.py @@ -7,8 +7,8 @@ from database import Base from stories import models as story_models from users import models as user_models - from NytLiveCounty import models as nyt_models +from likes import models as like_models # this is the Alembic Config object, which provides # access to the values within the .ini file in use. diff --git a/backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py b/backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py new file mode 100644 index 00000000..74801aeb --- /dev/null +++ b/backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py @@ -0,0 +1,41 @@ +"""add table for like and dislike + +Revision ID: 7ecf335fdfc2 +Revises: 527194b9fb18 +Create Date: 2020-10-13 09:42:37.480671 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "7ecf335fdfc2" +down_revision = "527194b9fb18" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "likes", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("updated_at", sa.DateTime(), nullable=True), + sa.Column("like", sa.Boolean(), nullable=True), + sa.Column("story_id", sa.Integer(), nullable=True), + sa.Column("liker_story_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(["liker_story_id"], ["stories.id"],), + sa.ForeignKeyConstraint(["story_id"], ["stories.id"],), + sa.PrimaryKeyConstraint("id"), + ) + op.create_index(op.f("ix_likes_id"), "likes", ["id"], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_likes_id"), table_name="likes") + op.drop_table("likes") + # ### end Alembic commands ### diff --git a/backend/likes/__init__.py b/backend/likes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/likes/crud.py b/backend/likes/crud.py new file mode 100644 index 00000000..dff066dc --- /dev/null +++ b/backend/likes/crud.py @@ -0,0 +1,43 @@ +from sqlalchemy.orm import Session +from . import models, schemas +from sqlalchemy.sql.expression import and_ +from stories.crud import update + + +def get_like_by_story_and_user( + db: Session, story_id: int, liker_story_id: int +): + return db.query(models.Like).filter( + and_( + models.Like.story_id == story_id, + models.Like.liker_story_id == liker_story_id, + ) + ) + + +def update_like(db, like_id, like: schemas.LikeCreate): + return update(like_id, like, models.Like, db) + + +def create_like(db, like: schemas.LikeCreate, liker_story_id: int): + d = like.dict() + d["liker_story_id"] = liker_story_id + db_like = models.Like(**d) + db.add(db.like) + db.commit() + db.refresh(db_like) + return db_like + + +def get_like_count(db, story_id): + return ( + db.query(models.Like).filter(models.Like.story_id == story_id).count() + ) + + +def is_like_by(db, story_id, liker_story_id): + db_like = get_like_by_story_and_user(db, story_id, liker_story_id) + if db_like: + return db_like.like + else: + return None diff --git a/backend/likes/models.py b/backend/likes/models.py new file mode 100644 index 00000000..c33f2e75 --- /dev/null +++ b/backend/likes/models.py @@ -0,0 +1,10 @@ +from database import Base +from sqlalchemy import Column, ForeignKey, Integer, Boolean + + +class Like(Base): + __tablename__ = "likes" + + like = Column(Boolean) + story_id = Column(Integer, ForeignKey("stories.id")) + liker_story_id = Column(Integer, ForeignKey("stories.id")) diff --git a/backend/likes/schemas.py b/backend/likes/schemas.py new file mode 100644 index 00000000..b2a16afd --- /dev/null +++ b/backend/likes/schemas.py @@ -0,0 +1,13 @@ +from pydantic import BaseModel + + +class LikeCreate(BaseModel): + like: bool = None + story_id: int + + +class Like(LikeCreate): + liker_story_id: int + + class Config: + orm_mode = True diff --git a/backend/router/api.py b/backend/router/api.py index 3a549c0b..7adf4894 100644 --- a/backend/router/api.py +++ b/backend/router/api.py @@ -1,6 +1,6 @@ from fastapi import APIRouter -from router import auth, stories, users, symptoms, data, nyt_live_county +from router import auth, stories, users, symptoms, data, nyt_live_county, likes router = APIRouter() @@ -17,3 +17,5 @@ router.include_router( nyt_live_county.router, prefix="/nyt_live_county", tags=["nyt_live_county"] ) + +router.include_router(likes.router, prefix="/likes", tags=["likes"]) diff --git a/backend/router/likes.py b/backend/router/likes.py new file mode 100644 index 00000000..142f671d --- /dev/null +++ b/backend/router/likes.py @@ -0,0 +1,64 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session +from starlette.responses import JSONResponse +import json + +from auth import main +from database import get_db +from likes import crud, schemas +from stories.crud import get_story +from stories import schemas as stories_schemas + +router = APIRouter() + + +@router.post("/", response_model=schemas.Like) +async def create_like( + like: schemas.LikeCreate, + current_story: stories_schemas.Story = Depends(main.get_current_story), + db: Session = Depends(get_db), +): + if not get_story(db, like.story_id): + raise HTTPException( + status_code=404, + detail="Target story cannot be found", + headers={"WWW-Authenticate": "Bearer"}, + ) + + if not current_story: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail="User haven't shared their story", + headers={"WWW-Authenticate": "Bearer"}, + ) + + like_to_update = crud.get_like_by_story_and_user( + db, story_id=like.story_id, liker_story_id=current_story.id + ) + + if like_to_update: + return crud.update_like(db, like_to_update.id, like) + else: + if like.story_id == like.liker_story_id: + raise HTTPException( + status_code=422, + detail="User cannot like or dislike their own stories", + headers={"WWW-Authenticate": "Bearer"}, + ) + + return crud.create_like(db, like, current_story.id) + + +@router.get("/{story_id}") +async def get_like_count( + story_id: int, + current_story: stories_schemas.Story = Depends(main.get_current_story), + db: Session = Depends(get_db), +): + like_count = crud.get_like_count(story_id) + is_like_by_me = crud.is_like_by(story_id, current_story.id, db) + + return JSONResponse( + json.dumps({"like_count": like_count, "like": is_like_by_me}), + status_code=200, + ) From c085c734b3a087e81d8c457cab9fc23f59b769f7 Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Tue, 13 Oct 2020 03:14:54 -0700 Subject: [PATCH 3/6] add table for like and dislike --- backend/likes/crud.py | 14 +++++++++----- backend/router/likes.py | 10 ++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/likes/crud.py b/backend/likes/crud.py index dff066dc..cba9d6be 100644 --- a/backend/likes/crud.py +++ b/backend/likes/crud.py @@ -7,11 +7,15 @@ def get_like_by_story_and_user( db: Session, story_id: int, liker_story_id: int ): - return db.query(models.Like).filter( - and_( - models.Like.story_id == story_id, - models.Like.liker_story_id == liker_story_id, + return ( + db.query(models.Like) + .filter( + and_( + models.Like.story_id == story_id, + models.Like.liker_story_id == liker_story_id, + ) ) + .first() ) @@ -23,7 +27,7 @@ def create_like(db, like: schemas.LikeCreate, liker_story_id: int): d = like.dict() d["liker_story_id"] = liker_story_id db_like = models.Like(**d) - db.add(db.like) + db.add(db_like) db.commit() db.refresh(db_like) return db_like diff --git a/backend/router/likes.py b/backend/router/likes.py index 142f671d..9b833c99 100644 --- a/backend/router/likes.py +++ b/backend/router/likes.py @@ -1,7 +1,6 @@ from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.orm import Session from starlette.responses import JSONResponse -import json from auth import main from database import get_db @@ -39,7 +38,7 @@ async def create_like( if like_to_update: return crud.update_like(db, like_to_update.id, like) else: - if like.story_id == like.liker_story_id: + if like.story_id == current_story.id: raise HTTPException( status_code=422, detail="User cannot like or dislike their own stories", @@ -55,10 +54,9 @@ async def get_like_count( current_story: stories_schemas.Story = Depends(main.get_current_story), db: Session = Depends(get_db), ): - like_count = crud.get_like_count(story_id) - is_like_by_me = crud.is_like_by(story_id, current_story.id, db) + like_count = crud.get_like_count(db, story_id) + is_like_by_me = crud.is_like_by(db, story_id, current_story.id) return JSONResponse( - json.dumps({"like_count": like_count, "like": is_like_by_me}), - status_code=200, + {"like_count": like_count, "like": is_like_by_me}, status_code=200, ) From 23313c5b834951af038376d67a4147a0c5570299 Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Tue, 13 Oct 2020 03:30:09 -0700 Subject: [PATCH 4/6] fixed a bug --- backend/likes/crud.py | 12 +++++++++++- backend/router/likes.py | 8 +++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/likes/crud.py b/backend/likes/crud.py index cba9d6be..58ffdb7f 100644 --- a/backend/likes/crud.py +++ b/backend/likes/crud.py @@ -35,7 +35,17 @@ def create_like(db, like: schemas.LikeCreate, liker_story_id: int): def get_like_count(db, story_id): return ( - db.query(models.Like).filter(models.Like.story_id == story_id).count() + db.query(models.Like) + .filter(and_(models.Like.story_id == story_id, models.Like.like == 1)) + .count() + ) + + +def get_dislike_count(db, story_id): + return ( + db.query(models.Like) + .filter(and_(models.Like.story_id == story_id, models.Like.like == 0)) + .count() ) diff --git a/backend/router/likes.py b/backend/router/likes.py index 9b833c99..8a5978e4 100644 --- a/backend/router/likes.py +++ b/backend/router/likes.py @@ -55,8 +55,14 @@ async def get_like_count( db: Session = Depends(get_db), ): like_count = crud.get_like_count(db, story_id) + dislike_count = crud.get_dislike_count(db, story_id) is_like_by_me = crud.is_like_by(db, story_id, current_story.id) return JSONResponse( - {"like_count": like_count, "like": is_like_by_me}, status_code=200, + { + "like": like_count, + "dislike": dislike_count, + "like_by_me": is_like_by_me, + }, + status_code=200, ) From 0b5e44ae21834806737046d528455d03cc2e13b9 Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Tue, 13 Oct 2020 21:37:25 -0700 Subject: [PATCH 5/6] change like & dislike for my story --- ...335fdfc2_add_table_for_like_and_dislike.py | 41 ------------------- backend/likes/crud.py | 20 +++++---- backend/likes/models.py | 5 ++- backend/likes/schemas.py | 2 +- backend/router/likes.py | 33 ++++++++------- backend/stories/crud.py | 8 ++++ 6 files changed, 43 insertions(+), 66 deletions(-) delete mode 100644 backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py diff --git a/backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py b/backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py deleted file mode 100644 index 74801aeb..00000000 --- a/backend/alembic/versions/7ecf335fdfc2_add_table_for_like_and_dislike.py +++ /dev/null @@ -1,41 +0,0 @@ -"""add table for like and dislike - -Revision ID: 7ecf335fdfc2 -Revises: 527194b9fb18 -Create Date: 2020-10-13 09:42:37.480671 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = "7ecf335fdfc2" -down_revision = "527194b9fb18" -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "likes", - sa.Column("id", sa.Integer(), nullable=False), - sa.Column("created_at", sa.DateTime(), nullable=True), - sa.Column("updated_at", sa.DateTime(), nullable=True), - sa.Column("like", sa.Boolean(), nullable=True), - sa.Column("story_id", sa.Integer(), nullable=True), - sa.Column("liker_story_id", sa.Integer(), nullable=True), - sa.ForeignKeyConstraint(["liker_story_id"], ["stories.id"],), - sa.ForeignKeyConstraint(["story_id"], ["stories.id"],), - sa.PrimaryKeyConstraint("id"), - ) - op.create_index(op.f("ix_likes_id"), "likes", ["id"], unique=False) - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f("ix_likes_id"), table_name="likes") - op.drop_table("likes") - # ### end Alembic commands ### diff --git a/backend/likes/crud.py b/backend/likes/crud.py index 58ffdb7f..b69fe44f 100644 --- a/backend/likes/crud.py +++ b/backend/likes/crud.py @@ -5,13 +5,13 @@ def get_like_by_story_and_user( - db: Session, story_id: int, liker_story_id: int + db: Session, my_story_id: int, liker_story_id: int ): return ( db.query(models.Like) .filter( and_( - models.Like.story_id == story_id, + models.Like.my_story_id == my_story_id, models.Like.liker_story_id == liker_story_id, ) ) @@ -33,24 +33,28 @@ def create_like(db, like: schemas.LikeCreate, liker_story_id: int): return db_like -def get_like_count(db, story_id): +def get_like_count(db, my_story_id): return ( db.query(models.Like) - .filter(and_(models.Like.story_id == story_id, models.Like.like == 1)) + .filter( + and_(models.Like.my_story_id == my_story_id, models.Like.like == 1) + ) .count() ) -def get_dislike_count(db, story_id): +def get_dislike_count(db, my_story_id): return ( db.query(models.Like) - .filter(and_(models.Like.story_id == story_id, models.Like.like == 0)) + .filter( + and_(models.Like.my_story_id == my_story_id, models.Like.like == 0) + ) .count() ) -def is_like_by(db, story_id, liker_story_id): - db_like = get_like_by_story_and_user(db, story_id, liker_story_id) +def is_like_by(db, my_story_id, liker_story_id): + db_like = get_like_by_story_and_user(db, my_story_id, liker_story_id) if db_like: return db_like.like else: diff --git a/backend/likes/models.py b/backend/likes/models.py index c33f2e75..c2cbfe87 100644 --- a/backend/likes/models.py +++ b/backend/likes/models.py @@ -1,10 +1,13 @@ from database import Base from sqlalchemy import Column, ForeignKey, Integer, Boolean +from sqlalchemy.orm import relationship class Like(Base): __tablename__ = "likes" like = Column(Boolean) - story_id = Column(Integer, ForeignKey("stories.id")) + my_story_id = Column(Integer, ForeignKey("my_stories.id")) liker_story_id = Column(Integer, ForeignKey("stories.id")) + + my_story = relationship("MyStory", lazy="select") diff --git a/backend/likes/schemas.py b/backend/likes/schemas.py index b2a16afd..f6cfce53 100644 --- a/backend/likes/schemas.py +++ b/backend/likes/schemas.py @@ -3,7 +3,7 @@ class LikeCreate(BaseModel): like: bool = None - story_id: int + my_story_id: int class Like(LikeCreate): diff --git a/backend/router/likes.py b/backend/router/likes.py index 8a5978e4..3acf77ca 100644 --- a/backend/router/likes.py +++ b/backend/router/likes.py @@ -5,22 +5,23 @@ from auth import main from database import get_db from likes import crud, schemas -from stories.crud import get_story +from stories.crud import get_my_story from stories import schemas as stories_schemas router = APIRouter() @router.post("/", response_model=schemas.Like) -async def create_like( +def create_like( like: schemas.LikeCreate, current_story: stories_schemas.Story = Depends(main.get_current_story), db: Session = Depends(get_db), ): - if not get_story(db, like.story_id): + my_story = get_my_story(db, like.my_story_id) + if not my_story: raise HTTPException( status_code=404, - detail="Target story cannot be found", + detail="Target my story cannot be found", headers={"WWW-Authenticate": "Bearer"}, ) @@ -32,31 +33,33 @@ async def create_like( ) like_to_update = crud.get_like_by_story_and_user( - db, story_id=like.story_id, liker_story_id=current_story.id + db, my_story_id=like.my_story_id, liker_story_id=current_story.id ) if like_to_update: - return crud.update_like(db, like_to_update.id, like) + db_like = crud.update_like(db, like_to_update.id, like) else: - if like.story_id == current_story.id: + if my_story.story_id == current_story.id: raise HTTPException( status_code=422, - detail="User cannot like or dislike their own stories", + detail="User cannot like or dislike their own my stories", headers={"WWW-Authenticate": "Bearer"}, ) - return crud.create_like(db, like, current_story.id) + db_like = crud.create_like(db, like, current_story.id) + return db_like -@router.get("/{story_id}") -async def get_like_count( - story_id: int, + +@router.get("/{my_story_id}") +def get_like_count( + my_story_id: int, current_story: stories_schemas.Story = Depends(main.get_current_story), db: Session = Depends(get_db), ): - like_count = crud.get_like_count(db, story_id) - dislike_count = crud.get_dislike_count(db, story_id) - is_like_by_me = crud.is_like_by(db, story_id, current_story.id) + like_count = crud.get_like_count(db, my_story_id) + dislike_count = crud.get_dislike_count(db, my_story_id) + is_like_by_me = crud.is_like_by(db, my_story_id, current_story.id) return JSONResponse( { diff --git a/backend/stories/crud.py b/backend/stories/crud.py index a8b077c9..12e0ade6 100644 --- a/backend/stories/crud.py +++ b/backend/stories/crud.py @@ -146,3 +146,11 @@ def update_latest_my_story(db: Session, story: schemas.Story, my_story): def get_my_story_count(db: Session): return db.query(models.MyStory).count() + + +def get_my_story(db: Session, my_story_id: int): + return ( + db.query(models.MyStory) + .filter(models.MyStory.id == my_story_id) + .first() + ) From 09430345106968a31e64b519286a6ffb3f634b8f Mon Sep 17 00:00:00 2001 From: Paul Zhu Date: Tue, 13 Oct 2020 21:42:15 -0700 Subject: [PATCH 6/6] change like & dislike for my story --- ...e0efb31c_add_table_for_like_and_dislike.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 backend/alembic/versions/edace0efb31c_add_table_for_like_and_dislike.py diff --git a/backend/alembic/versions/edace0efb31c_add_table_for_like_and_dislike.py b/backend/alembic/versions/edace0efb31c_add_table_for_like_and_dislike.py new file mode 100644 index 00000000..686970ce --- /dev/null +++ b/backend/alembic/versions/edace0efb31c_add_table_for_like_and_dislike.py @@ -0,0 +1,41 @@ +"""add table for like and dislike + +Revision ID: edace0efb31c +Revises: 527194b9fb18 +Create Date: 2020-10-14 02:51:38.265440 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "edace0efb31c" +down_revision = "527194b9fb18" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "likes", + sa.Column("id", sa.Integer(), nullable=False), + sa.Column("created_at", sa.DateTime(), nullable=True), + sa.Column("updated_at", sa.DateTime(), nullable=True), + sa.Column("like", sa.Boolean(), nullable=True), + sa.Column("my_story_id", sa.Integer(), nullable=True), + sa.Column("liker_story_id", sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(["liker_story_id"], ["stories.id"],), + sa.ForeignKeyConstraint(["my_story_id"], ["my_stories.id"],), + sa.PrimaryKeyConstraint("id"), + ) + op.create_index(op.f("ix_likes_id"), "likes", ["id"], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f("ix_likes_id"), table_name="likes") + op.drop_table("likes") + # ### end Alembic commands ###