feat(admin): 건조시럽 환산계수 관리 페이지 추가
- /admin/drysyrup 페이지 구현 - GET /api/drug-info/drysyrup 전체 목록 API - DELETE /api/drug-info/drysyrup/<sung_code> 삭제 API - 검색, CRUD, 통계 카드 기능
This commit is contained in:
127
backend/app.py
127
backend/app.py
@@ -4145,6 +4145,133 @@ def api_drysyrup_update(sung_code):
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/drug-info/drysyrup', methods=['GET'])
|
||||
def api_drysyrup_list():
|
||||
"""
|
||||
건조시럽 전체 목록 조회 API
|
||||
|
||||
Query params:
|
||||
q: 검색어 (성분명/제품명 검색)
|
||||
|
||||
Returns:
|
||||
{ "success": true, "data": [...] }
|
||||
"""
|
||||
try:
|
||||
session = db_manager.get_postgres_session()
|
||||
if session is None:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'PostgreSQL 연결 실패',
|
||||
'data': []
|
||||
})
|
||||
|
||||
search_query = request.args.get('q', '').strip()
|
||||
|
||||
if search_query:
|
||||
query = text("""
|
||||
SELECT
|
||||
idx,
|
||||
ingredient_code,
|
||||
ingredient_name,
|
||||
product_name,
|
||||
conversion_factor,
|
||||
post_prep_amount,
|
||||
main_ingredient_amt,
|
||||
storage_conditions,
|
||||
expiration_date
|
||||
FROM drysyrup
|
||||
WHERE
|
||||
ingredient_name ILIKE :search
|
||||
OR product_name ILIKE :search
|
||||
OR ingredient_code ILIKE :search
|
||||
ORDER BY ingredient_name, product_name
|
||||
""")
|
||||
rows = session.execute(query, {'search': f'%{search_query}%'}).fetchall()
|
||||
else:
|
||||
query = text("""
|
||||
SELECT
|
||||
idx,
|
||||
ingredient_code,
|
||||
ingredient_name,
|
||||
product_name,
|
||||
conversion_factor,
|
||||
post_prep_amount,
|
||||
main_ingredient_amt,
|
||||
storage_conditions,
|
||||
expiration_date
|
||||
FROM drysyrup
|
||||
ORDER BY ingredient_name, product_name
|
||||
""")
|
||||
rows = session.execute(query).fetchall()
|
||||
|
||||
data = []
|
||||
for row in rows:
|
||||
data.append({
|
||||
'idx': row[0],
|
||||
'sung_code': row[1],
|
||||
'ingredient_name': row[2],
|
||||
'product_name': row[3],
|
||||
'conversion_factor': float(row[4]) if row[4] is not None else None,
|
||||
'post_prep_amount': row[5],
|
||||
'main_ingredient_amt': row[6],
|
||||
'storage_conditions': row[7],
|
||||
'expiration_date': row[8]
|
||||
})
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'data': data,
|
||||
'count': len(data)
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"건조시럽 목록 조회 오류: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': str(e),
|
||||
'data': []
|
||||
}), 500
|
||||
|
||||
|
||||
@app.route('/api/drug-info/drysyrup/<sung_code>', methods=['DELETE'])
|
||||
def api_drysyrup_delete(sung_code):
|
||||
"""
|
||||
건조시럽 삭제 API
|
||||
"""
|
||||
try:
|
||||
session = db_manager.get_postgres_session()
|
||||
if session is None:
|
||||
return jsonify({'success': False, 'error': 'PostgreSQL 연결 실패'}), 500
|
||||
|
||||
# 존재 여부 확인
|
||||
check_query = text("SELECT 1 FROM drysyrup WHERE ingredient_code = :sung_code")
|
||||
existing = session.execute(check_query, {'sung_code': sung_code}).fetchone()
|
||||
|
||||
if not existing:
|
||||
return jsonify({'success': False, 'error': '존재하지 않는 성분코드'}), 404
|
||||
|
||||
# 삭제
|
||||
delete_query = text("DELETE FROM drysyrup WHERE ingredient_code = :sung_code")
|
||||
session.execute(delete_query, {'sung_code': sung_code})
|
||||
session.commit()
|
||||
|
||||
return jsonify({'success': True, 'message': '삭제 완료'})
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"건조시럽 삭제 오류 (SUNG_CODE={sung_code}): {e}")
|
||||
try:
|
||||
session.rollback()
|
||||
except:
|
||||
pass
|
||||
return jsonify({'success': False, 'error': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/admin/drysyrup')
|
||||
def admin_drysyrup():
|
||||
"""건조시럽 환산계수 관리 페이지"""
|
||||
return render_template('admin_drysyrup.html')
|
||||
|
||||
|
||||
# ==================== 입고이력 API ====================
|
||||
|
||||
@app.route('/api/drugs/<drug_code>/purchase-history')
|
||||
|
||||
Reference in New Issue
Block a user