def users_search(request, oauth_params): r""" **/users/search** 사용자 검색 method * GET * oauth required parameter * **q** (필수): 검색 질의어 note * 검색어를 화이트 스페이스를 기준으로 토큰화 하여, 토큰이 숫자인 경우 학번으로, 영문인 경우 아이디 및 이름으로, 한글인 경우 이름으로 분류, 각 분류 내 OR 연산, 분류 별 AND 연산으로 검색함. (ex. q="99 98 준" : 1998 또는 1999 학번 중 이름에 '준'이라는 글자가 포함된 회원 검색) * 학번을 두 자리로 입력한 경우, 50보다 작으면 20XX 학번으로, 50보다 크거나 같으면 19XX 학번으로 검색. * 결과는 최대 200건을 반환한다. example * request .. parsed-literal:: GET /users/search?q=99 HTTP/1.1 * response (성공) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 [ { "name": "박종필", "mobile": "123-4567-8900", "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "introduce": "", "id": "jeppy", "birthday": null, "messenger": "MSN:[email protected]", "homepage": "jeppy.cafe24.com", "email": "*****@*****.**", "entrance_year": 1999 }, ... { "name": "강석천", "mobile": null, "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "introduce": null, "id": "reset", "birthday": null, "messenger": null, "homepage": null, "email": null, "entrance_year": 1999 } ] """ try: q = request.GET["q"] except KeyError as e: raise RequiredParameterDoesNotExist(e) try: users = User.search(q) except NoMatchingResult: users = [] ret = dumps(users[:200]) return HttpResponse(ret, content_type="application/json")
def users_show(request, oauth_params, user_id=None): r""" **/users/show/<user_id>** 사용자 조회 method * GET * oauth required note * user_id 생략시, oauth 인증된 사용자 정보 반환 example * request .. parsed-literal:: GET /users/show/gochi HTTP/1.1 * response (성공) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "name": "이덕준", "mobile": "123-4567-8900", "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "introduce": "", "id": "gochi", "birthday": null, "messenger": "google talk : [email protected]", "homepage": "gochi.kr", "email": "*****@*****.**", "entrance_year": 1999 } * response (실패) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "error", "message": "user_id가 올바르지 않습니다.", "type": "<class 'apiprj.exceptions.ParameterIsNotValid'>" } """ if not user_id: if request.GET.has_key("user_id"): user_id = request.GET["user_id"] else: oauth_token = oauth_params["oauth_token"] user_id = Token.get_user_id(oauth_token) try: user = User.get(user_id) except ObjectDoesNotExist: raise ParameterIsNotValid("user_id가 올바르지 않습니다.") ret = dumps(user) return HttpResponse(ret, content_type="application/json")
def boards_favorite(request, oauth_params): r""" **/boards/favorite** 즐겨찾는 게시판 리스트 반환 method * GET * oauth required note * 즐겨찾는 게시판은 즐겨찾기 등록된 게시판 및 자유게시판과 가입한 cafe의 게시판을 포함한다. example * request (oauth parameter는 예제에서 생략) .. parsed-literal:: GET /boards/favorite HTTP/1.1 * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 [ { "board_id": "board_freeboard", "count": 10147, "description": "", "title": "자유게시판", "admin": "anjae83", "count24h": 0 }, ... { "board_id": "photo_part_plan", "count": 1670, "description": "", "title": "기획총무부 사진 게시판", "admin": "hyojeong28", "count24h": 0 } ] """ def join_list(list1, list2): return list1 + [item for item in list2 if item not in list1] oauth_token = oauth_params["oauth_token"] user_id = Token.get_user_id(oauth_token) # add default default_list = ["board_freeboard"] # add favorites favorites = Favorite.get_by_user(user_id) favorite_list = map(lambda x: x.get("board_id"), favorites) # add cafe cafe_board_list = [] cafe_boards = [Cafe.get_boards(cafe_id) for cafe_id in User.get_cafe(user_id)] if cafe_boards: cafe_board_list = reduce(lambda x, y: x + y, cafe_boards) # merge default, favorite, cafe list board_list = reduce(join_list, (default_list, favorite_list, cafe_board_list)) # get boards boards = filter(None, map(Board.get_or_none, board_list)) ret = dumps(boards) return HttpResponse(ret, content_type="application/json")
def users_search(request, oauth_params): r""" **/users/search** 사용자 검색 method * GET * oauth required parameter * **q** (필수): 검색 질의어 note * 검색어를 화이트 스페이스를 기준으로 토큰화 하여, 토큰이 숫자인 경우 학번으로, 영문인 경우 아이디 및 이름으로, 한글인 경우 이름으로 분류, 각 분류 내 OR 연산, 분류 별 AND 연산으로 검색함. (ex. q="99 98 준" : 1998 또는 1999 학번 중 이름에 '준'이라는 글자가 포함된 회원 검색) * 학번을 두 자리로 입력한 경우, 50보다 작으면 20XX 학번으로, 50보다 크거나 같으면 19XX 학번으로 검색. * 결과는 최대 200건을 반환한다. example * request .. parsed-literal:: GET /users/search?q=99 HTTP/1.1 * response (성공) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 [ { "name": "박종필", "mobile": "123-4567-8900", "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "introduce": "", "id": "jeppy", "birthday": null, "messenger": "MSN:[email protected]", "homepage": "jeppy.cafe24.com", "email": "*****@*****.**", "entrance_year": 1999 }, ... { "name": "강석천", "mobile": null, "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "introduce": null, "id": "reset", "birthday": null, "messenger": null, "homepage": null, "email": null, "entrance_year": 1999 } ] """ try: q = request.GET['q'] except KeyError as e: raise RequiredParameterDoesNotExist(e) try: users = User.search(q) except NoMatchingResult: users = [] ret = dumps(users[:200]) return HttpResponse(ret, content_type='application/json')
def users_show(request, oauth_params, user_id=None): r""" **/users/show/<user_id>** 사용자 조회 method * GET * oauth required note * user_id 생략시, oauth 인증된 사용자 정보 반환 example * request .. parsed-literal:: GET /users/show/gochi HTTP/1.1 * response (성공) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "name": "이덕준", "mobile": "123-4567-8900", "img_url": "http://s.twimg.com/a/1278188204/images/default_profile_0_normal.png", "introduce": "", "id": "gochi", "birthday": null, "messenger": "google talk : [email protected]", "homepage": "gochi.kr", "email": "*****@*****.**", "entrance_year": 1999 } * response (실패) .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 { "status": "error", "message": "user_id가 올바르지 않습니다.", "type": "<class 'apiprj.exceptions.ParameterIsNotValid'>" } """ if not user_id: if request.GET.has_key('user_id'): user_id = request.GET['user_id'] else: oauth_token = oauth_params['oauth_token'] user_id = Token.get_user_id(oauth_token) try: user = User.get(user_id) except ObjectDoesNotExist: raise ParameterIsNotValid("user_id가 올바르지 않습니다.") ret = dumps(user) return HttpResponse(ret, content_type='application/json')
def boards_favorite(request, oauth_params): r""" **/boards/favorite** 즐겨찾는 게시판 리스트 반환 method * GET * oauth required note * 즐겨찾는 게시판은 즐겨찾기 등록된 게시판 및 자유게시판과 가입한 cafe의 게시판을 포함한다. example * request (oauth parameter는 예제에서 생략) .. parsed-literal:: GET /boards/favorite HTTP/1.1 * response .. parsed-literal:: HTTP/1.0 200 OK Content-Type: application/json; charset=utf-8 [ { "board_id": "board_freeboard", "count": 10147, "description": "", "title": "자유게시판", "admin": "anjae83", "count24h": 0 }, ... { "board_id": "photo_part_plan", "count": 1670, "description": "", "title": "기획총무부 사진 게시판", "admin": "hyojeong28", "count24h": 0 } ] """ def join_list(list1, list2): return list1 + [item for item in list2 if item not in list1] oauth_token = oauth_params['oauth_token'] user_id = Token.get_user_id(oauth_token) # add default default_list = ['board_freeboard'] # add favorites favorites = Favorite.get_by_user(user_id) favorite_list = map(lambda x: x.get('board_id'), favorites) # add cafe cafe_board_list = [] cafe_boards = [ Cafe.get_boards(cafe_id) for cafe_id in User.get_cafe(user_id) ] if cafe_boards: cafe_board_list = reduce(lambda x, y: x + y, cafe_boards) # merge default, favorite, cafe list board_list = reduce(join_list, (default_list, favorite_list, cafe_board_list)) # get boards boards = filter(None, map(Board.get_or_none, board_list)) ret = dumps(boards) return HttpResponse(ret, content_type='application/json')