feat: Add alerts_enabled to plant schemas and endpoints

This commit is contained in:
haneulai 2026-04-14 16:40:47 +09:00
parent d8a3efab06
commit cd684eae22
2 changed files with 43 additions and 1 deletions

View File

@ -9,7 +9,7 @@ from supabase import Client
from typing import List
from app.core.database import get_db
from app.schemas.plant import PlantsListResponse, PlantWithLatestLog, SolarLogBase
from app.schemas.plant import PlantsListResponse, PlantWithLatestLog, SolarLogBase, PlantAlertUpdateRequest
router = APIRouter(
prefix="/plants",
@ -138,3 +138,40 @@ async def get_plant_detail(
status_code=500,
detail=f"데이터베이스 조회 중 오류가 발생했습니다: {str(e)}"
)
@router.patch("/{company_id}/{plant_id}/alerts")
async def update_plant_alerts(
company_id: int,
plant_id: str,
alert_update: PlantAlertUpdateRequest,
db: Client = Depends(get_db)
) -> dict:
"""
특정 발전소의 알림 활성화 상태를 변경합니다.
"""
try:
response = db.table("plants") \
.update({"alerts_enabled": alert_update.alerts_enabled}) \
.eq("id", plant_id) \
.eq("company_id", company_id) \
.execute()
if not response.data:
raise HTTPException(
status_code=404,
detail="발전소를 찾을 수 없거나 업데이트에 실패했습니다."
)
return {
"status": "success",
"message": "알림 설정이 변경되었습니다.",
"data": response.data[0]
}
except HTTPException:
raise
except Exception as e:
raise HTTPException(
status_code=500,
detail=f"알림 설정 변경 중 오류가 발생했습니다: {str(e)}"
)

View File

@ -17,8 +17,13 @@ class PlantBase(BaseModel):
name: str
capacity: Optional[float] = Field(None, description="발전 용량 (kW)")
location: Optional[str] = Field(None, description="발전소 위치")
alerts_enabled: Optional[bool] = Field(True, description="이상 알림 활성화 여부")
created_at: Optional[datetime] = None
class PlantAlertUpdateRequest(BaseModel):
alerts_enabled: bool
class SolarLogBase(BaseModel):
"""발전 로그 기본 정보 스키마"""