{"openapi":"3.0.0","info":{"title":"林園高中校園資訊整合系統 API 技術文件","version":"2.0.0","contact":{"name":"Zhicheng","url":"https://lyhsca.org","email":"cheng@lyhsca.org"}},"servers":[{"url":"https://api.lyhssa.org","description":"production"},{"url":"http://localhost:8787","description":"development"},{"url":"https://lyhs-app-backend.lysa23.workers.dev","description":"cloudflare worker"}],"components":{"securitySchemes":{"access_token":{"type":"http","scheme":"bearer","description":"Bearer access token for authenticated users."}},"schemas":{},"parameters":{}},"paths":{"/v1/status":{"get":{"summary":"取得服務狀態","tags":["基礎建設"],"description":"LYHS+ 系統運作狀態","operationId":"get_ServiceStatus","responses":{"200":{"description":"請求成功","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","example":"operational"},"version":{"type":"string","example":"1.0.0"},"service":{"type":"object","properties":{"database":{"type":"object","properties":{"status":{"type":"string","example":"connected"},"latency":{"type":"string","example":"854ms"}}}}},"timestamp":{"type":"string","example":"2025-02-22T15:13:29.274Z"},"environment":{"type":"string","example":"production"}}}}}},"500":{"description":"發生不明錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Error check service status"}}}}}}}}},"/v1/auth/googleLogin":{"post":{"summary":"使用 Google 登入","description":"Google 登入","tags":["身份驗證"],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"flow":{"type":"string"},"grant_value":{"type":"string"},"redirect_uri":{"type":"string"}},"required":["flow","grant_value","redirect_uri"]}}}},"operationId":"post_googleLogin","responses":{"200":{"description":"成功登入","content":{"application/json":{"schema":{"type":"object","properties":{"access_token":{"type":"string"},"refresh_token":{"type":"string"},"token_type":{"type":"string","example":"Bearer"},"expires_in":{"type":"number","example":604800},"refresh_expires_in":{"type":"number","example":2592000}},"required":["access_token","refresh_token","token_type","expires_in","refresh_expires_in"]}}}},"400":{"description":"格式錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Invalid flow type"}}}}}},"404":{"description":"找不到用戶","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"User not found"}}}}}},"500":{"description":"發生不明錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Error Login Google account"}}}}}}}}},"/v1/auth/googleReg":{"post":{"summary":"使用 Google 註冊帳號","description":"Google 註冊","tags":["身份驗證"],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"flow":{"type":"string"},"grant_value":{"type":"string"},"redirect_uri":{"type":"string"}},"required":["flow","grant_value","redirect_uri"]}}}},"operationId":"post_googleReg","responses":{"200":{"description":"成功註冊","content":{"application/json":{"schema":{"type":"object","properties":{"access_token":{"type":"string"},"refresh_token":{"type":"string"},"token_type":{"type":"string","example":"Bearer"},"expires_in":{"type":"number","example":604800},"refresh_expires_in":{"type":"number","example":2592000}},"required":["access_token","refresh_token","token_type","expires_in","refresh_expires_in"]}}}},"400":{"description":"格式錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Invalid flow type"}}}}}},"404":{"description":"找不到用戶","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"User not found"}}}}}},"500":{"description":"發生不明錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Error Login Google account"}}}}}}}}},"/v1/auth/login":{"post":{"summary":"使用一般電子郵件登入","tags":["身份驗證"],"operationId":"post_userLogin","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string","format":"email"},"password":{"type":"string"}},"required":["email","password"]}}}},"responses":{"200":{"description":"登入成功","content":{"application/json":{"schema":{"type":"object","properties":{"access_token":{"type":"string"},"refresh_token":{"type":"string"},"token_type":{"type":"string","example":"Bearer"},"expires_in":{"type":"number","example":604800},"refresh_expires_in":{"type":"number","example":2592000}},"required":["access_token","refresh_token","token_type","expires_in","refresh_expires_in"]}}}},"400":{"description":"缺少密碼資訊","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"],"example":{"error":"Password is missing"}}}}},"404":{"description":"使用者不存在","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"],"example":{"error":"User not found"}}}}},"500":{"description":"伺服器內部錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"],"example":{"error":"Internal server error"}}}}}}}},"/v1/auth/logout":{"post":{"summary":"登出帳號","tags":["身份驗證"],"description":"登出使用者","security":[{"sessionId":[]}],"operationId":"post_userLogout","responses":{"200":{"description":"登出成功","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}}}},"400":{"description":"缺少驗證資訊","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"],"example":{"error":"Missing Authorization header"}}}}},"500":{"description":"伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"required":["error"],"example":{"error":"Internal Server Error"}}}}}}}},"/v1/auth/refresh":{"post":{"summary":"刷新 Access Token","description":"使用 refresh_token 取得新的 access_token 與 refresh_token（旋轉）","tags":["身份驗證"],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"refresh_token":{"type":"string"}},"required":["refresh_token"]}}}},"operationId":"post_refreshToken","responses":{"200":{"description":"刷新成功","content":{"application/json":{"schema":{"type":"object","properties":{"access_token":{"type":"string"},"refresh_token":{"type":"string"},"token_type":{"type":"string","example":"Bearer"},"expires_in":{"type":"number","example":604800},"refresh_expires_in":{"type":"number","example":2592000}},"required":["access_token","refresh_token","token_type","expires_in","refresh_expires_in"]}}}},"400":{"description":"請求資料格式錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"example":{"error":"Missing refresh_token"}}}}},"401":{"description":"Refresh token 無效或已過期","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}},"example":{"error":"Invalid or expired refresh token"}}}}},"500":{"description":"伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}},"/v1/user/me":{"get":{"summary":"取得帳號資料","tags":["會員帳號"],"description":"取得帳號相關資料","security":[{"access_token":[]}],"operationId":"get_getUserData","responses":{"200":{"description":"取得資料成功","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"auth_person":{"type":"string","example":"Zhicheng"},"class":{"type":"string","example":"C1"},"email":{"type":"string","example":"example@lyhsca.org"},"grade":{"type":"string","example":"G1"},"id":{"type":"string","example":"123456"},"level":{"type":"string","example":"L1"},"name":{"type":"string","example":"Zhicheng"},"role":{"type":"string","example":"R1"},"type":{"type":"string","example":"normal"}}}}}}}},"400":{"description":"無 sessionId / 格式錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"SessionId is missing or malformed"}}}}}},"401":{"description":"驗證錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Invalid or expired token"}}}}}},"404":{"description":"找不到用戶","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"User not found"}}}}}},"500":{"description":"發生不明錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","example":"Error fetching user data"}}}}}}}}},"/v1/lyps/list":{"get":{"summary":"獲取學校網站公告列表","description":"獲取學校網站公告列表，包括標題、發布時間、內容等信息。","tags":["校園資訊"],"operationId":"get_listAd","responses":{"200":{"description":"成功獲取公告列表","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["success","error"]},"data":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string"},"department":{"type":"string"},"title":{"type":"string"},"link":{"type":"string"}}}},"total":{"type":"number"}}}}}},"500":{"description":"內部伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}},"/v1/lyps/detail/{rawUrl}":{"get":{"summary":"獲取學校網站公告詳細資料","description":"獲取學校網站公告列表，包括標題、發布時間、內容等信息。","tags":["校園資訊"],"operationId":"get_getAnnDetail","responses":{"200":{"description":"成功獲取公告列表","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","enum":["success","error"]},"data":{"type":"array","items":{"type":"object","properties":{"date":{"type":"string"},"department":{"type":"string"},"title":{"type":"string"},"link":{"type":"string"}}}},"total":{"type":"number"}}}}}},"500":{"description":"內部伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}},"/v1/lyps/ann/add":{"post":{"summary":"新增學生會公告","description":"此操作僅限學生會幹部使用。","security":[{"access_token":[]}],"tags":["學生會公告"],"requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","properties":{"title":{"type":"string"},"content":{"type":"string"},"category":{"type":"string"},"tags":{"type":"array","items":{"type":"string"}},"is_banner":{"type":"boolean"},"is_top":{"type":"boolean"},"link":{"type":"string"},"target_group":{"type":"string"},"attachments":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"url":{"type":"string"}}}},"file":{"type":"string","format":"binary"}},"required":["title","content","category","tags","is_banner","is_top","link","target_group","attachments","file"]}}}},"operationId":"post_addLysaAnn","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/lyps/ann/list":{"get":{"summary":"獲取學生會所有公告","tags":["學生會公告"],"operationId":"get_ListLysaAnn","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/lyps/ann/view/{id}":{"put":{"summary":"獲取公告詳細內容","tags":["學生會公告"],"operationId":"put_ViewLysaAnn","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/lyps/ann/delete/{id}":{"delete":{"summary":"刪除學生會公告","description":"此操作僅限學生會幹部使用。","security":[{"access_token":[]}],"tags":["學生會公告"],"parameters":[{"name":"id","required":true,"description":"公告 ID","in":"path","schema":{"type":"string","format":"id"}}],"operationId":"delete_DeleteAnnouncement","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/lyps/ai/chat":{"post":{"summary":"AI 對話式搜尋","description":"連接AI獲取學校相關資訊","tags":["校園資訊"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"input":{"type":"string","description":"使用者輸入的問題"}},"required":["input"]}}}},"operationId":"post_ChatInput","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/lyps/lunch/batch":{"post":{"summary":"上傳午餐資料","tags":["校園午餐"],"operationId":"post_lunchBatch","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/lyps/lunch/list":{"get":{"summary":"獲取午餐資料","tags":["校園午餐"],"operationId":"get_getLunchData","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/cal/events":{"get":{"summary":"獲取林園高中所有活動","tags":["行事曆"],"operationId":"get_getAllEvents","responses":{"200":{"description":"獲取行事曆成功","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"success":{"type":"boolean","description":"操作是否成功"},"meta":{"type":"object","properties":{"served_by":{"type":"string"},"served_by_region":{"type":"string"},"served_by_primary":{"type":"boolean"},"timings":{"type":"object","properties":{"sql_duration_ms":{"type":"number"}}},"duration":{"type":"number"},"changes":{"type":"number"},"last_row_id":{"type":"number"},"changed_db":{"type":"boolean"},"size_after":{"type":"number"},"rows_read":{"type":"number"},"rows_written":{"type":"number"},"result":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"title":{"type":"string"},"description":{"type":"string"},"date":{"type":"string"},"office":{"type":"string"}}}}}}}}}}}}},"500":{"description":"發生錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}}}}}}}},"/v1/cal/event":{"post":{"summary":"新增活動","tags":["行事曆"],"security":[{"sessionId":[]}],"operationId":"post_addEvent","responses":{"200":{"description":"成功新增活動","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","description":"成功訊息"}}}}}},"400":{"description":"錯誤的請求","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}}}}}},"500":{"description":"伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}}}}}}}},"delete":{"summary":"刪除活動","tags":["行事曆"],"security":[{"sessionId":[]}],"operationId":"delete_deleteEvent","responses":{"200":{"description":"成功刪除活動","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","description":"成功訊息"}}}}}},"400":{"description":"錯誤的請求","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}}}}}},"500":{"description":"伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}}}}}}}}},"/v1/cal/sub":{"get":{"summary":"訂閱行事曆","tags":["行事曆"],"operationId":"get_subscribe","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/cal/update":{"put":{"summary":"更新行事曆事件","tags":["行事曆"],"operationId":"put_UpdateEvent","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"事件ID"},"title":{"type":"string","description":"事件標題"},"description":{"type":"string","description":"事件描述"},"date":{"type":"string","description":"事件日期"},"office":{"type":"string","description":"辦公室"}},"required":["id","title","description","date","office"]}}}},"responses":{"200":{"description":"更新成功","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string","description":"更新成功訊息"}},"required":["message"]}}}},"403":{"description":"權限不足","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}},"required":["error"]}}}},"500":{"description":"伺服器錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}},"required":["error"]}}}}}}},"/v1/admin/accountInfo/total":{"get":{"summary":"獲取使用者數量","description":"此操作僅限擁有管理權限的帳號。","tags":["系統管理"],"security":[{"sessionId":[]}],"operationId":"get_getUserNum","responses":{"200":{"description":"成功獲取使用者帳號數量","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"object","properties":{"COUNT(*)":{"type":"number","description":"使用者帳號數量"}},"required":["userNum"]}},"required":["data"]}}}},"500":{"description":"伺服器內部錯誤","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"錯誤訊息"}},"required":["error"]}}}}}}},"/v1/admin/service/all":{"get":{"operationId":"get_getServices","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/service/update":{"post":{"summary":"更新服務狀態","description":"管理 LYHS+ 各項服務狀態","tags":["系統管理"],"operationId":"post_adjustService","requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"status":{"type":"integer"}},"required":["name","status"]}}}},"responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/user/delete/{uuid}":{"delete":{"summary":"刪除用戶資料","description":"此權限僅限具備學生會幹部身份執行","security":[{"access_token":[]}],"tags":["系統管理"],"parameters":[{"name":"uuid","in":"path","description":"要刪除的用戶的 UUID","required":true,"schema":{"type":"string","format":"uuid"}}],"operationId":"delete_DeleteUser","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/user/ban/{uuid}":{"put":{"summary":"禁用用戶","description":"此權限僅限具備學生會幹部身份執行","security":[{"access_token":[]}],"tags":["系統管理"],"parameters":[{"name":"uuid","in":"path","description":"要禁用的用戶的 UUID","required":true,"schema":{"type":"string","format":"uuid"}}],"operationId":"put_BanUser","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/user/list":{"get":{"summary":"獲取所有用戶資料","description":"此權限僅限具備學生會幹部身份執行","security":[{"access_token":[]}],"tags":["系統管理"],"operationId":"get_ListAllUsers","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/user/create/studentMember":{"post":{"summary":"創建學生帳號","description":"管理帳號創建學生帳號","tags":["系統管理"],"security":[{"access_token":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"stu_id":{"type":"string"},"zh_name":{"type":"string"},"class_name":{"type":"string"},"grade":{"type":"string"},"number":{"type":"string"},"is_member":{"type":"boolean"}},"required":["stu_id","zh_name","class_name","grade","number","is_member"]}}}},"operationId":"post_CreateStudentUser","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/user/create/lysaStaff":{"post":{"summary":"創建學生會幹部帳號","description":"管理帳號創建學生會幹部帳號，密碼預設為學號","tags":["系統管理"],"security":[{"access_token":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"},"stu_id":{"type":"string"},"zh_name":{"type":"string"},"class_name":{"type":"string"},"grade":{"type":"string"},"number":{"type":"string"}},"required":["email","stu_id","zh_name","class_name","grade","number"]}}}},"operationId":"post_CreateLysaStaffAccount","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}},"/v1/admin/user/create/batch":{"post":{"summary":"批量新增會員資料","operationId":"post_BatchCreateUser","responses":{"200":{"description":"Successful response","content":{"application/json":{"schema":{}}}}}}}},"webhooks":{}}