log.py 1.06 KB
Newer Older
崔为之's avatar
崔为之 committed
1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# @Version     : Python 3.11.4
# @Software    : Sublime Text 4
# @Author      : StudentCWZ
# @Email       : StudentCWZ@outlook.com
# @Date        : 2023/11/19 16:05
# @File        : log.py
# @Description :
"""

崔为之's avatar
崔为之 committed
13
from flask import Blueprint, current_app, request, jsonify
崔为之's avatar
崔为之 committed
14 15 16 17 18 19 20
from flask_restful import Api
from loguru import logger
from pydantic import ValidationError

from application.schemas import ParseLogRequestItem
from application.services import LogService

崔为之's avatar
崔为之 committed
21

崔为之's avatar
崔为之 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
log_api = Blueprint('log_api', __name__)
api_logs = Api(log_api)


@log_api.route('/logs', methods=['POST'])
def parse():
    json_data = request.get_json(force=True)
    if not json_data:
        logger.error('No input data provided')
        return jsonify({"message": "No input data provided"}), 400

    try:
        item = ParseLogRequestItem(**json_data)
    except ValidationError as e:
        return jsonify({"message": "Invalid input data", "errors": e.errors()}), 400

    total = LogService.parse(item)
    return jsonify(
        search_total=total
    ), 200
崔为之's avatar
崔为之 committed
42