Skip to content

Feature/#30 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,6 @@ cython_debug/
marimo/_static/
marimo/_lsp/
__marimo__/

# SQLiteDB
pynewsdb.db
File renamed without changes.
39 changes: 39 additions & 0 deletions app/routers/libraries/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from fastapi import APIRouter, Request, status
from pydantic import BaseModel
from services.database.orm.library import insert_library

from app.schemas import Library as LibrarySchema
from app.services.database.models.libraries import Library


class LibraryResponse(BaseModel):
status: str = "Library created successfully"


def setup():
router = APIRouter(prefix="/libraries", tags=["libraries"])

@router.post(
"",
response_model=LibraryResponse,
status_code=status.HTTP_200_OK,
summary="Create a library",
description="Create a new library to follow",
)
async def create_library(
request: Request,
body: LibrarySchema,
):
await insert_library(
Library(
library_name=body.library_name,
user_email="",
releases_url=body.releases_url.encoded_string(),
logo=body.logo.encoded_string(),
),
request.app.db_session_factory,
)

return LibraryResponse()

return router
7 changes: 5 additions & 2 deletions app/routers/router.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from fastapi import APIRouter

from app.routers.authentication import setup as authentication_router_setup
from app.routers.healthcheck.routes import setup as healthcheck_router_setup
from app.routers.libraries.routes import setup as libraries_router_setup
from app.routers.news.routes import setup as news_router_setup
from app.routers.authentication import setup as authentication_router_setup


def setup_router() -> APIRouter:
router = APIRouter()
router.include_router(healthcheck_router_setup(), prefix="")
router.include_router(news_router_setup(), prefix="")
router.include_router(authentication_router_setup(), prefix='')
router.include_router(authentication_router_setup(), prefix="")
router.include_router(libraries_router_setup(), prefix="")
return router
28 changes: 14 additions & 14 deletions app/schemas.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
from pydantic import BaseModel, HttpUrl
from datetime import datetime
from typing import List
from enum import Enum
from typing import List

from pydantic import BaseModel, HttpUrl

## News
class News(BaseModel):
description: str
tag: str

class Library(BaseModel):
library_name: str
news: list[News]
releases_url: HttpUrl
logo: HttpUrl
version: str
release_date: datetime
release_doc_url: HttpUrl

## Community / User Class

# Community / User Class
class Community(BaseModel):
username: str
email: str
## Extends Community Class with hashed password


# Extends Community Class with hashed password
class CommunityInDB(Community):
password: str


class Token(BaseModel):
access_token: str
token_type: str
expires_in: int


class TokenPayload(BaseModel):
username: str

## Subscription Class

# Subscription Class
class TagEnum(str, Enum):
bug_fix = "bug_fix"
update = "update"
deprecate = "deprecate"
new_feature = "new_feature"
security_fix = "security_fix"


class Subscription(BaseModel):
tags: List[TagEnum]
libraries_list: List[str]
13 changes: 13 additions & 0 deletions app/services/database/orm/library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from sqlmodel.ext.asyncio.session import AsyncSession

from app.services.database.models.libraries import Library


async def insert_library(
library: Library,
session: AsyncSession,
):
session.add(library)
await session.commit()
await session.refresh(library)
return library