Skip to content

Commit

Permalink
쿼리문에도 시간 timezone 주입
Browse files Browse the repository at this point in the history
  • Loading branch information
morecleverer committed Jan 30, 2025
1 parent 7c7b600 commit 03cc6bc
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions snuvote/app/vote/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def get_ongoing_list(self, start_cursor: tuple[datetime,int] |None) -> tuple[Lis
filtered_votes = (
select(Vote.id)
.where(
(Vote.create_datetime < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
(Vote.create_datetime.replace(tzinfo=timezone.utc) < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
| (
(Vote.create_datetime == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
(Vote.create_datetime.replace(tzinfo=timezone.utc) == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
)
)
.where(Vote.end_datetime > datetime.now(timezone.utc))
.where(Vote.end_datetime.replace(tzinfo=timezone.utc) > datetime.now(timezone.utc))
.subquery()
)

Expand Down Expand Up @@ -126,17 +126,17 @@ def get_ended_votes_list(self, start_cursor: tuple[datetime,int] |None) -> tuple
if start_cursor is None:
filtered_votes = (
select(Vote.id)
.where(Vote.end_datetime < datetime.now(timezone.utc))
.where(Vote.end_datetime.replace(tzinfo=timezone.utc) < datetime.now(timezone.utc))
.subquery()
)
else: # 커서가 None이 아니면 커서보다 과거에 끝난 투표부터 최근에 끝난 순으로 self.pagination_size개
filtered_votes = (
select(Vote.id)
.where(Vote.end_datetime <= datetime.now(timezone.utc))
.where(Vote.end_datetime.replace(tzinfo=timezone.utc) <= datetime.now(timezone.utc))
.where(
(Vote.end_datetime < start_cursor) # 종료시간이 커서 시간보다 과거이거나
(Vote.end_datetime.replace(tzinfo=timezone.utc) < start_cursor) # 종료시간이 커서 시간보다 과거이거나
| (
(Vote.end_datetime == start_cursor[0]) & (Vote.id > start_cursor[1]) # 종료시간이 커서와 같은데 id가 더 큰 경우
(Vote.end_datetime.replace(tzinfo=timezone.utc) == start_cursor[0]) & (Vote.id > start_cursor[1]) # 종료시간이 커서와 같은데 id가 더 큰 경우
)
)
.subquery()
Expand Down Expand Up @@ -184,9 +184,9 @@ def get_hot_votes_list(self, start_cursor: tuple[datetime,int] |None) -> tuple[
filtered_votes = (
select(Vote.id)
.where(
(Vote.create_datetime < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
(Vote.create_datetime.replace(tzinfo=timezone.utc) < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
| (
(Vote.create_datetime == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
(Vote.create_datetime.replace(tzinfo=timezone.utc) == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
)
)
.subquery()
Expand Down Expand Up @@ -237,9 +237,9 @@ def get_my_votes_list(self, user_id: int, start_cursor: tuple[datetime,int] |Non
filtered_votes = (
select(Vote.id)
.where(
(Vote.create_datetime < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
(Vote.create_datetime.replace(tzinfo=timezone.utc) < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
| (
(Vote.create_datetime == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
(Vote.create_datetime.replace(tzinfo=timezone.utc) == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
)
)
.where(Vote.writer_id == user_id)
Expand Down Expand Up @@ -293,9 +293,9 @@ def get_participated_votes_list(self, user_id: int, start_cursor: tuple[datetime
.join(Choice, Choice.vote_id == Vote.id)
.where(ChoiceParticipation.user_id == user_id)
.where(
(Vote.create_datetime < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
(Vote.create_datetime.replace(tzinfo=timezone.utc) < start_cursor[0]) # 생성 시간이 커서보다 과거이거나
| (
(Vote.create_datetime == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
(Vote.create_datetime.replace(tzinfo=timezone.utc) == start_cursor[0]) & (Vote.id > start_cursor[1]) # 생성 시간이 커서와 같은데 id가 더 큰 경우
)
)
.subquery()
Expand Down

0 comments on commit 03cc6bc

Please sign in to comment.