Skip to content
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

Unify Song Services #111

Merged
merged 203 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
a147050
chore : change token expire time to 7 days
AntonioMrtz Oct 9, 2023
fbe29f2
fix : gap show all now is 14px
AntonioMrtz Oct 9, 2023
e97ca68
feat : mostrarTodo user playlists
AntonioMrtz Oct 9, 2023
8996a95
feat :add ShowAllSongsFromArtist fix ShowAllPlaylist
AntonioMrtz Oct 9, 2023
92e19a0
feat : add mostrarTodo button UserProfile
AntonioMrtz Oct 9, 2023
8a74c8b
fix : userprofile for artist fix canciones del artista header
AntonioMrtz Oct 9, 2023
d85b6a3
fix : reduce Playlist>Song artist hitbox
AntonioMrtz Oct 9, 2023
dfd3f89
fix : reduce cards artist hitbox
AntonioMrtz Oct 9, 2023
258396f
feat : make SongCard use cards style and add clickable artist
AntonioMrtz Oct 9, 2023
3101ed8
fix : delete empty onContextMenu SongCard
AntonioMrtz Oct 10, 2023
dc28b9a
fix : add repeat song increases play count by 1
AntonioMrtz Oct 10, 2023
e1e59d1
fix : disable song still playing while logout and play 2 songs at sam…
AntonioMrtz Oct 10, 2023
fb3b50c
fix : alt text of image cards
AntonioMrtz Oct 10, 2023
2cf5bd8
fix : no anidated button inside SongCard
AntonioMrtz Oct 10, 2023
e05dfc1
file : move componentes/ to components/
AntonioMrtz Oct 13, 2023
82f2640
file : delete tech docs
AntonioMrtz Oct 13, 2023
8f7dcf4
Create Procfile
AntonioMrtz Oct 17, 2023
1a0e97a
Update Procfile
AntonioMrtz Oct 17, 2023
56f2e04
Update Procfile
AntonioMrtz Oct 17, 2023
6f56775
feat : add Dockerfile deploy Backend
AntonioMrtz Oct 17, 2023
80ff081
fix : add SECRET_KEY_SIGN env variable to example Dockerfile run
AntonioMrtz Oct 17, 2023
ca40c1f
fix : fix typo
AntonioMrtz Oct 17, 2023
010900f
fix : modified path of mui imports
AntonioMrtz Oct 10, 2023
63b7a1c
test : add test StartMenu
AntonioMrtz Oct 11, 2023
bb6c5ff
chore : add github actions frontend tests
AntonioMrtz Oct 11, 2023
00995eb
test : add RegisterMenu tests
AntonioMrtz Oct 12, 2023
6d72a0c
test : add UserProfile tests
AntonioMrtz Oct 12, 2023
6fb9055
test : add Home tests
AntonioMrtz Oct 12, 2023
1b735f7
test : increase coverage Home test with mock fetchs
AntonioMrtz Oct 12, 2023
4cd3549
test : increase coverage UserProfile tests
AntonioMrtz Oct 12, 2023
fb9cb59
test : add App tests
AntonioMrtz Oct 13, 2023
be20d6c
test : add Genre tests
AntonioMrtz Oct 13, 2023
34d6c66
test : add Explorar tests
AntonioMrtz Oct 13, 2023
cba88e9
file : move pages tests to their own folder
AntonioMrtz Oct 13, 2023
5641372
file : delete tech docs
AntonioMrtz Oct 13, 2023
3c870ec
fix : add mock scrollto in App tests
AntonioMrtz Oct 13, 2023
dad81de
test : add Playlist tests
AntonioMrtz Oct 13, 2023
d4def43
file : move apptest to __tests__/renderer/
AntonioMrtz Oct 13, 2023
2ca0e0e
test : add Sticky Header tests
AntonioMrtz Oct 14, 2023
dcb843c
chore : fix typo
AntonioMrtz Oct 14, 2023
a0406e0
test : add ItemsAllArtist tests
AntonioMrtz Oct 14, 2023
b7e44d3
test : add ItemsAllPlaylist test
AntonioMrtz Oct 14, 2023
51fa098
fix : typo error add .test to test files
AntonioMrtz Oct 14, 2023
86b9c36
test : add ItemsAllSong tests
AntonioMrtz Oct 14, 2023
78b1935
fix : add expect statement according to Cards content in Items
AntonioMrtz Oct 14, 2023
4169e5b
fix : test name error
AntonioMrtz Oct 14, 2023
d742603
test : add ItemsAllPlaylistFromUser tests
AntonioMrtz Oct 14, 2023
fc814d3
test : add Sidebar tests
AntonioMrtz Oct 16, 2023
36cd005
test : add Sidebaer>Playlist tests
AntonioMrtz Oct 16, 2023
8ef7669
test : add AddSongPlaylistAccordion tests
AntonioMrtz Oct 16, 2023
a150c0f
test : add Token tests
AntonioMrtz Oct 16, 2023
e6ff82a
test : add Footer tests
AntonioMrtz Oct 16, 2023
d785b0f
test : add SongInfo tests
AntonioMrtz Oct 16, 2023
1ab5b9d
test : add SongConfig & VolumeSlider tests
AntonioMrtz Oct 16, 2023
6a32f2d
test : add ContextMenuSong
AntonioMrtz Oct 16, 2023
5f03d76
test : draft player test
AntonioMrtz Oct 17, 2023
887f9c2
test : add Player tests
AntonioMrtz Oct 18, 2023
55fb3bc
test : add ContextMenuPlaylist tests
AntonioMrtz Oct 18, 2023
83750e1
chore : delete prints on ContextMenuPlaylist tests
AntonioMrtz Oct 18, 2023
e1fadc0
fix : interceptor react gets latest cookie on fetch
AntonioMrtz Oct 18, 2023
4e3a5ab
fix : remove artist field fetch create song
AntonioMrtz Oct 18, 2023
ac6da05
file : delete unused lambda
AntonioMrtz Oct 19, 2023
947d44f
docs : update readme with tests and docker info
AntonioMrtz Oct 19, 2023
379e898
fix : adapt Dockerfile to master branch
AntonioMrtz Oct 19, 2023
5413fa9
docs : add tests to contributing
AntonioMrtz Oct 19, 2023
9ef971d
docs : add tests to contributing
AntonioMrtz Oct 19, 2023
546f821
docs : update readme with tests and docker info
AntonioMrtz Oct 19, 2023
9cd1bcc
chore : change comments dockerize master-streaming
AntonioMrtz Oct 19, 2023
c297143
feat : add workflow generate docs
AntonioMrtz Oct 20, 2023
ef70aaf
feat : add workflow generate docs
AntonioMrtz Oct 20, 2023
82de95b
docs : add api docs
AntonioMrtz Oct 21, 2023
c108bfd
docs : add api docs
AntonioMrtz Oct 21, 2023
bdddbe3
feat : add backend methods for search by name
AntonioMrtz Oct 21, 2023
0286f33
fix : songCollection to song_collection
AntonioMrtz Oct 22, 2023
fd0e7f4
feat : add backend methods for search by name
AntonioMrtz Oct 21, 2023
987da8c
fix : use dto getsong for search_by_name song_service
AntonioMrtz Oct 22, 2023
e27d30e
fix : change branch to update docs github actions
AntonioMrtz Oct 23, 2023
d3db8d9
fix : change branch to update docs github actions
AntonioMrtz Oct 23, 2023
d8941cf
feat : update readme
AntonioMrtz Oct 23, 2023
14ba868
feat : update readme
AntonioMrtz Oct 23, 2023
c158c83
docs : update readme goals
AntonioMrtz Oct 25, 2023
aff2fb8
docs : update readme goals
AntonioMrtz Oct 25, 2023
a450d3a
chore : delete unused imports from tests
AntonioMrtz Oct 21, 2023
3fe5b72
feat : change search_by_name output to arrays of jsons
AntonioMrtz Oct 21, 2023
e289511
docs : update docs search_by_name
AntonioMrtz Oct 21, 2023
8ff2a55
style : format search service
AntonioMrtz Oct 21, 2023
074bd62
test : add search endpoint tests
AntonioMrtz Oct 21, 2023
e3339b1
feat : add UserCard
AntonioMrtz Oct 21, 2023
36eb6ba
feat : add search bar
AntonioMrtz Oct 21, 2023
60c0cd2
feat : add filtered items
AntonioMrtz Oct 22, 2023
e65d20d
test : add Explorar searchbar tests
AntonioMrtz Oct 22, 2023
1e18ea0
chore : gitignore dont ignore .vscode
AntonioMrtz Oct 29, 2023
a19ef18
chore : add recomended extensions
AntonioMrtz Oct 29, 2023
8b3e0b0
chore : gitignore dont ignore .vscode
AntonioMrtz Oct 29, 2023
1267e93
chore : add recomended extensions
AntonioMrtz Oct 29, 2023
346a725
chore : add issue template
AntonioMrtz Nov 1, 2023
7175f15
chore : add issue template
AntonioMrtz Nov 1, 2023
a363fa8
fix : move issue template under ISSUE_TEMPLATE folder
AntonioMrtz Nov 1, 2023
32d1043
fix : move issue template under ISSUE_TEMPLATE folder
AntonioMrtz Nov 1, 2023
f5fecd8
Update issue templates
AntonioMrtz Nov 1, 2023
8658d7a
fix : rename issue template
AntonioMrtz Nov 1, 2023
6718a64
Update issue templates
AntonioMrtz Nov 1, 2023
c1f556d
Update issue templates
AntonioMrtz Nov 1, 2023
2583aa7
fix : add onerror image to cards and profiles
AntonioMrtz Nov 2, 2023
6504045
fix : add onerror image to cards and profiles
AntonioMrtz Nov 2, 2023
3b2a01e
fix : Explorar fix after cherry didnt work
AntonioMrtz Nov 2, 2023
855661c
fix : artists not showing explorar
AntonioMrtz Nov 2, 2023
85f7900
docs : add frontend architecture
AntonioMrtz Nov 4, 2023
170fb3e
docs : add frontend architecture
AntonioMrtz Nov 4, 2023
84471d1
chore : modify build icons
AntonioMrtz Nov 25, 2023
7214a6f
chore : add spotify icon to build
AntonioMrtz Nov 25, 2023
66fc922
fix : replace browser router with hashrouter for build
AntonioMrtz Nov 25, 2023
d4fd177
chore : modify build icons
AntonioMrtz Nov 25, 2023
a61f9a9
chore : add spotify icon to build
AntonioMrtz Nov 25, 2023
1e78c65
fix : replace browser router with hashrouter for build
AntonioMrtz Nov 25, 2023
ee29302
docs : add funding kofi
AntonioMrtz Feb 17, 2024
db7e2c8
docs : add funding kofi
AntonioMrtz Feb 17, 2024
eaeaa85
build : protect backend path into env
AntonioMrtz Feb 24, 2024
c170a6b
ci : add mongo uri env logic instead of mongo pass
AntonioMrtz Feb 24, 2024
19df91c
ci : establish v12 backend python version pipeline
AntonioMrtz Feb 24, 2024
21ee962
ci : update python backend actions for more recent ones
AntonioMrtz Feb 24, 2024
e69907c
ci : add mongo uri env logic instead of mongo pass
AntonioMrtz Feb 24, 2024
e3557d1
docs : add frontend docs
AntonioMrtz Feb 24, 2024
cf59198
build : protect backend path into env
AntonioMrtz Feb 24, 2024
723cfcc
docs : update PR template with new types of commit/branches
AntonioMrtz Feb 24, 2024
9f1fbe6
chore : add comments new backend env on Dockerfile
AntonioMrtz Feb 24, 2024
4513f42
docs : update PR template with new types of commit/branches
AntonioMrtz Feb 24, 2024
3d8fc63
docs : add frontend docs
AntonioMrtz Feb 24, 2024
f0a02cb
fix : add correct link readme frontend
AntonioMrtz Feb 24, 2024
4dd27f5
docs : update setup with boto and aws cli
AntonioMrtz Feb 24, 2024
b48d67b
chore : vscode adjusts for new test path
AntonioMrtz Feb 24, 2024
f58f1f3
docs : update docs with new separated requirements
AntonioMrtz Feb 24, 2024
39c5a79
chore : add comments new backend env on Dockerfile
AntonioMrtz Feb 24, 2024
c751d8f
fix : pipeline backend test unify run
AntonioMrtz Feb 24, 2024
ee53335
docs : update PR template with new types of commit/branches
AntonioMrtz Feb 24, 2024
87df9c7
build : protect backend path into env
AntonioMrtz Feb 24, 2024
cd01b6c
ci : add mongo uri env logic instead of mongo pass
AntonioMrtz Feb 24, 2024
080e67a
docs : add frontend docs
AntonioMrtz Feb 24, 2024
5910de2
chore : add separated reduced requirements backend
AntonioMrtz Feb 24, 2024
8781600
refactor : rename __tests__ folder into tests
AntonioMrtz Feb 24, 2024
0292aa0
docs : update docs with new separated requirements
AntonioMrtz Feb 24, 2024
24c3b5a
chore: delete boto from requirements
AntonioMrtz Feb 24, 2024
3ab2fb9
fix : search service wrong name of file_song_collection
AntonioMrtz Feb 24, 2024
2531406
chore : add recommended extensions
AntonioMrtz Feb 24, 2024
a1bbeab
chore : add recommended extensions
AntonioMrtz Feb 24, 2024
99482d9
fix : rename Debug Main to Debug Backend
AntonioMrtz Mar 10, 2024
7b644db
fix : add correct link readme frontend
AntonioMrtz Mar 10, 2024
5e42a8b
fix : rename Debug Main to Debug Backend
AntonioMrtz Mar 10, 2024
d5ee66b
fix : add docker compose build and up script
AntonioMrtz Mar 12, 2024
a8cb9dd
fix : add docker compose build and up script
AntonioMrtz Mar 12, 2024
aaf88b1
fix : add docker compose build and up script
AntonioMrtz Mar 17, 2024
adf49ea
Merge branch 'master-streaming' of https://github.com/AntonioMrtz/Spo…
AntonioMrtz Mar 17, 2024
f449d11
refactor : rename Backend API folder to Backend
AntonioMrtz Mar 17, 2024
485b0a5
chore : remove left test
AntonioMrtz Mar 17, 2024
686a016
Merge branch 'master-streaming-lambda' of https://github.com/AntonioM…
AntonioMrtz Mar 17, 2024
bab283b
chore : delete merge files
AntonioMrtz Mar 17, 2024
ffa5294
fix : solve migration problems son song service
AntonioMrtz Mar 17, 2024
795fdbf
Merge branch 'master-streaming-lambda' of https://github.com/AntonioM…
AntonioMrtz Mar 17, 2024
e506a7a
Merge pull request #106 from AntonioMrtz/master-migration
AntonioMrtz Mar 17, 2024
5cdd3aa
docs : Update API documentation
actions-user Mar 17, 2024
dddcd06
chore : remove unused debug one test config
AntonioMrtz Mar 17, 2024
10cd413
chore : remove lambda url from env example
AntonioMrtz Mar 17, 2024
fa1affd
docs : update build prod doc
AntonioMrtz Mar 17, 2024
48b5cba
Merge branch 'master-streaming-lambda' of https://github.com/AntonioM…
AntonioMrtz Mar 17, 2024
a077e20
Merge branch 'master-streaming' of https://github.com/AntonioMrtz/Spo…
AntonioMrtz Mar 17, 2024
fd0f894
ci : fix requirements dev path
AntonioMrtz Mar 17, 2024
21b546d
style : run black
AntonioMrtz Mar 17, 2024
3b7f3fd
Merge pull request #107 from AntonioMrtz/master-streaming-migration
AntonioMrtz Mar 17, 2024
1d8e23a
docs : Update API documentation
actions-user Mar 17, 2024
7832e1f
test : migrate backend tests folder to root
AntonioMrtz Mar 18, 2024
0a92cd7
test : migrate backend tests folder to root
AntonioMrtz Mar 18, 2024
5708f20
Merge pull request #109 from AntonioMrtz/test/Extract-Backend-Tests-F…
AntonioMrtz Mar 18, 2024
217806b
docs : update steps for run tests and generate docs
AntonioMrtz Mar 18, 2024
0a1fc62
docs : update steps for run tests and generate docs
AntonioMrtz Mar 18, 2024
ef8fa8b
refactor : move song_service from services to services.song_services
AntonioMrtz Mar 19, 2024
a1e038c
feat : integrate master-streaming
AntonioMrtz Mar 19, 2024
9b34f07
fix : remove search by name artist from master-streaming migration
AntonioMrtz Mar 19, 2024
3064296
Merge branch 'master' of https://github.com/AntonioMrtz/SpotifyElectr…
AntonioMrtz Mar 19, 2024
8c5fe7a
refactor : rename mongodb-blob to db-blob secondary architecture
AntonioMrtz Mar 19, 2024
be44651
style : run black and isort
AntonioMrtz Mar 22, 2024
9e1b285
docs : complete style backend code with isort
AntonioMrtz Mar 22, 2024
ca0e39b
chore : npm audit fix
AntonioMrtz Mar 22, 2024
09d645b
chore : delete unused init.py
AntonioMrtz Mar 22, 2024
7b84738
refactor : rename Player to PlayerStreaming
AntonioMrtz Mar 22, 2024
af86a33
feat : add lifespan handler to app start
AntonioMrtz Mar 22, 2024
07a3764
revert : remove lifespan_handler
AntonioMrtz Mar 22, 2024
41cac1a
chore : remove unused comment
AntonioMrtz Mar 22, 2024
8f724bd
Revert "revert : remove lifespan_handler"
AntonioMrtz Mar 23, 2024
50778fb
fix : on startup and teardown not deprecated
AntonioMrtz Mar 23, 2024
fc9eb09
feat : add PropertiesManager and its logic
AntonioMrtz Mar 23, 2024
d920bbf
docs : update docs with new env variables
AntonioMrtz Mar 23, 2024
648da5e
fix : backend test pipeline fix secrets
AntonioMrtz Mar 23, 2024
cda4e2e
feat : add dynamic song service depending on architecture
AntonioMrtz Mar 23, 2024
812838d
style : run black and isort
AntonioMrtz Mar 23, 2024
0db5819
ci : run streaming lambda and db blob tests on pipeline
AntonioMrtz Mar 23, 2024
b5127a5
ci : divide backend tests pipeline by architecture
AntonioMrtz Mar 23, 2024
b435c10
Revert "ci : divide backend tests pipeline by architecture"
AntonioMrtz Mar 23, 2024
6f7bc98
docs : add npm run build setup frontend
AntonioMrtz Mar 23, 2024
20c4443
test : add properties manager tests
AntonioMrtz Mar 23, 2024
8f2c447
refactor : make protected PropertiesManager load_architecture and loa…
AntonioMrtz Mar 24, 2024
dc35051
feat : add PlayerFiles for DB-BLOB architecture
AntonioMrtz Mar 24, 2024
e83ca32
test : fix properties manager tests by cleaning env in load arch no e…
AntonioMrtz Mar 24, 2024
a6bb938
docs : frontend select Music Player depending on architecture
AntonioMrtz Mar 24, 2024
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
14 changes: 13 additions & 1 deletion .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,27 @@ jobs:
working-directory: Backend
run: pip install -r requirements.txt && pip install -r requirements-test.txt

