Spaces:
Running
Running
Ved Gupta
commited on
Commit
·
35e685d
1
Parent(s):
d1d97b7
user enpoint created and tested
Browse files- README.md +15 -0
- app/api/__init__.py +1 -2
- app/api/endpoints/__init__.py +1 -2
- app/api/endpoints/items.py +0 -13
- app/api/endpoints/users.py +16 -22
- app/api/models/__init__.py +1 -1
- app/api/models/item.py +0 -16
- app/api/models/transcribe.py +4 -0
- app/api/models/user.py +5 -0
- app/core/models/User.py +18 -0
README.md
CHANGED
@@ -69,6 +69,21 @@ The project structure is organized as follows:
|
|
69 |
- `README.md`: this file.
|
70 |
- `.vscode`: contains Visual Studio Code configuration files.
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
## Run this Project
|
74 |
|
|
|
69 |
- `README.md`: this file.
|
70 |
- `.vscode`: contains Visual Studio Code configuration files.
|
71 |
|
72 |
+
## Active Paths
|
73 |
+
| Path | Name | Methods |
|
74 |
+
| ------------------------|----------------------|-------------|
|
75 |
+
| /api/v1/openapi.json | openapi | GET, HEAD |
|
76 |
+
| /docs | swagger_ui_html | GET, HEAD |
|
77 |
+
| /docs/oauth2-redirect | swagger_ui_redirect | GET, HEAD |
|
78 |
+
| /redoc | redoc_html | GET, HEAD |
|
79 |
+
| /api/v1/items/ | read_items | GET |
|
80 |
+
| /api/v1/items/{item_id} | read_item | GET |
|
81 |
+
| /api/v1/users/ | create_user | POST |
|
82 |
+
| /api/v1/users/{user_id}/ | read_user | GET |
|
83 |
+
| /api/v1/users/{user_id}/ | update_user | PUT |
|
84 |
+
| /api/v1/users/{user_id}/ | delete_user | DELETE |
|
85 |
+
| /api/v1/transcribe/ | post_audio | POST |
|
86 |
+
|
87 |
|
88 |
## Run this Project
|
89 |
|
app/api/__init__.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
# File: whisper.api/app/api/__init__.py
|
2 |
|
3 |
from fastapi import APIRouter
|
4 |
-
from .endpoints import
|
5 |
|
6 |
api_router = APIRouter()
|
7 |
|
8 |
-
api_router.include_router(items.router, prefix="/items", tags=["items"])
|
9 |
api_router.include_router(users.router, prefix="/users", tags=["users"])
|
10 |
api_router.include_router(transcribe.router, prefix="/transcribe", tags=["transcribe"])
|
|
|
1 |
# File: whisper.api/app/api/__init__.py
|
2 |
|
3 |
from fastapi import APIRouter
|
4 |
+
from .endpoints import users, transcribe
|
5 |
|
6 |
api_router = APIRouter()
|
7 |
|
|
|
8 |
api_router.include_router(users.router, prefix="/users", tags=["users"])
|
9 |
api_router.include_router(transcribe.router, prefix="/transcribe", tags=["transcribe"])
|
app/api/endpoints/__init__.py
CHANGED
@@ -2,10 +2,9 @@
|
|
2 |
|
3 |
from fastapi import APIRouter
|
4 |
|
5 |
-
from . import
|
6 |
|
7 |
router = APIRouter()
|
8 |
|
9 |
-
router.include_router(items.router, prefix="/items", tags=["items"])
|
10 |
router.include_router(users.router, prefix="/users", tags=["users"])
|
11 |
router.include_router(transcribe.router, prefix="/transcribe", tags=["transcribe"])
|
|
|
2 |
|
3 |
from fastapi import APIRouter
|
4 |
|
5 |
+
from . import users, transcribe
|
6 |
|
7 |
router = APIRouter()
|
8 |
|
|
|
9 |
router.include_router(users.router, prefix="/users", tags=["users"])
|
10 |
router.include_router(transcribe.router, prefix="/transcribe", tags=["transcribe"])
|
app/api/endpoints/items.py
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
from fastapi import APIRouter
|
2 |
-
|
3 |
-
router = APIRouter()
|
4 |
-
|
5 |
-
|
6 |
-
@router.get("/")
|
7 |
-
async def read_items():
|
8 |
-
return [{"name": "Item Foo"}, {"name": "item Bar"}]
|
9 |
-
|
10 |
-
|
11 |
-
@router.get("/{item_id}")
|
12 |
-
async def read_item(item_id: int, q: str = None):
|
13 |
-
return {"item_id": item_id, "q": q}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/endpoints/users.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from fastapi import APIRouter, HTTPException
|
2 |
from uuid import UUID
|
3 |
|
4 |
-
from app.api.models.user import User, UpdateUser, UserResponse
|
5 |
from app.core.database import SessionLocal
|
6 |
from app.core.security import get_password_hash, verify_password
|
7 |
from app.core.models import UserInDB
|
@@ -28,29 +28,23 @@ async def create_user(user: User):
|
|
28 |
|
29 |
@router.get("/{user_id}/", response_model=UserResponse)
|
30 |
async def read_user(user_id: UUID):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
35 |
|
36 |
|
37 |
-
@router.put("/{user_id}/", response_model=
|
38 |
-
async def
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
raise HTTPException(status_code=400, detail=
|
46 |
-
if user.username is None:
|
47 |
-
user.username = db_user.username
|
48 |
-
else:
|
49 |
-
db_user.username = user.username
|
50 |
-
db_user.hashed_password = get_password_hash(user.password)
|
51 |
-
database.commit()
|
52 |
-
database.refresh(db_user)
|
53 |
-
return {**user.dict(), "id": db_user.id, "hashed_password": None}
|
54 |
|
55 |
|
56 |
@router.delete("/{user_id}/")
|
|
|
1 |
from fastapi import APIRouter, HTTPException
|
2 |
from uuid import UUID
|
3 |
|
4 |
+
from app.api.models.user import User, UpdateUser, UserResponse, PasswordUpdate
|
5 |
from app.core.database import SessionLocal
|
6 |
from app.core.security import get_password_hash, verify_password
|
7 |
from app.core.models import UserInDB
|
|
|
28 |
|
29 |
@router.get("/{user_id}/", response_model=UserResponse)
|
30 |
async def read_user(user_id: UUID):
|
31 |
+
try:
|
32 |
+
USER = UserController(database)
|
33 |
+
USER.read(user_id)
|
34 |
+
return UserResponse.from_orm(USER.details())
|
35 |
+
except Exception as e:
|
36 |
+
raise HTTPException(status_code=400, detail=e.__str__())
|
37 |
|
38 |
|
39 |
+
@router.put("/{user_id}/update_password/", response_model=UserResponse)
|
40 |
+
async def update_password(user_id: UUID, password: PasswordUpdate):
|
41 |
+
try:
|
42 |
+
USER = UserController(database)
|
43 |
+
USER.update_password(user_id, password.current_password, password.new_password)
|
44 |
+
return UserResponse.from_orm(USER.details())
|
45 |
+
|
46 |
+
except Exception as e:
|
47 |
+
raise HTTPException(status_code=400, detail=e.__str__())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
@router.delete("/{user_id}/")
|
app/api/models/__init__.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
from .item import Item
|
2 |
from .user import User
|
|
|
|
|
|
1 |
from .user import User
|
2 |
+
from .transcribe import Transcribe
|
app/api/models/item.py
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
from typing import Optional
|
2 |
-
from pydantic import BaseModel
|
3 |
-
|
4 |
-
|
5 |
-
class ItemBase(BaseModel):
|
6 |
-
title: str
|
7 |
-
description: Optional[str] = None
|
8 |
-
|
9 |
-
|
10 |
-
class ItemCreate(ItemBase):
|
11 |
-
pass
|
12 |
-
|
13 |
-
|
14 |
-
class Item(ItemBase):
|
15 |
-
id: int
|
16 |
-
owner_id: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/api/models/transcribe.py
CHANGED
@@ -9,3 +9,7 @@ from sqlalchemy import Column, Integer, String, Boolean, ForeignKey
|
|
9 |
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
10 |
|
11 |
from app.core.database import Base
|
|
|
|
|
|
|
|
|
|
9 |
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
10 |
|
11 |
from app.core.database import Base
|
12 |
+
|
13 |
+
|
14 |
+
class Transcribe(BaseModel):
|
15 |
+
...
|
app/api/models/user.py
CHANGED
@@ -29,6 +29,11 @@ class UserResponse(UserBase):
|
|
29 |
}
|
30 |
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
class User(UserBase):
|
33 |
password: str
|
34 |
|
|
|
29 |
}
|
30 |
|
31 |
|
32 |
+
class PasswordUpdate(BaseModel):
|
33 |
+
current_password: str
|
34 |
+
new_password: str
|
35 |
+
|
36 |
+
|
37 |
class User(UserBase):
|
38 |
password: str
|
39 |
|
app/core/models/User.py
CHANGED
@@ -75,6 +75,24 @@ class UserController:
|
|
75 |
return True
|
76 |
return False
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
def details(self):
|
79 |
return self.db_user
|
80 |
|
|
|
75 |
return True
|
76 |
return False
|
77 |
|
78 |
+
def read(self, user_id: uuid.UUID):
|
79 |
+
self.db_user = self.db.query(UserInDB).filter(UserInDB.id == user_id).first()
|
80 |
+
if not self.db_user:
|
81 |
+
raise Exception("User not found")
|
82 |
+
self.user = self.db_user.data()
|
83 |
+
|
84 |
+
def update_password(
|
85 |
+
self, user_id: uuid.UUID, current_password: str, new_password: str
|
86 |
+
):
|
87 |
+
self.read(user_id)
|
88 |
+
if verify_password(current_password, self.db_user.hashed_password):
|
89 |
+
self.db_user.hashed_password = get_password_hash(new_password)
|
90 |
+
self.db.commit()
|
91 |
+
self.db.refresh(self.db_user)
|
92 |
+
self.user = self.db_user.data()
|
93 |
+
else:
|
94 |
+
raise Exception("Current password is incorrect")
|
95 |
+
|
96 |
def details(self):
|
97 |
return self.db_user
|
98 |
|