Esempio n. 1
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')
Esempio n. 2
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')
Esempio n. 3
0
def remove(request):
    try:
        parameters = json.loads(request.body, encoding='utf-8')
        validate_required_parameters(parameters, ['post'])
        post = post_queries.removePost(parameters['post'])
        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')
Esempio n. 4
0
def open(request):
    try:
        parameters = json.loads(request.body, encoding='utf-8')
        validate_required_parameters(parameters, ['thread'])
        thread = thread_queries.openThread(parameters['thread'])
        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')
Esempio n. 5
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')
Esempio n. 6
0
def create(request):
    try:
        parameters = json.loads(request.body, encoding='utf-8')
        validate_required_parameters(parameters, ['name', 'short_name', 'user'])

        forum_queries.addForum(parameters['name'], parameters['short_name'], parameters['user'])
        forum = forum_queries.getAddedForum(parameters['short_name'])
        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')
Esempio n. 7
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')