- name: Run tests
- name: Run tests Streaming lambda Architecture
working-directory: Backend/
run: python -m pytest .
env:
MONGO_URI : ${{ secrets.MONGO_URI }}
SECRET_KEY_SIGN : ${{ secrets.SECRET_KEY_SIGN }}
DISTRIBUTION_ID : ${{ secrets.DISTRIBUTION_ID }}
LAMBDA_URL : ${{ secrets.LAMBDA_URL }}
ARCH : "STREAMING_LAMBDA"
ENV_VALUE : "PROD"

- name: Run tests Database Blob Architecture
working-directory: Backend/
run: python -m pytest .
env:
MONGO_URI : ${{ secrets.MONGO_URI }}
SECRET_KEY_SIGN : ${{ secrets.SECRET_KEY_SIGN }}
DISTRIBUTION_ID : ${{ secrets.DISTRIBUTION_ID }}
LAMBDA_URL : ${{ secrets.LAMBDA_URL }}
ARCH : "DB_BLOB"
ENV_VALUE : "PROD"

- name: Fail workflow on test failure
if: ${{ failure() }}
Expand Down
2 changes: 2 additions & 0 deletions Backend/.env.example
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
2 changes: 1 addition & 1 deletion Backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]


#docker build -t spotify_electron_backend_image .
#docker run -d --name spotify_electron_backend -e MONGO_URI=mongo-uri SECRET_KEY_SIGN=secret-key-sign LAMBDA_URL=lambda-url -p 8000:8000 spotify_electron_backend_image
#docker run -d --name spotify_electron_backend -e MONGO_URI=mongo-uri SECRET_KEY_SIGN=secret-key-sign LAMBDA_URL=lambda-url ARCH=STREAMING_LAMBDA ENV_VALUE=PROD -p 8000:8000 spotify_electron_backend_image
1 change: 1 addition & 0 deletions Backend/requirements-test.txt
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 removed Backend/src/__init__.py
Empty file.
62 changes: 62 additions & 0 deletions Backend/src/boostrap/PropertiesManager.py
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()
15 changes: 15 additions & 0 deletions Backend/src/constants/set_up_constants.py
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"
4 changes: 4 additions & 0 deletions Backend/src/constants/song_service_set_up_constants.py
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"
5 changes: 3 additions & 2 deletions Backend/src/database/Database.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import os

