예제 #1
0
def list(request):
    try:
        parameters = request.GET.dict()
        validate_optional_parameters(parameters, ['since', 'limit', 'order'], [None, None, 'desc'])
        if 'forum' in parameters and 'thread' not in parameters:
            from technopark_db_api_app.queries import forum_queries

            posts = forum_queries.getPostsList(parameters['forum'],
                                               parameters['since'],
                                               parameters['order'],
                                               parameters['limit'], [])
        elif 'thread' in parameters and 'forum' not in parameters:
            from technopark_db_api_app.queries import thread_queries

            posts = thread_queries.getPostsList(parameters['thread'],
                                                parameters['since'],
                                                parameters['order'],
                                                parameters['limit'])
        else:
            raise Exception("Wrong required parameters")
        response_json = {
            'code': 0,
            'response': posts,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')
예제 #2
0
def create(request):
    try:
        parameters = json.loads(request.body, encoding='utf-8')
        validate_required_parameters(parameters, ['date', 'thread', 'message', 'user', 'forum'])
        validate_optional_parameters(parameters,
                                     ['parent', 'isApproved', 'isHighlighted', 'isEdited', 'isSpam', 'isDeleted'],
                                     [None, False, False, False, False, False])
        post_queries.addPost(parameters['forum'],
                             parameters['thread'],
                             parameters['user'],
                             parameters['message'],
                             parameters['date'],
                             parameters['parent'],
                             parameters['isApproved'],
                             parameters['isHighlighted'],
                             parameters['isEdited'],
                             parameters['isSpam'],
                             parameters['isDeleted'])
        post = post_queries.getAddedPost(parameters['forum'],
                                         parameters['thread'],
                                         parameters['user'],
                                         parameters['date'])
        response_json = {
            'code': 0,
            'response': post,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')
예제 #3
0
def create(request):
    try:
        parameters = json.loads(request.body, encoding='utf-8')
        validate_required_parameters(parameters, ['forum', 'title', 'isClosed', 'user', 'date', 'message', 'slug'])
        validate_optional_parameters(parameters, ['isDeleted'], [False])

        thread_queries.addThread(parameters['forum'],
                                 parameters['slug'],
                                 parameters['title'],
                                 parameters['message'],
                                 parameters['user'],
                                 parameters['date'],
                                 parameters['isClosed'],
                                 parameters['isDeleted'])
        thread = thread_queries.getAddedThread(parameters['forum'], parameters['slug'])
        response_json = {
            'code': 0,
            'response': thread,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')
예제 #4
0
def details(request):
    try:
        parameters = request.GET.dict()
        validate_required_parameters(parameters, ['forum'])
        validate_optional_parameters(parameters, ['related'], [[]])
        forum = forum_queries.getDetailedForum(parameters['forum'], parameters['related'])
        response_json = {
            'code': 0,
            'response': forum,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')
예제 #5
0
def listPosts(request):
    try:
        parameters = request.GET.dict()
        validate_required_parameters(parameters, ['thread'])
        validate_optional_parameters(parameters, ['since', 'limit', 'order'], [None, None, 'desc'])
        threads = thread_queries.getPostsList(parameters['thread'],
                                           parameters['since'],
                                           parameters['order'],
                                           parameters['limit'])
        response_json = {
            'code': 0,
            'response': threads,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')