创建新模板
()
| 353 | |
| 354 | @api.route('/api/v1/template', methods=['POST']) |
| 355 | def create_template_api(): |
| 356 | """创建新模板""" |
| 357 | try: |
| 358 | data = request.get_json() |
| 359 | if not data or 'template_name' not in data: |
| 360 | return jsonify({'error': 'Missing template_name'}), 400 |
| 361 | |
| 362 | template_name = data['template_name'].strip() |
| 363 | if not template_name: |
| 364 | return jsonify({'error': 'template_name cannot be empty'}), 400 |
| 365 | |
| 366 | content = data.get('content', '[]') |
| 367 | |
| 368 | # 检查模板是否已存在 |
| 369 | existing_templates = list_templates() |
| 370 | if template_name in existing_templates: |
| 371 | return jsonify({'error': f'Template "{template_name}" already exists'}), 409 |
| 372 | |
| 373 | # 保存新模板 |
| 374 | save_template(template_name, content) |
| 375 | |
| 376 | return jsonify({'message': f'Template "{template_name}" created successfully'}), 201 |
| 377 | |
| 378 | except FileExistsError: |
| 379 | return jsonify({'error': f'Template already exists'}), 409 |
| 380 | except Exception as e: |
| 381 | return jsonify({'error': str(e)}), 500 |
| 382 | |
| 383 | |
| 384 | @api.route('/api/v1/templates', methods=['GET']) |
nothing calls this directly
no test coverage detected