from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from src.boostrap.PropertiesManager import PropertiesManager
from src.constants.set_up_constants import MONGO_URI_ENV_NAME

formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
logging.basicConfig(level=logging.WARNING)
Expand Down Expand Up @@ -42,7 +43,7 @@ class Database(metaclass=DatabaseMeta):
def __init__(self):
if Database.connection is None:
try:
uri = os.getenv("MONGO_URI")
uri = getattr(PropertiesManager, MONGO_URI_ENV_NAME)
Database.connection = MongoClient(uri, server_api=ServerApi("1"))[
"SpotifyElectron"
]
Expand Down
81 changes: 49 additions & 32 deletions Backend/src/main.py
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)
4 changes: 3 additions & 1 deletion Backend/src/middleware/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class CheckJwtAuth(BaseHTTPMiddleware):
bypass_methods = ["DELETE"]

def bypass_request(self, request: Request):
"""print(request.method)
"""
TODO clean
print(request.method)
print(request.url.path)
print(request.headers)"""
""" print(f"COOKIES = \n {request.cookies}")
Expand Down
2 changes: 0 additions & 2 deletions Backend/src/model/Playlist.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
from dataclasses import dataclass

import src.services.song_service as song_service


@dataclass
class Playlist:
Expand Down
20 changes: 20 additions & 0 deletions Backend/src/model/SongBlob.py
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
8 changes: 2 additions & 6 deletions Backend/src/routers/canciones.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@

