feed WIP
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import psycopg2.extras
|
||||
from psycopg2._psycopg import connection
|
||||
|
||||
# swipe create and delete
|
||||
|
||||
def create_swipe(
|
||||
conn: connection,
|
||||
username: str,
|
||||
feed_id: int,
|
||||
picture_id: int,
|
||||
value: int
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
insert into picrinth.swipes
|
||||
(username, feed_id, picture_id, value, created_at)
|
||||
values (%s, %s, %s, %s, now())
|
||||
returning id
|
||||
""",
|
||||
(username, feed_id, picture_id, value),
|
||||
)
|
||||
conn.commit()
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
def delete_swipe(
|
||||
conn: connection,
|
||||
username: str,
|
||||
feed_id: int,
|
||||
picture_id: int
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
delete from picrinth.swipes
|
||||
where username = %s and picture_id = %s and feed_id = %s
|
||||
""",
|
||||
(username, picture_id, feed_id),
|
||||
)
|
||||
conn.commit()
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
# swipe receiving
|
||||
|
||||
def get_swipe(
|
||||
conn: connection,
|
||||
username: str,
|
||||
feed_id: int,
|
||||
picture_id: int
|
||||
):
|
||||
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
select username,
|
||||
feed_id, picture_id,
|
||||
value, created_at
|
||||
from picrinth.swipes
|
||||
where username = %s and feed_id = %s and picture_id = %s
|
||||
""",
|
||||
(username, feed_id, picture_id),
|
||||
)
|
||||
return cur.fetchone()
|
||||
|
||||
|
||||
def get_swipes_by_picture_id(
|
||||
conn: connection,
|
||||
feed_id: int,
|
||||
picture_id: int
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
select *
|
||||
from picrinth.swipes
|
||||
where feed_id = %s and picture_id = %s
|
||||
""",
|
||||
(feed_id, picture_id),
|
||||
)
|
||||
return cur.fetchone()
|
||||
|
||||
def get_swipes_by_user(
|
||||
conn: connection,
|
||||
username: str,
|
||||
feed_id: int
|
||||
):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"""
|
||||
select *
|
||||
from picrinth.swipes
|
||||
where username = %s and feed_id = %s
|
||||
""",
|
||||
(username, feed_id),
|
||||
)
|
||||
return cur.fetchone()
|
||||
Reference in New Issue
Block a user