v2.1: 标签系统增删改、分类编辑功能

This commit is contained in:
2026-05-23 12:01:45 +08:00
parent 87286986ea
commit 2e8bfea262
3 changed files with 181 additions and 4 deletions

24
app.py
View File

@@ -390,6 +390,30 @@ def create_tag():
return jsonify(dict(tag))
@app.route('/api/tags/<tag_id>', methods=['PUT'])
def update_tag(tag_id):
data = request.get_json(force=True)
conn = get_db()
tag = conn.execute('SELECT * FROM tags WHERE id=?', (tag_id,)).fetchone()
if not tag:
conn.close()
return jsonify({'error': '标签不存在'}), 404
name = data.get('name', '').strip()
if not name:
conn.close()
return jsonify({'error': '标签名不能为空'}), 400
# 检查重名(排除自身)
existing = conn.execute('SELECT id FROM tags WHERE name=? AND id!=?', (name, tag_id)).fetchone()
if existing:
conn.close()
return jsonify({'error': '标签名已存在'}), 400
conn.execute('UPDATE tags SET name=? WHERE id=?', (name, tag_id))
conn.commit()
tag = conn.execute('SELECT * FROM tags WHERE id=?', (tag_id,)).fetchone()
conn.close()
return jsonify(dict(tag))
@app.route('/api/tags/<tag_id>', methods=['DELETE'])
def delete_tag(tag_id):
conn = get_db()