import src.services.dto_service as dto_service
import src.services.security_service as security_service
import src.services.song_service as song_service_streaming
from fastapi import APIRouter, Header, HTTPException, UploadFile
from fastapi.responses import Response
from src.model.Genre import Genre
from src.services.song_services.song_service_provider import get_song_service

router = APIRouter(
prefix="/canciones",
tags=["canciones"],
)

""" if "pytest" in modules:
song_service = song_service_database

else: """
song_service = song_service_streaming
song_service = get_song_service()


@router.get("/{nombre}")
Expand Down
8 changes: 4 additions & 4 deletions Backend/src/services/all_users_service.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import src.services.artist_service as artist_service
import src.services.playlist_service as playlist_service
import src.services.song_service as song_service
import src.services.user_service as user_service
from fastapi import HTTPException
from src.model.TokenData import TokenData
from src.model.UserType import User_Type
from src.services.song_services.song_service_provider import get_song_service
from src.services.utils import checkValidParameterString

MAX_NUMBER_PLAYBACK_HISTORY_SONGS = 5

services_map = {
User_Type.USER: user_service,
User_Type.ARTIST: artist_service,
}


MAX_NUMBER_PLAYBACK_HISTORY_SONGS = 5
song_service = get_song_service()


def isArtistOrUser(user_name: str) -> User_Type or null:
Expand Down
7 changes: 5 additions & 2 deletions Backend/src/services/artist_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
from datetime import datetime
from sys import modules

