#!/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 : """ from flask import Blueprint, current_app, request, jsonify from flask_restful import Api from loguru import logger from pydantic import ValidationError from application.schemas import ParseLogRequestItem from application.services import LogService 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