Skip to content

Commit

Permalink
fix(room, checklist): 매매, 주거타입 str로 반환, 크롤링 데이터 수정, state를 status로 변경 (
Browse files Browse the repository at this point in the history
…#43)

* fix(room, checklist): 매매, 주거타입 str로 반환, 크롤링 데이터 수정, state를 status로 변경

* chore: ci오류 해결
  • Loading branch information
parkdaye committed Aug 14, 2020
1 parent 8b16650 commit dd8d103
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 89 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ h2==3.2.0
hpack==3.0.0
hstspreload==2020.7.29
httpcore==0.9.1
httptools==0.1.1 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
httptools==0.1.1; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
httpx==0.13.3
hyperframe==5.2.0
idna==2.10
Expand All @@ -30,5 +30,5 @@ sqlalchemy==1.3.18
starlette==0.13.6
urllib3==1.25.10
uvicorn==0.11.7
uvloop==0.14.0 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
uvloop==0.14.0; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
websockets==8.1
4 changes: 2 additions & 2 deletions src/apps/checklist/models/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Label(IntEnum):
max_length = 50


class StateCategory(str, Enum):
class StatusCategory(str, Enum):
""" 문제 유형 """

Looking = "Looking"
Expand Down Expand Up @@ -57,7 +57,7 @@ class CheckQuestion(OrmModel):
type_: QuestionType
label: str = Field(max_length=Label.max_length)
category: QuestionCategory
state: StateCategory
status: StatusCategory
checks: List[CheckItem]


Expand Down
10 changes: 5 additions & 5 deletions src/apps/checklist/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ...oauth.models.entity import User
from ...persona.models.domain import QuestionCategory, QuestionType
from ...rooms.models.entity import Room
from .domain import Contents, Label, StateCategory, Title
from .domain import Contents, Label, StatusCategory, Title


class CheckItem(Base):
Expand Down Expand Up @@ -151,8 +151,8 @@ class CheckQuestion(Base):
nullable=False,
comment="페르소나 결과와 연결되는 카테고리",
)
state: str = Column(
"state", Enum(StateCategory), nullable=False, comment="방 계약 상태"
status: str = Column(
"status", Enum(StatusCategory), nullable=False, comment="방 계약 상태"
)
checks: List[CheckItem] = relationship(
"CheckItem",
Expand All @@ -167,13 +167,13 @@ def __init__(
type_: QuestionType,
label: str,
category: QuestionCategory,
state: StateCategory,
status: StatusCategory,
) -> None:
self.title = title
self.type_ = type_
self.label = label
self.category = category
self.state = state
self.status = status


class UserChecklist(Base):
Expand Down
6 changes: 3 additions & 3 deletions src/apps/checklist/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..oauth.services import get_current_user
from . import services
from .models.domain import CheckQuestion as CheckQuestionDto
from .models.domain import StateCategory
from .models.domain import StatusCategory
from .models.responses import ChecklistResponse

router = APIRouter()
Expand All @@ -23,13 +23,13 @@
response_model=ChecklistResponse,
)
async def get_checklist(
state: StateCategory,
status: StatusCategory,
current_user: UserInDB = Security(get_current_user),
session: Session = Depends(get_database_session),
) -> ChecklistResponse:

checklist: List[CheckQuestionDto] = services.get_checklist(
user_info=current_user, session=session, state=state
user_info=current_user, session=session, status=status
)

return ChecklistResponse(
Expand Down
12 changes: 6 additions & 6 deletions src/apps/checklist/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
from ..persona.models.domain import ChoiceItem
from ..persona.services import get_user_choices
from .models.domain import CheckQuestion as CheckQuestionDto
from .models.domain import StateCategory
from .models.domain import StatusCategory
from .models.entity import CheckQuestion, UserChecklist


def get_checklist(
user_info: UserInDB, session: Session, state: StateCategory
user_info: UserInDB, session: Session, status: StatusCategory
) -> List[CheckQuestionDto]:
"""사용자의 체크리스트 가져오기"""
user_checklist: List[CheckQuestionDto] = (
session.query(CheckQuestion)
.join(UserChecklist, CheckQuestion.uid == UserChecklist.question_id)
.filter(
(UserChecklist.user_id == user_info.uid)
& (CheckQuestion.state == state)
& (CheckQuestion.status == status)
)
.all()
)
Expand All @@ -28,7 +28,7 @@ def get_checklist(
user_checklist = get_checklist_by_persona(
answers=get_user_choices(user_info=user_info, session=session),
session=session,
state=state,
status=status,
)

for question in user_checklist:
Expand All @@ -42,10 +42,10 @@ def get_checklist(


def get_checklist_by_persona(
answers: List[ChoiceItem], session: Session, state: StateCategory
answers: List[ChoiceItem], session: Session, status: StatusCategory
) -> List[CheckQuestionDto]:
"""페르소나 태그를 통해 체크리스트 질문 필터링"""
checklist: List[CheckQuestionDto] = session.query(CheckQuestion).filter(
CheckQuestion.state == state
CheckQuestion.status == status
).all()
return checklist
36 changes: 29 additions & 7 deletions src/apps/rooms/models/domain/dabang.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime
from enum import IntEnum
from typing import Any, List, Optional

from pydantic import Field
from pydantic.dataclasses import dataclass

from ...exceptions import NoneTypeError
from ..entity import BuildingType, SellingType
from ..domain.landlords import BuildingType, SellingType
from .landlords import RoomItem

image_url = "http://d1774jszgerdmk.cloudfront.net/512/{image_key}"
Expand Down Expand Up @@ -245,7 +246,7 @@ class RoomOption:

@dataclass
class Room:
selling_type: SellingType
selling_type: Optional[int] = None
is_favorited: Optional[Any] = None
favorited_count: Optional[int] = None
seq: Optional[int] = None
Expand Down Expand Up @@ -387,6 +388,21 @@ class User:
role_type: Optional[str] = None


class DabangBuildingType(IntEnum):
OneRoom = 0
TwoRoom = 1
ThreeRoom = 2
Officetel = 3
Apartment = 4
Villa = 5


class DabangSellingType(IntEnum):
MonthlyRent = 0
Jeonse = 1
Selling = 2


@dataclass
class Dabang:
is_messenger_sender_agented: Optional[bool] = None
Expand Down Expand Up @@ -426,23 +442,29 @@ def to_room(self) -> RoomItem:
raise NoneTypeError("건물층수가 없습니다")
if self.room.maintenance_cost_str is None:
raise NoneTypeError("관리비가 없습니다")
if self.room.selling_type is None:
raise NoneTypeError("매매타입이 없습니다")
deposit, monthly_rent, _ = self.room.price_info.pop()
image_key = self.room.photos.pop()

return RoomItem(
uid=f"Dabang::{self.room.id}",
deposit=deposit,
monthly_rent=monthly_rent,
selling_type=SellingType(self.room.selling_type),
selling_type=SellingType(
DabangSellingType(self.room.selling_type).name
),
address=self.room.address,
title=self.room.title,
description=self.room.memo,
image=image_url.format(image_key=image_key),
building_type=BuildingType(self.room.room_type),
building_type=BuildingType(
DabangBuildingType(self.room.room_type).name
),
room_size=self.room.room_size,
floor=f"{self.room.room_floor_str}/{self.room.building_floor_str}",
has_elevator=(self.room.elevator_str == "있음"),
administrative_expenses=int(
self.room.maintenance_cost_str.replace("만 원", "")
),
administrative_expenses=0
if self.room.maintenance_cost_str == "없음"
else int(self.room.maintenance_cost_str.replace("만 원", "")),
)
61 changes: 48 additions & 13 deletions src/apps/rooms/models/domain/landlords.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
from enum import Enum
from enum import Enum, IntEnum
from typing import Optional

from pydantic import BaseModel, Field

from ..entity import (
Address,
AdministrativeExpenses,
BuildingType,
Description,
Floor,
Image,
RoomSize,
SellingType,
Title,
Uid,
)

class Description(IntEnum):
max_length = 3000


class Uid(IntEnum):
max_length = 100


class Address(IntEnum):
max_length = 100


class Title(IntEnum):
max_length = 100


class Image(IntEnum):
max_length = 300


class Floor(IntEnum):
max_length = 20


class AdministrativeExpenses(IntEnum):
max_length = 20


class RoomSize(IntEnum):
max_precision = 7
max_scale = 2


class CrawlingTarget(str, Enum):
Expand All @@ -24,6 +44,21 @@ class CrawlingTarget(str, Enum):
Zigbang = "Zigbang"


class BuildingType(str, Enum):
OneRoom = "OneRoom"
TwoRoom = "TwoRoom"
ThreeRoom = "ThreeRoom"
Officetel = "Officetel"
Apartment = "Apartment"
Villa = "Villa"


class SellingType(str, Enum):
MonthlyRent = "MonthlyRent" # 월세
Jeonse = "Jeonse" # 전세
Selling = "Selling" # 매매


class RoomItem(BaseModel):
uid: str = Field(max_length=Uid.max_length)
deposit: int = Field(...)
Expand Down
5 changes: 2 additions & 3 deletions src/apps/rooms/models/domain/zigbang.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from pydantic import Field
from pydantic.dataclasses import dataclass

from ..entity import BuildingType, SellingType
from .landlords import RoomItem
from .landlords import BuildingType, RoomItem, SellingType

image_url = "https://ic.zigbang.com/ic/items/{uid}/1.jpg?w={width}&h={height}"

Expand Down Expand Up @@ -38,7 +37,7 @@ class Item:
전용면적: Optional[Area] = None
계약면적: Optional[Area] = None
room_type_title: Optional[RoomTypeTitle] = None
floor: int = Field(...)
floor: Optional[str] = None
floor_string: Optional[str] = None
title: Optional[str] = None
address: Optional[str] = None
Expand Down
60 changes: 12 additions & 48 deletions src/apps/rooms/models/entity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,18 @@

from .....core.database import Base
from ....oauth.models.entity import User


class Description(IntEnum):
max_length = 1000


class Uid(IntEnum):
max_length = 100


class Address(IntEnum):
max_length = 100


class Title(IntEnum):
max_length = 100


class Image(IntEnum):
max_length = 300


class BuildingType(IntEnum):
OneRoom = 0
TwoRoom = 1
ThreeRoom = 2
Officetel = 3
Apartment = 4
Villa = 5


class SellingType(IntEnum):
MonthlyRent = 0 # 월세
Jeonse = 1 # 전세
Selling = 2 # 매매


class Floor(IntEnum):
max_length = 20


class AdministrativeExpenses(IntEnum):
max_length = 20


class RoomSize(IntEnum):
max_precision = 7
max_scale = 2
from ..domain.landlords import (
Address,
AdministrativeExpenses,
BuildingType,
Description,
Floor,
Image,
RoomSize,
SellingType,
Title,
Uid,
)


class Room(Base):
Expand Down

0 comments on commit dd8d103

Please sign in to comment.