def mutate(root, info, mode, name): # MongoDB에서 삭제 RankModel.objects(mode=mode, name=name).delete() # 삭제되었는지 확인 success = RankModel.objects(mode=mode, name=name).first() == None # 결과 반환 return DeleteRank(success=success)
def mutate(root, info, **input): # MongoDB Model 생성 model = RankModel( mode=input.get("mode"), name=input.get("name"), score=input.get("score"), is_mobile=input.get("is_mobile"), reg_dttm=datetime.datetime.now().strftime("%Y%m%d%H%M%S") # 현재시간 ) # MongoDB에 저장 model.save() # 결과 반환 return CreateRank(rank=model, success=True)
def init_db(): for idx in range(1, 5): RankModeModel(mode=f"{ idx }x{ idx }").save() for idx in range(1000): RankModel(name="heo", mode="4x4", score=idx, is_mobile=False, reg_dttm="20200413170848").save()
def resolve_ranks(parent, info, page, count_for_rows, **kwargs): order = kwargs.get("order") if "order" in kwargs else list() search = kwargs.get("search") if "search" in kwargs else dict() page = page if page > 0 else 1 count_for_rows = count_for_rows if count_for_rows > 0 else 10 skip = (page - 1) * count_for_rows model = RankModel.objects(**search).order_by( *order).skip(skip).limit(count_for_rows) return model
def mutate(root, info, mode, name, data): # 수정할 MongoDB Model 조회 model = RankModel.objects(mode=mode, name=name).first() # 입력받은 파라미터로 수정 if data.score is not None: model.score = data.score if data.is_mobile is not None: model.is_mobile = data.is_mobile model.upd_dttm = datetime.datetime.now().strftime("%Y%m%d%H%M%S") # MongoDB에 저장 model.save() # 결과 반환 return UpdateRank(rank=model, success=True)
def resolve_ranking(cls, root, info, **input) -> RankConnection: # Pagination page = input.get("page") if "page" in input else 1 count_for_rows = input.get( "count_for_rows") if "count_for_rows" in input else 10 order = input.get("order") if "order" in input else list() skip = (page - 1) * count_for_rows # Mongo Object Parse to Edge conn_type = cls.ranking.type node_name = conn_type._meta.node._meta.name datas = RankModel.objects(mode=root.mode).all() nodes = datas.order_by(*order).skip(skip).limit(count_for_rows) edges = [ conn_type.Edge(node=node, cursor=base64(f"{ node_name }:{ str(node.id) }")) for node in nodes ] # Create new RankConnection Object return conn_type(edges=edges, page_info=relay.PageInfo(has_previous_page=True, has_next_page=True), total_count=len(datas))
def get_node_from_global_id(info, global_id, only_type=None): _type, id = global_id.split(":") if only_type: assert _type == only_type._meta.name, 'Received not compatible node.' return RankModel.objects(id=id).first()