Skip to content

Commit bb56834

Browse files
authored
Merge pull request #37 from PythonFloripa/feature/#30
Feature/#30
2 parents 06f3e2d + b82e8ce commit bb56834

6 files changed

Lines changed: 74 additions & 16 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,6 @@ cython_debug/
205205
marimo/_static/
206206
marimo/_lsp/
207207
__marimo__/
208+
209+
# SQLiteDB
210+
pynewsdb.db

app/routers/libraries/routes.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

app/routers/router.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from fastapi import APIRouter
22

3+
from app.routers.authentication import setup as authentication_router_setup
34
from app.routers.healthcheck.routes import setup as healthcheck_router_setup
5+
from app.routers.libraries.routes import setup as libraries_router_setup
46
from app.routers.news.routes import setup as news_router_setup
5-
from app.routers.authentication import setup as authentication_router_setup
7+
68

79
def 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

app/schemas.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
from pydantic import BaseModel, HttpUrl
2-
from datetime import datetime
3-
from typing import List
41
from 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

117
class 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
2014
class Community(BaseModel):
2115
username: str
2216
email: str
23-
## Extends Community Class with hashed password
17+
18+
19+
# Extends Community Class with hashed password
2420
class CommunityInDB(Community):
2521
password: str
2622

23+
2724
class Token(BaseModel):
2825
access_token: str
2926
token_type: str
3027
expires_in: int
3128

29+
3230
class TokenPayload(BaseModel):
3331
username: str
3432

35-
## Subscription Class
33+
34+
# Subscription Class
3635
class 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+
4343
class Subscription(BaseModel):
4444
tags: List[TagEnum]
4545
libraries_list: List[str]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

0 commit comments

Comments
 (0)