-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from AntonioMrtz/feat/Unify-Song-Services
Feat/unify song services
- Loading branch information
Showing
58 changed files
with
2,696 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
MONGO_URI=mongodb://root:root@localhost:27017/ | ||
SECRET_KEY_SIGN=f24e2f3ac557d487b6d879fb2d86f2b2 | ||
LAMBDA_URL=https://lambda-url.us-east-1.on.aws/path/ | ||
ARCH=STREAMING_LAMBDA | ||
ENV_VALUE=PROD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pytest==8.0.1 | ||
pytest-cov==4.1.0 | ||
pytest-mock==3.12.0 | ||
pytest-env==1.1.3 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
from typing import List | ||
|
||
from dotenv import load_dotenv | ||
from src.constants.set_up_constants import ( | ||
ARCHITECTURE_ENV_NAME, | ||
DEFAULT_ARCHITECTURE, | ||
DISTRIBUTION_ID_ENV_NAME, | ||
ENV_VALUE_ENV_NAME, | ||
LAMBDA_URL_ENV_NAME, | ||
MONGO_URI_ENV_NAME, | ||
PROD, | ||
SECRET_KEY_SIGN_ENV_NAME, | ||
TEST, | ||
) | ||
|
||
|
||
class _PropertiesManager: | ||
def __init__(self) -> None: | ||
load_dotenv() | ||
self.env_variables = [ | ||
MONGO_URI_ENV_NAME, | ||
SECRET_KEY_SIGN_ENV_NAME, | ||
DISTRIBUTION_ID_ENV_NAME, | ||
LAMBDA_URL_ENV_NAME, | ||
ENV_VALUE_ENV_NAME, | ||
] | ||
self._load_env_variables(self.env_variables) | ||
self._load_architecture() | ||
|
||
def _load_architecture(self): | ||
# TODO | ||
architecture_type = os.getenv(ARCHITECTURE_ENV_NAME, DEFAULT_ARCHITECTURE) | ||
if not architecture_type: | ||
# TODO convert to log | ||
architecture_type = DEFAULT_ARCHITECTURE | ||
self.__setattr__(ARCHITECTURE_ENV_NAME, DEFAULT_ARCHITECTURE) | ||
print(f"No architecture type selected, using {DEFAULT_ARCHITECTURE}") | ||
self.__setattr__(ARCHITECTURE_ENV_NAME, architecture_type) | ||
# TODO convert to log | ||
print(f"Architecture selected : {architecture_type}") | ||
# TODO | ||
print(f"Running init method for architecture : {architecture_type}") | ||
|
||
def _load_env_variables(self, env_names: List[str]): | ||
# TODO | ||
for env_name in env_names: | ||
env_variable_value = os.getenv(env_name) | ||
if not env_variable_value: | ||
# TODO convert to log | ||
print(f"No enviroment variable provided for {env_name}") | ||
continue | ||
self.__setattr__(env_name, env_variable_value) | ||
|
||
def is_production_enviroment(self) -> bool: | ||
return self.__getattribute__(ENV_VALUE_ENV_NAME) == PROD | ||
|
||
def is_testing_enviroment(self) -> bool: | ||
return self.__getattribute__(ENV_VALUE_ENV_NAME) == TEST | ||
|
||
|
||
PropertiesManager = _PropertiesManager() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ARCH_STREAMING_LAMBDA = "STREAMING_LAMBDA" | ||
ARCH_STREAMING_SDK = "STREAMING_SDK" | ||
ARCH_DB_BLOB = "DB_BLOB" | ||
|
||
PROD = "PROD" | ||
TEST = "TEST" | ||
|
||
ARCHITECTURE_ENV_NAME = "ARCH" | ||
DEFAULT_ARCHITECTURE = ARCH_STREAMING_LAMBDA | ||
|
||
SECRET_KEY_SIGN_ENV_NAME = "SECRET_KEY_SIGN" | ||
MONGO_URI_ENV_NAME = "MONGO_URI" | ||
DISTRIBUTION_ID_ENV_NAME = "DISTRIBUTION_ID" | ||
LAMBDA_URL_ENV_NAME = "LAMBDA_URL" | ||
ENV_VALUE_ENV_NAME = "ENV_VALUE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
MODULE_PREFIX_NAME = "src.services.song_services." | ||
SONG_SERVICE_STREAMING_LAMBDA_SERVICE_MODULE_NAME = "song_service_aws_lambda" | ||
SONG_SERVICE_STREAMING_SDK_SERVICE_MODULE_NAME = "song_service_aws_sdk" | ||
SONG_SERVICE_DB_BLOB_SERVICE_MODULE_NAME = "song_service_db_blob" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,58 @@ | ||
from contextlib import asynccontextmanager | ||
|
||
from fastapi import FastAPI | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from src.boostrap.PropertiesManager import PropertiesManager | ||
from src.middleware.middleware import CheckJwtAuth | ||
from src.routers import artistas, canciones, generos, login, playlists, search, usuarios | ||
|
||
|
||
@asynccontextmanager | ||
async def lifespan_handler(app: FastAPI): | ||
"""Handles the the before and after events of the app start | ||
Parameters | ||
---------- | ||
app : FastAPI | ||
the app object that is going to be created | ||
""" | ||
# TODO print init | ||
app.include_router(playlists.router) | ||
app.include_router(canciones.router) | ||
app.include_router(generos.router) | ||
app.include_router(usuarios.router) | ||
app.include_router(artistas.router) | ||
app.include_router(login.router) | ||
app.include_router(search.router) | ||
yield | ||
# teardown app | ||
# TODO print teardown | ||
|
||
|
||
app = FastAPI( | ||
title="SpotifyElectronAPI", | ||
description="API created with FastAPI Python to manage backend for \ | ||
Spotify Electron App https://github.com/AntonioMrtz/SpotifyElectron", | ||
version="0.0.1", | ||
) | ||
|
||
""" Cors disabled """ | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=[ | ||
"http://localhost/", | ||
"http://localhost:1212", | ||
"https://localhost:1212/", | ||
"https://localhost", | ||
"https://localhost:1212", | ||
"https://localhost:1212/", | ||
"http://127.0.0.1:8000/", | ||
"http://127.0.0.1:8000", | ||
"http://127.0.0.1:8000/usuarios/", | ||
], | ||
allow_credentials=True, | ||
allow_methods=["POST", "GET", "PUT", "DELETE", "PATCH"], | ||
max_age=3600, | ||
allow_headers=["*"], | ||
description="API created with FastAPI Python to serve \ | ||
as backend for Spotify Electron music streaming Desktop App", | ||
version="1.0.0", | ||
lifespan=lifespan_handler, | ||
) | ||
|
||
app.add_middleware(CheckJwtAuth) | ||
|
||
app.include_router(playlists.router) | ||
app.include_router(canciones.router) | ||
app.include_router(generos.router) | ||
app.include_router(usuarios.router) | ||
app.include_router(artistas.router) | ||
app.include_router(login.router) | ||
app.include_router(search.router) | ||
if PropertiesManager.is_production_enviroment(): | ||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=[ | ||
"http://localhost/", | ||
"http://localhost:1212", | ||
"https://localhost:1212/", | ||
"https://localhost", | ||
"https://localhost:1212", | ||
"https://localhost:1212/", | ||
"http://127.0.0.1:8000/", | ||
"http://127.0.0.1:8000", | ||
], | ||
allow_credentials=True, | ||
allow_methods=["POST", "GET", "PUT", "DELETE", "PATCH"], | ||
max_age=3600, | ||
allow_headers=["*"], | ||
) | ||
app.add_middleware(CheckJwtAuth) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import json | ||
from dataclasses import dataclass | ||
|
||
from src.model.Genre import Genre | ||
|
||
|
||
@dataclass | ||
class SongBlob: | ||
|
||
name: str | ||
artist: str | ||
photo: str | ||
duration: int # In seconds | ||
genre: Genre | ||
file: bytes | ||
number_of_plays: int | ||
|
||
def get_json(self) -> json: | ||
song_json = json.dumps(self.__dict__) | ||
return song_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.