File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -205,3 +205,6 @@ cython_debug/
205205marimo /_static /
206206marimo /_lsp /
207207__marimo__ /
208+
209+ # SQLiteDB
210+ pynewsdb.db
File renamed without changes.
Original file line number Diff line number Diff line change 1+ from fastapi import APIRouter , Request , status
2+ from pydantic import BaseModel
3+ from services .database .orm .library import insert_library
4+
5+ from app .schemas import Library as LibrarySchema
6+ from app .services .database .models .libraries import Library
7+
8+
9+ class LibraryResponse (BaseModel ):
10+ status : str = "Library created successfully"
11+
12+
13+ def setup ():
14+ router = APIRouter (prefix = "/libraries" , tags = ["libraries" ])
15+
16+ @router .post (
17+ "" ,
18+ response_model = LibraryResponse ,
19+ status_code = status .HTTP_200_OK ,
20+ summary = "Create a library" ,
21+ description = "Create a new library to follow" ,
22+ )
23+ async def create_library (
24+ request : Request ,
25+ body : LibrarySchema ,
26+ ):
27+ await insert_library (
28+ Library (
29+ library_name = body .library_name ,
30+ user_email = "" ,
31+ releases_url = body .releases_url .encoded_string (),
32+ logo = body .logo .encoded_string (),
33+ ),
34+ request .app .db_session_factory ,
35+ )
36+
37+ return LibraryResponse ()
38+
39+ return router
Original file line number Diff line number Diff line change 11from fastapi import APIRouter
22
3+ from app .routers .authentication import setup as authentication_router_setup
34from app .routers .healthcheck .routes import setup as healthcheck_router_setup
5+ from app .routers .libraries .routes import setup as libraries_router_setup
46from app .routers .news .routes import setup as news_router_setup
5- from app . routers . authentication import setup as authentication_router_setup
7+
68
79def setup_router () -> APIRouter :
810 router = APIRouter ()
911 router .include_router (healthcheck_router_setup (), prefix = "" )
1012 router .include_router (news_router_setup (), prefix = "" )
11- router .include_router (authentication_router_setup (), prefix = '' )
13+ router .include_router (authentication_router_setup (), prefix = "" )
14+ router .include_router (libraries_router_setup (), prefix = "" )
1215 return router
Original file line number Diff line number Diff line change 1- from pydantic import BaseModel , HttpUrl
2- from datetime import datetime
3- from typing import List
41from enum import Enum
2+ from typing import List
3+
4+ from pydantic import BaseModel , HttpUrl
55
6- ## News
7- class News (BaseModel ):
8- description : str
9- tag : str
106
117class Library (BaseModel ):
128 library_name : str
13- news : list [ News ]
9+ releases_url : HttpUrl
1410 logo : HttpUrl
15- version : str
16- release_date : datetime
17- release_doc_url : HttpUrl
1811
19- ## Community / User Class
12+
13+ # Community / User Class
2014class Community (BaseModel ):
2115 username : str
2216 email : str
23- ## Extends Community Class with hashed password
17+
18+
19+ # Extends Community Class with hashed password
2420class CommunityInDB (Community ):
2521 password : str
2622
23+
2724class Token (BaseModel ):
2825 access_token : str
2926 token_type : str
3027 expires_in : int
3128
29+
3230class TokenPayload (BaseModel ):
3331 username : str
3432
35- ## Subscription Class
33+
34+ # Subscription Class
3635class TagEnum (str , Enum ):
3736 bug_fix = "bug_fix"
3837 update = "update"
3938 deprecate = "deprecate"
4039 new_feature = "new_feature"
4140 security_fix = "security_fix"
4241
42+
4343class Subscription (BaseModel ):
4444 tags : List [TagEnum ]
4545 libraries_list : List [str ]
Original file line number Diff line number Diff line change 1+ from sqlmodel .ext .asyncio .session import AsyncSession
2+
3+ from app .services .database .models .libraries import Library
4+
5+
6+ async def insert_library (
7+ library : Library ,
8+ session : AsyncSession ,
9+ ):
10+ session .add (library )
11+ await session .commit ()
12+ await session .refresh (library )
13+ return library
You can’t perform that action at this time.
0 commit comments