import bcrypt
import src.services.song_service as song_service
from fastapi import HTTPException
from src.database.Database import Database
from src.model.Artist import Artist
from src.model.TokenData import TokenData
from src.services.song_services.song_service_provider import get_song_service
from src.services.utils import checkValidParameterString

if "pytest" in modules:
Expand All @@ -15,6 +16,8 @@
else:
artist_collection = Database().connection["artista"]

song_service = get_song_service()


def check_user_exists(user_name: str) -> bool:
"""Checks if the user or artists exists
Expand Down Expand Up @@ -397,7 +400,7 @@ def get_artists(names: list) -> list:
return artists


def search_by_name(name: str) -> list:
def search_by_name(name: str) -> json:
"""Returns a list of Artist that contains "name" in their names

Parameters
Expand Down
4 changes: 3 additions & 1 deletion Backend/src/services/dto_service.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from typing import List

import src.services.playlist_service as playlist_service
import src.services.song_service as song_service
from fastapi import HTTPException
from src.model.DTO.PlaylistDTO import PlaylistDTO
from src.model.DTO.SongDTO import SongDTO
from src.model.Genre import Genre
from src.services.song_services.song_service_provider import get_song_service
from src.services.utils import checkValidParameterString

song_service = get_song_service()


def get_song(name: str) -> SongDTO:
"""Returns a song's metadata without his audio file"
Expand Down
Loading