definicion correcta metodos api
This commit is contained in:
@ -65,8 +65,7 @@ def count_news_by_source_in_range(
|
||||
.group_by(NewsItem.fuente)
|
||||
.all()
|
||||
)
|
||||
return {"count_by_source_in_range": results}
|
||||
|
||||
return {"count_by_source_in_range": [{"fuente": fuente, "count": count} for fuente, count in results]}
|
||||
|
||||
@router.get("/news/count/by-author/date-range")
|
||||
def count_news_by_author_in_range(
|
||||
@ -78,8 +77,7 @@ def count_news_by_author_in_range(
|
||||
.group_by(NewsItem.autor)
|
||||
.all()
|
||||
)
|
||||
return {"count_by_author_in_range": results}
|
||||
|
||||
return {"count_by_author_in_range": [{"autor": autor, "count": count} for autor, count in results]}
|
||||
|
||||
@router.get("/news/count/favorable/by-author/date-range")
|
||||
def count_favorable_news_by_author_in_range(
|
||||
@ -95,8 +93,7 @@ def count_favorable_news_by_author_in_range(
|
||||
.group_by(NewsItem.autor)
|
||||
.all()
|
||||
)
|
||||
return {"favorable_count_by_author_in_range": results}
|
||||
|
||||
return {"favorable_count_by_author_in_range": [{"autor": autor, "count": count} for autor, count in results]}
|
||||
|
||||
@router.get("/news/count/unfavorable/by-author/date-range")
|
||||
def count_unfavorable_news_by_author_in_range(
|
||||
@ -112,7 +109,7 @@ def count_unfavorable_news_by_author_in_range(
|
||||
.group_by(NewsItem.autor)
|
||||
.all()
|
||||
)
|
||||
return {"unfavorable_count_by_author_in_range": results}
|
||||
return {"unfavorable_count_by_author_in_range": [{"autor": autor, "count": count} for autor, count in results]}
|
||||
|
||||
@router.get("/news/count/favorable/by-source/date-range")
|
||||
def count_favorable_news_by_source_in_range(
|
||||
@ -128,7 +125,7 @@ def count_favorable_news_by_source_in_range(
|
||||
.group_by(NewsItem.fuente)
|
||||
.all()
|
||||
)
|
||||
return {"favorable_count_by_source_in_range": results}
|
||||
return {"favorable_count_by_source_in_range": [{"fuente": fuente, "count": count} for fuente, count in results]}
|
||||
|
||||
@router.get("/news/count/unfavorable/by-source/date-range")
|
||||
def count_unfavorable_news_by_source_in_range(
|
||||
@ -144,7 +141,7 @@ def count_unfavorable_news_by_source_in_range(
|
||||
.group_by(NewsItem.fuente)
|
||||
.all()
|
||||
)
|
||||
return {"unfavorable_count_by_source_in_range": results}
|
||||
return {"unfavorable_count_by_source_in_range": [{"fuente": fuente, "count": count} for fuente, count in results]}
|
||||
|
||||
@router.get("/news/neutral/date-range")
|
||||
def get_neutral_news_in_range(
|
||||
@ -181,13 +178,29 @@ def get_mixed_news_in_range(
|
||||
|
||||
@router.get("/news/count/by-source")
|
||||
def count_news_by_source(db: Session = Depends(get_db)):
|
||||
results = db.query(NewsItem.fuente, func.count(NewsItem.id)).group_by(NewsItem.fuente).all()
|
||||
return {"count_by_source": results}
|
||||
results = (
|
||||
db.query(NewsItem.fuente, func.count(NewsItem.id))
|
||||
.group_by(NewsItem.fuente)
|
||||
.all()
|
||||
)
|
||||
|
||||
# Convertir resultados en una lista de diccionarios
|
||||
response = [{"fuente": fuente, "count": count} for fuente, count in results]
|
||||
|
||||
return {"count_by_fuente": response}
|
||||
|
||||
@router.get("/news/count/by-author")
|
||||
def count_news_by_author(db: Session = Depends(get_db)):
|
||||
results = db.query(NewsItem.autor, func.count(NewsItem.id)).group_by(NewsItem.autor).all()
|
||||
return {"count_by_author": results}
|
||||
results = (
|
||||
db.query(NewsItem.autor, func.count(NewsItem.id))
|
||||
.group_by(NewsItem.autor)
|
||||
.all()
|
||||
)
|
||||
|
||||
# Convertir resultados en una lista de diccionarios
|
||||
response = [{"autor": autor, "count": count} for autor, count in results]
|
||||
|
||||
return {"count_by_author": response}
|
||||
|
||||
@router.get("/news/count/favorable/by-author")
|
||||
def count_favorable_news_by_author(db: Session = Depends(get_db)):
|
||||
|
Reference in New Issue
Block a user