Skip to content

Commit

Permalink
IMS log
Browse files Browse the repository at this point in the history
  • Loading branch information
WSL0809 committed Apr 1, 2024
1 parent 4a60638 commit ae1c657
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions api/IMS/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from fastapi import APIRouter, Depends, Query
from pydantic import BaseModel
from sqlalchemy import text
from sqlalchemy.orm import Session

import model
Expand Down Expand Up @@ -37,8 +38,9 @@ class Config:

class LogResponse(BaseModel):
id: int
product_id: int
user_id: int
product_name: str
user_name: str
user_role: str
operation: str
quantity_changed: int
timestamp: datetime
Expand Down Expand Up @@ -131,7 +133,18 @@ async def get_all_logs(
page_size: int = Query(10, description="Number of items per page")
):
skip = (page - 1) * page_size
logs = db.query(model.Log).offset(skip).limit(page_size).all()

query_log_sql = text(
"""
select log.operation, log.quantity_changed, log.timestamp,
p.name as product_name, u.username as user_name, u.role as user_role
from log
left join public.users u on log.user_id = u.id
left join public.product p on log.product_id = p.id
offset :skip limit :page_size
"""
)
logs = db.execute(query_log_sql, {"skip": skip, "page_size": page_size}).mappings().all()
logs_query = db.query(model.Log)

total_items = logs_query.count()
Expand Down

0 comments on commit ae1c657

Please sign in to comment.