Skip to content

Commit 0e83810

Browse files
committed
[fix] gnuboard#624 REST API > 최근 게시물 목록 출력 양식 수정
- Response Model 적용 출력 json key 제한 (gnuboard#624 wr_password 제거) - 개별글 정보: 게시판 목록과 같은 양식으로 출력 - mb_image, mb_icon, good, nogood 정보 출력
1 parent 87e4ac8 commit 0e83810

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

api/v1/models/board.py

+8
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ class ResponseBoardListModel(PaginationResponse):
284284
next_spt: Union[int, None]
285285

286286

287+
class ResponseTotalBoardNewListModel(BaseModel):
288+
"""최신글 목록 모델"""
289+
free: List[ResponseWriteModel]
290+
gallery: List[ResponseWriteModel]
291+
qa: List[ResponseWriteModel]
292+
notice: List[ResponseWriteModel]
293+
294+
287295
class ResponseGroupModel(BaseModel):
288296
"""게시판 그룹 모델"""
289297
gr_id: str

api/v1/routers/board_new.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from api.v1.dependencies.member import get_current_member
1111
from api.v1.models.response import response_401, response_422
1212
from api.v1.models.board import (
13-
BoardNewViewType, RequestBoardNewWrites, ResponseNormalModel, ResponseBoardNewListModel
13+
BoardNewViewType, RequestBoardNewWrites, ResponseNormalModel,
14+
ResponseBoardNewListModel, ResponseTotalBoardNewListModel,
15+
ResponseWriteModel
1416
)
1517
from lib.common import get_paging_info
1618
from service.board_new import BoardNewServiceAPI
@@ -57,7 +59,7 @@ async def api_board_new_list(
5759
async def api_latest_posts(
5860
service: Annotated[BoardNewServiceAPI, Depends()],
5961
data: RequestBoardNewWrites = Depends(),
60-
):
62+
) -> ResponseTotalBoardNewListModel:
6163
"""
6264
모든 게시판의 최신글을 조회합니다.
6365
"""
@@ -74,12 +76,12 @@ async def api_latest_posts_by_board(
7476
service: Annotated[BoardNewServiceAPI, Depends()],
7577
bo_table: Annotated[str, Path(..., title="게시판 코드", description="게시판 코드")],
7678
data: RequestBoardNewWrites = Depends(),
77-
):
79+
) -> List[ResponseWriteModel]:
7880
"""
7981
최신글을 게시판별로 조회합니다.
8082
"""
8183
latest_posts = service.get_latest_posts([bo_table], data.view_type.value, data.rows)
82-
return latest_posts
84+
return latest_posts[bo_table]
8385

8486

8587
@router.post("/delete",

service/board_new/board_new.py

+12
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from lib.common import dynamic_create_write_table, cut_name, FileCache
1010
from lib.board_lib import BoardConfig, get_list, get_list_thumbnail
1111
from service import BaseService
12+
from service.ajax.ajax import AJAXService
1213
from service.board_file_service import BoardFileService
1314
from service.point_service import PointService
15+
from api.v1.service.member import MemberImageServiceAPI
1416

1517

1618
class BoardNewService(BaseService):
@@ -143,6 +145,16 @@ def get_latest_posts(
143145
write.images, write.normal_files = self.file_service.get_board_files_by_type(bo_table, write.wr_id)
144146
# 썸네일 이미지 설정
145147
write.thumbnail = get_list_thumbnail(request, board, write, board_config.gallery_width, board_config.gallery_height)
148+
149+
# 회원 이미지, 아이콘 경로 설정
150+
write.mb_image_path = MemberImageServiceAPI.get_image_path(write.mb_id)
151+
write.mb_icon_path = MemberImageServiceAPI.get_icon_path(write.mb_id)
152+
153+
# 게시글 좋아요/싫어요 정보 설정
154+
ajax_good_data = AJAXService(self.request, self.db).get_ajax_good_data(bo_table, write)
155+
write.good = ajax_good_data["good"]
156+
write.nogood = ajax_good_data["nogood"]
157+
146158
boards_info[bo_table] = writes
147159

148160
return boards_info

0 commit comments

Comments
 (0)