Add user router
This commit is contained in:
parent
b22bc4e164
commit
e33d74308a
5 changed files with 93 additions and 13 deletions
|
@ -8,7 +8,7 @@ from sqlalchemy.orm import Session
|
|||
from app.database import get_db
|
||||
from app.ocpp_proto import chargepoint_manager
|
||||
from app.schemas.chargepoint import ChargePoint, ChargePointCreate, ChargePointUpdate, ChargePointPassword, ChargePointConnectionInfo
|
||||
from app.models.chargepoint import ChargePoint as DBChargePoint
|
||||
from app.models.chargepoint import ChargePoint as DbChargePoint
|
||||
from app.security import get_api_key
|
||||
|
||||
router = APIRouter(
|
||||
|
@ -23,7 +23,7 @@ async def get_chargepoints(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
return db.query(DBChargePoint).offset(skip).limit(limit).all()
|
||||
return db.query(DbChargePoint).offset(skip).limit(limit).all()
|
||||
|
||||
@router.get(path="/{chargepoint_id}", response_model=ChargePoint)
|
||||
async def get_chargepoint(
|
||||
|
@ -31,7 +31,7 @@ async def get_chargepoint(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
chargepoint = db.query(DBChargePoint).filter(DBChargePoint.id == chargepoint_id).first()
|
||||
chargepoint = db.get(DbChargePoint, chargepoint_id)
|
||||
if chargepoint is None:
|
||||
raise HTTPException(status_code=404, detail="Chargepoint not found")
|
||||
return chargepoint
|
||||
|
@ -42,7 +42,7 @@ async def get_chargepoint_password(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
chargepoint = db.query(DBChargePoint).filter(DBChargePoint.id == chargepoint_id).first()
|
||||
chargepoint = db.get(DbChargePoint, chargepoint_id)
|
||||
if chargepoint is None:
|
||||
raise HTTPException(status_code=404, detail="Chargepoint not found")
|
||||
return ChargePointPassword(password=chargepoint.password)
|
||||
|
@ -53,7 +53,7 @@ async def reset_chargepoint_password(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
chargepoint = db.query(DBChargePoint).filter(DBChargePoint.id == chargepoint_id).first()
|
||||
chargepoint = db.get(DbChargePoint, chargepoint_id)
|
||||
if chargepoint is None:
|
||||
raise HTTPException(status_code=404, detail="Chargepoint not found")
|
||||
chargepoint.password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(24))
|
||||
|
@ -66,7 +66,7 @@ async def create_chargepoint(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
chargepoint_db = DBChargePoint(
|
||||
chargepoint_db = DbChargePoint(
|
||||
friendly_name=chargepoint.friendly_name,
|
||||
is_active=chargepoint.is_active,
|
||||
password=''.join(random.choice(string.ascii_letters + string.digits) for i in range(24))
|
||||
|
@ -83,7 +83,7 @@ async def update_chargepoint(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
chargepoint = db.query(DBChargePoint).filter(DBChargePoint.id == chargepoint_id).first()
|
||||
chargepoint = db.get(DbChargePoint, chargepoint_id)
|
||||
if chargepoint is None:
|
||||
raise HTTPException(status_code=404, detail="Chargepoint not found")
|
||||
for key, value in chargepoint_update.model_dump(exclude_unset=True).items():
|
||||
|
@ -97,7 +97,7 @@ async def delete_chargepoint(
|
|||
api_key: str = Security(get_api_key),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
chargepoint = db.query(DBChargePoint).filter(DBChargePoint.id == chargepoint_id).first()
|
||||
chargepoint = db.get(DbChargePoint, chargepoint_id)
|
||||
if chargepoint is None:
|
||||
raise HTTPException(status_code=404, detail="Chargepoint not found")
|
||||
db.delete(chargepoint)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue