def create_attachment( self, post_id: int, type: str, file_name: str, path: str, extension: str, uuid: str, ) -> Optional[AttachmentEntity]: try: attachment = AttachmentModel( post_id=post_id, type=type, file_name=file_name, path=path, extension=extension, uuid=uuid, ) session.add(attachment) session.commit() return attachment.to_entity() if attachment else None except Exception as e: session.rollback() logger.error( f"[BoardRepository][create_attachment] post_id : {post_id} type : {type} file_name : {file_name} " f"path : {path} extension : {extension} uuid : {uuid} error : {e}" ) return None
def create_post(self, dto: CreatePostDto) -> Optional[PostEntity]: try: post = PostModel( user_id=dto.user_id, title=dto.title, region_group_id=dto.region_group_id, type=dto.type, is_comment_disabled=dto.is_comment_disabled, amount=dto.amount, unit=dto.unit, price_per_unit=dto.price_per_unit, status=dto.status, ) session.add(post) session.commit() article = ArticleModel(post_id=post.id, body=dto.body) session.add(article) session.commit() self.create_post_categories(post_id=post.id, dto=dto) return post.to_entity() except Exception as e: logger.error( f"[BoardRepository][create_post] user_id : {dto.user_id} title : {dto.title} " f"region_group_id : {dto.region_group_id} type : {dto.type} " f"is_comment_disabled : {dto.is_comment_disabled} amount : {dto.amount} unit : {dto.unit} " f"price_per_unit : {dto.price_per_unit} status : {dto.status} error : {e}" ) session.rollback() return None
def create_user(self, username: str = None, password: str = None) -> UserModels: hash = bcrypt.generate_password_hash(password).decode("utf-8") user = UserModels(username=username, password=hash) session.add(user) session.commit() return user.to_entity()
def create_board(self, dto: CreateBoardDto = None) -> Board: board = BoardModels(title=dto.title, body=dto.body, user_id=dto.user_id, is_deleted=False) session.add(board) session.commit() return board.to_entity()
def create_post_like_count(self, post_id) -> Optional[PostLikeCountEntity]: try: post_like_count = PostLikeCountModel(post_id=post_id) session.add(post_like_count) session.commit() return post_like_count.to_entity() except Exception as e: logger.error( f"[BoardRepository][create_post_like_count] post_id : {post_id} error : {e}" ) session.rollback() return None
def create_post_like_state(self, user_id: int, post_id: int): try: post_like_state = PostLikeStateModel( user_id=user_id, post_id=post_id, state=PostLikeStateEnum.LIKE.value) session.add(post_like_state) session.commit() return self.get_post_like_state(user_id=user_id, post_id=post_id) except Exception as e: logger.error( f"[BoardRepository][create_post_like_state] post_id : {post_id} user_id : {user_id} error : {e}" ) session.rollback() return False
def create_notification_history( self, notification_list: List[NotificationHistoryDto] ) -> None: try: for dto in notification_list: notification_history = NotificationHistoryModel( user_id=dto.user_id, status=dto.status, type=dto.type, category=dto.category, message=dto.message, ) session.add(notification_history) session.commit() self._set_notification_info(notification_history.id, dto.message) except Exception as e: # TODO : log e 필요 print("-------------------> ", e) session.rollback()
def create_post_report( self, dto: CreatePostReportDto) -> Optional[PostReportEntity]: try: post_report = PostReportModel( post_id=dto.post_id, report_user_id=dto.report_user_id, status=dto.status, context=dto.status, confirm_admin_id=dto.confirm_admin_id, is_system_report=dto.is_system_report, ) session.add(post_report) session.commit() return post_report.to_entity() if post_report else None except Exception as e: logger.error( f"[ReportRepository][create_post_report] post_id : {dto.post_id} report_user_id : {dto.report_user_id} " f"error : {e}") session.rollback() return None