Skip to content

Commit 21cb0ef

Browse files
committed
[fix] gnuboard#617 REST API > 게시판 조회 - 게시글 페이지당 목록수 수정
per_page 값이 0인 경우 개별 게시판 설정값 사용 개별 게시판 설정값도 0인 경우 config의 기본 설정 값을 사용
1 parent 87e4ac8 commit 21cb0ef

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

api/v1/models/board.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from fastapi import Body, Path, Query
77
from pydantic import BaseModel, ConfigDict, model_validator, Field
88

9-
from api.v1.models.pagination import PaginationResponse
9+
from api.v1.models.pagination import PaginationResponse, PagenationRequest
1010

1111

1212
class WriteModel(BaseModel):
@@ -273,6 +273,21 @@ class ResponseBoardModel(BaseModel):
273273
# bo_10: str
274274

275275

276+
class BoardPaginationRequest(PagenationRequest):
277+
per_page: int = Field(
278+
Query(default=0,
279+
ge=0,
280+
le=100,
281+
title="출력 수",
282+
description="""페이지 당 결과 수 <br>\
283+
최대 100 <br>\
284+
0인 경우 개별 게시판 설정을 따르고 <br>\
285+
개별 게시판 설정도 0인 경우 기본 설정의 값을 따름
286+
"""
287+
)
288+
)
289+
290+
276291
class ResponseBoardListModel(PaginationResponse):
277292
"""게시판 목록 모델"""
278293
categories: list

api/v1/routers/board.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
ResponseBoardListModel, ResponseNormalModel, ResponseCreateWriteModel,
1818
CommentUpdateModel
1919
)
20-
from api.v1.models.pagination import PagenationRequest
20+
from api.v1.models.board import BoardPaginationRequest
2121
from api.v1.service.board import (
2222
ListPostServiceAPI, ReadPostServiceAPI,
2323
CreatePostServiceAPI, UpdatePostServiceAPI, DownloadFileServiceAPI,
@@ -43,19 +43,21 @@
4343
)
4444
async def api_list_post(
4545
service: Annotated[ListPostServiceAPI, Depends(ListPostServiceAPI.async_init)],
46-
pagination: Annotated[PagenationRequest, Depends()]
46+
pagination: Annotated[BoardPaginationRequest, Depends()]
4747
) -> ResponseBoardListModel:
4848
"""
4949
게시판 정보, 글 목록을 반환합니다.
5050
"""
51+
per_page = service.get_board_per_page(pagination.per_page)
52+
5153
writes = service.get_writes(
5254
with_files=True,
5355
page=pagination.page,
5456
per_page=pagination.per_page
5557
)
5658
total_records = service.get_total_count()
5759
paging_info = get_paging_info(
58-
pagination.page, pagination.per_page, total_records
60+
pagination.page, per_page, total_records
5961
)
6062
content = {
6163
"total_records": total_records,

service/board/board.py

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ def get_write(self, wr_id: Union[int, str]) -> WriteBaseModel:
156156

157157
return write
158158

159+
def get_board_per_page(self, per_page = 0):
160+
"""게시판별 페이지당 게시글 수를 가져온다."""
161+
if per_page != 0:
162+
return per_page
163+
if self.board.bo_page_rows != 0:
164+
return self.board.bo_page_rows # 게시판 설정에서 페이지당 게시글 수를 사용
165+
else:
166+
return self.config.cf_page_rows # 상위 클래스(BoardConfig)에서 설정한 페이지당 게시글 수를 사용
167+
159168
def get_parent_post(self, parent_id: int, is_reply: bool = True):
160169
"""부모글 호출"""
161170
if not parent_id:

0 commit comments

Comments
 (0)