Skip to content

Commit aa2a3cc

Browse files
Feat/#194 ping (#196)
* ping実装完了 * tagの更新 * GET /v2/raspis/{}/messages/{}の実装
1 parent 01c2f4f commit aa2a3cc

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

api/main.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from contextlib import asynccontextmanager
2+
from datetime import datetime
23
from typing import Union
34

45
from fastapi import FastAPI
@@ -27,13 +28,26 @@ async def lifespan(app: FastAPI):
2728

2829
tags_metadata = [
2930
{
30-
"name": "raspi",
31+
"name": "futarin-raspi",
3132
"description": "[futairn-raspi]()から使用するエンドポイント",
3233
},
3334
{
3435
"name": "sandbox",
3536
"description": "デバッグ用",
3637
},
38+
{
39+
"name": "raspis",
40+
},
41+
{
42+
"name": "users",
43+
},
44+
{
45+
"name": "couples",
46+
},
47+
{
48+
"name": "v1",
49+
"description": "**Deprecated (非推奨)**",
50+
},
3751
{
3852
"name": "v0 (deprecated)",
3953
"description": "**Deprecated (非推奨)** URI変更なし",
@@ -75,6 +89,11 @@ def read_item(item_id: int, q: Union[str, None] = None):
7589
return {"item_id": item_id, "q": q}
7690

7791

92+
@app.get("/ping")
93+
def ping():
94+
return {"message": "pong", "timestamp": datetime.now()}
95+
96+
7897
@app.post("/push")
7998
def push():
8099
return push_id(1)

api/v1/routers/raspi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@router.post(
2121
"/",
22-
tags=["raspi"],
22+
tags=["v1"],
2323
summary="一連の動作全て",
2424
response_class=FileResponse,
2525
responses={

api/v1/routers/sandbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
@router.post(
1616
"/transcript",
17-
tags=["sandbox"],
17+
tags=["sandbox", "v1"],
1818
summary="whisperによる文字起こし",
1919
response_model=TextResponse,
2020
)
@@ -34,7 +34,7 @@ async def transcript(file: UploadFile = File(...)) -> TextResponse:
3434

3535
@router.post(
3636
"/gpt",
37-
tags=["sandbox"],
37+
tags=["sandbox", "v1"],
3838
summary="chatGPTによる文章生成",
3939
response_model=TextResponse,
4040
)

api/v2/routers/raspi.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
from v2.services.gpt import generate_text
2222
from v2.services.pubsub import get_service
23-
from v2.utils.query import get_thread_id, get_user_id_same_couple
23+
from v2.utils.query import get_thread_id
2424

2525
router = APIRouter()
2626
logger = get_logger()
@@ -34,7 +34,7 @@
3434

3535
@router.post(
3636
"/{id}",
37-
tags=["raspi"],
37+
tags=["futarin-raspi"],
3838
summary="一連の動作全て",
3939
response_class=FileResponse,
4040
responses={
@@ -82,7 +82,7 @@ async def all(
8282

8383
@router.post(
8484
"/{id}/messages",
85-
tags=["raspi"],
85+
tags=["futarin-raspi"],
8686
summary="メッセージ送信",
8787
response_model=raspi_schema.RaspiMessageResponse,
8888
)
@@ -100,7 +100,7 @@ async def create_message(
100100
return response
101101

102102

103-
@router.post("/{id}/negotiate", tags=["raspi"], summary="websocketsのURL発行")
103+
@router.post("/{id}/negotiate", tags=["futarin-raspi"], summary="websocketsのURL発行")
104104
async def negotiate(id: int):
105105
if not id:
106106
return "missing user id", 400
@@ -110,30 +110,33 @@ async def negotiate(id: int):
110110

111111

112112
@router.get(
113-
"/{id}",
114-
tags=["raspi"],
113+
"/{raspi_id}/messages/{message_id}",
114+
tags=["futarin-raspi"],
115115
summary="同coupleのメッセージ取得",
116116
# response_model=Union[FileResponse, raspi_schema.RaspiMessageResponse],
117117
)
118-
async def get_message(id: int, db: AsyncSession = Depends(get_db)):
118+
async def get_message(
119+
raspi_id: int,
120+
message_id: int,
121+
):
119122
# 同coupleのidを取得
120-
boddy_id = await get_user_id_same_couple(db, id)
123+
# boddy_id = await get_user_id_same_couple(db, id)
121124
# 同coupleのファイルをダウンロード
122-
is_downloaded = is_downloaded_blob(str(boddy_id), blob_service_client)
125+
is_downloaded = is_downloaded_blob(str(message_id), blob_service_client)
123126

124127
if is_downloaded:
125128
current_dir = os.path.dirname(os.path.abspath(__file__))
126-
file_path = os.path.join(current_dir, f"../../downloads/{boddy_id}.wav")
129+
file_path = os.path.join(current_dir, f"../../downloads/{message_id}.wav")
127130
return FileResponse(
128-
path=file_path, media_type="audio/wav", filename=f"{boddy_id}.wav"
131+
path=file_path, media_type="audio/wav", filename=f"{message_id}.wav"
129132
)
130133

131-
return {"id": id, "message": "相方のファイルは見つかりませんでした"}
134+
return {"id": raspi_id, "message": "相方のファイルは見つかりませんでした"}
132135

133136

134137
@router.get(
135138
"/",
136-
tags=["raspi"],
139+
tags=["raspis"],
137140
summary="ラズパイ一覧の取得",
138141
response_model=List[raspi_schema.RaspiResponse],
139142
)
@@ -143,7 +146,7 @@ async def list_raspi(db: AsyncSession = Depends(get_db)):
143146

144147
@router.post(
145148
"/",
146-
tags=["raspi"],
149+
tags=["raspis"],
147150
summary="新規ラズパイの作成",
148151
response_model=raspi_schema.RaspiResponse,
149152
)
@@ -155,7 +158,7 @@ async def create_raspi(
155158

156159
@router.put(
157160
"/{id}",
158-
tags=["raspi"],
161+
tags=["raspis"],
159162
summary="ラズパイの更新",
160163
response_model=raspi_schema.RaspiResponse,
161164
)
@@ -168,7 +171,7 @@ async def update_raspi(
168171
return await raspi_crud.update_raspi(db, raspi_body, original=raspi)
169172

170173

171-
@router.delete("/{id}", tags=["raspi"], summary="ラズパイの削除", response_model=None)
174+
@router.delete("/{id}", tags=["raspis"], summary="ラズパイの削除", response_model=None)
172175
async def delete_raspi(id: int, db: AsyncSession = Depends(get_db)):
173176
raspi = await raspi_crud.get_raspi(db, raspi_id=id)
174177
if raspi is None:

0 commit comments

Comments
 (0)