-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactoring boards #462
Closed
Closed
Refactoring boards #462
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4eea55c
add : base layer for domain and infra
hyukychang 432f024
feat: infra structure layer of board
hyukychang dfc89bd
feat: add domain, infra, service layer
hyukychang 61041c5
fix: change name
hyukychang f2403e6
feat: add constants in controller
hyukychang aa340ff
fix: change to AraDjangoInfra due to rebase
hyukychang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from ara.domain.board.type import BoardInfo | ||
from ara.infra.board.board_infra import BoardInfra | ||
|
||
|
||
class BoardDomain: | ||
def __init__(self) -> None: | ||
self.board_infra = BoardInfra() | ||
|
||
def get_all_boards(self) -> list[BoardInfo]: | ||
return self.board_infra.get_all_boards() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from enum import IntEnum, IntFlag, auto | ||
|
||
|
||
class BoardAccessPermissionType(IntEnum): | ||
READ = 0 | ||
WRITE = 1 | ||
COMMENT = 2 | ||
|
||
|
||
class NameType(IntFlag): | ||
REGULAR = auto() | ||
ANONYMOUS = auto() | ||
REALNAME = auto() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import BaseModel | ||
|
||
from ara.domain.board.constants import NameType | ||
|
||
|
||
class BoardGroupInfo(BaseModel): | ||
id: int | ||
ko_name: str | ||
en_name: str | ||
slug: str | ||
|
||
|
||
class TopicInfo(BaseModel): | ||
slug: str | ||
ko_name: str | ||
en_name: str | ||
|
||
|
||
class BoardInfo(BaseModel): | ||
id: int | ||
created_at: datetime | ||
updated_at: datetime | ||
deleted_at: datetime | ||
slug: str | ||
ko_name: str | ||
en_name: str | ||
# TODO(hyuk): 이거 group_has_access_permission 여기 잘보고 뭐 할거 판단 | ||
read_access_mask: int | ||
write_access_mask: int | ||
comment_access_mask: int | ||
is_readonly: bool | ||
is_hidden: bool | ||
name_type: NameType | ||
is_school_communication: int | ||
group: BoardGroupInfo | ||
banner_image: str | ||
ko_banner_description: str | ||
en_banner_description: str | ||
top_threshold: int | ||
topics: list[TopicInfo] | ||
|
||
class Config: | ||
arbitrary_types_allowed = True |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from apps.core.models.board import Board | ||
from apps.core.models.board_group import BoardGroup | ||
from ara.domain.board.type import BoardGroupInfo, BoardInfo, TopicInfo | ||
from ara.infra.django_infra import AraDjangoInfra | ||
|
||
|
||
class BoardGroupInfra(AraDjangoInfra[BoardGroup]): | ||
def __init__(self) -> None: | ||
super().__init__(Board) | ||
|
||
pass | ||
|
||
|
||
class BoardInfra(AraDjangoInfra[Board]): | ||
def __init__(self) -> None: | ||
super().__init__(Board) | ||
self.board_group_infra = BoardGroupInfra() | ||
|
||
def get_all_boards(self) -> list[BoardInfo]: | ||
queryset = Board.objects.select_related("group").extra( | ||
select={ | ||
"topic_id": "topic.id", | ||
"topic_slug": "topic.slug", | ||
"topic_ko_name": "topic.ko_name", | ||
"topic_en_name": "topic.en_name", | ||
}, | ||
tables=[ | ||
"core_board` AS `b` LEFT OUTER JOIN `core_topic` AS `topic`" | ||
" ON `b`.`id` = `topic`.`parent_board_id" | ||
], | ||
where=["b.id = core_board.id"], | ||
) | ||
|
||
d: dict[BoardInfo, BoardInfo] = {} | ||
for board_model in queryset: | ||
board_info = self._to_board_without_topics(board_model) | ||
if board_info.id in d.keys(): | ||
d[board_info.id].topics.append( | ||
TopicInfo( | ||
slug=board_model.topic_slug, | ||
ko_name=board_model.topic_ko_name, | ||
en_name=board_model.topic_en_name, | ||
) | ||
) | ||
else: | ||
if board_model.topic_id is None: | ||
d[board_info.id] = board_info | ||
else: | ||
board_info_with_topic = board_info | ||
board_info_with_topic.topics.append( | ||
TopicInfo( | ||
slug=board_model.topic_slug, | ||
ko_name=board_model.topic_ko_name, | ||
en_name=board_model.topic_en_name, | ||
) | ||
) | ||
d[board_info.id] = board_info_with_topic | ||
|
||
return [info for info in d.values()] | ||
|
||
def _to_board_without_topics(self, board: Board) -> BoardInfo: | ||
return BoardInfo( | ||
id=board.id, | ||
created_at=board.created_at, | ||
updated_at=board.updated_at, | ||
deleted_at=board.deleted_at, | ||
slug=board.slug, | ||
ko_name=board.ko_name, | ||
en_name=board.en_name, | ||
read_access_mask=board.read_access_mask, | ||
write_access_mask=board.write_access_mask, | ||
comment_access_mask=board.comment_access_mask, | ||
is_readonly=board.is_readonly, | ||
is_hidden=board.is_hidden, | ||
name_type=board.name_type, | ||
is_school_communication=board.is_school_communication, | ||
group=BoardGroupInfo( | ||
id=board.group.id, | ||
ko_name=board.group.ko_name, | ||
en_name=board.group.en_name, | ||
slug=board.group.slug, | ||
), | ||
banner_image=board.banner_image.url, | ||
ko_banner_description=board.ko_banner_description, | ||
en_banner_description=board.en_banner_description, | ||
top_threshold=board.top_threshold, | ||
topics=[], | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from ara.domain.board.board_domain import BoardDomain | ||
from ara.domain.board.type import BoardInfo | ||
|
||
|
||
class BoardService: | ||
def __init__(self) -> None: | ||
self.board_domain = BoardDomain() | ||
|
||
def get_all_boards(self) -> list[BoardInfo]: | ||
return self.board_domain.get_all_boards() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hyukychang
AraDjangoInfra
가 뭔가요?