Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add top article feature #385

Merged
merged 15 commits into from
Jul 2, 2023
Merged

Add top article feature #385

merged 15 commits into from
Jul 2, 2023

Conversation

injoonH
Copy link
Member

@injoonH injoonH commented May 18, 2023

게시판을 불러오는 방식

(Top Articles): GET /articles/top/
(Others): GET /articles/?parent_board=<id>

핫 게시물이 되는 조건

  1. boards table에 좋아요 개수 threshold field 추가 후 넘었는지 여부로 평가
    1. threshold 넘지 않았어도 어드민 페이지에서 인기글로 수정 가능합니다.

Model

  1. Article

    topped_at field를 추가하였습니다.

    topped_at = models.DateTimeField(
        verbose_name="인기글 달성 시각",
        blank=True,
        null=True,
        default=None,
    )
  2. Board

    top_threshold field를 추가하였습니다.

    top_threshold = models.SmallIntegerField(
        verbose_name="인기글 달성 기준 좋아요 개수",
        default=10,
    )
  3. Article.update_vote_status()

    vote가 업데이트될 때 1. 기존에 인기글이 아니었고 2. 좋아요 개수가 threshold 개수를 넘었다면 인기글로 전환합니다. (전환 시각을 저장합니다.)

    def update_vote_status(self) -> None:
        if (
            self.topped_at is None
            and self.positive_vote_count >= self.parent_board.top_threshold
        ):
            self.topped_at = timezone.now()

Viewset

  1. ArticleViewSet

    @decorators.action(detail=False, methods=["get"])
    def top(self, request):
        top_articles = Article.objects.exclude(topped_at__isnull=True)
        page = self.paginate_queryset(top_articles)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)
    
        serializer = self.get_serializer(top_articles, many=True)
        return response.Response(data=serializer.data, status=status.HTTP_200_OK)

@injoonH injoonH requested a review from retroinspect May 18, 2023 09:10
@injoonH injoonH self-assigned this May 18, 2023
@retroinspect
Copy link
Contributor

카드

@retroinspect
Copy link
Contributor

retroinspect commented May 18, 2023

정책적 결정

  1. 현재로써는 기존의 인기글들을 따로 인기글 게시판에 올리지 않는다
  2. 좋아요 했다가 취소해서 인기글 기준을 만족하지 않게 되어도 인기글 게시판에서 내려가지 않는다
  3. 게시판의 인기글 threshold를 바꾸었을 때도 즉각적으로 인기글이 생기거나 없어지지는 않고, 좋아요가 눌릴 때마다 인기글 threshold를 넘는지 계산하여 인기글로 만든다.

Copy link
Contributor

@retroinspect retroinspect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정렬 로직 추가하고 테스트 작성하면 될 듯 합니다

@injoonH injoonH dismissed retroinspect’s stale review July 2, 2023 12:41

Added ordering logic and tests.

Copy link
Contributor

@retroinspect retroinspect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@injoonH injoonH merged commit 5d8937a into develop Jul 2, 2023
@injoonH injoonH deleted the feat/top-articles branch July 2, 2023 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants