Skip to content

Commit

Permalink
Merge pull request #193 from AntonioMrtz/feat/190-custom-hooks-frontend
Browse files Browse the repository at this point in the history
#190: Custom Hooks Frontend
  • Loading branch information
AntonioMrtz authored Sep 7, 2024
2 parents 4788bde + 9feac1b commit 978fc76
Show file tree
Hide file tree
Showing 131 changed files with 3,784 additions and 1,709 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/eslintrc-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "master-*"

jobs:
build:
run-frontend-lint:
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-style-prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "master-*"

jobs:
build:
run-frontend-style-check:
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "master-*"

jobs:
build:
frontend-test:
runs-on: ubuntu-latest

steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Generate OpenAPI Schema
name: Generate OpenAPI Schema and Frontend Client

on:
pull_request:
types:
branches:
- closed

jobs:
generate-and-save-docs:
generate-openapi-schema-generate-frontend-client:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

Expand Down Expand Up @@ -36,13 +36,20 @@ jobs:
ARCH: BLOB
ENV_VALUE: PROD

- name: Generate OpenAPI client Frontend
working-directory: Electron/
run: |
npm install
npm run build
npm run generate-openapi-client
- name: Add and commit changes
working-directory: Electron/src/swagger/
working-directory: Electron/src/
run: |
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
git add openapi.json
if git commit -m "docs: Update OpenAPI Schema"; then
git add swagger/
if git commit -m "ci: Update OpenAPI schema and generate Frontend client"; then
echo "CHANGES=true" >> $GITHUB_ENV
else
echo "No changes to commit"
Expand All @@ -55,3 +62,22 @@ jobs:
with:
token: ${{ secrets.PAT }}
branch: ${{ github.base_ref }}

frontend-test:
runs-on: ubuntu-latest
needs: generate-openapi-schema-generate-frontend-client
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Change directory and run test
working-directory: Electron
run: |
npm install
npm run build
npm test
2 changes: 1 addition & 1 deletion .github/workflows/ruff-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- "master"
- "master-*"
jobs:
ruff:
ruff-format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ruff-lint-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- "master"
- "master-*"
jobs:
ruff:
ruff-lint-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions Backend/app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ async def lifespan_handler(app: FastAPI): # noqa: ANN201

app = FastAPI(
title=AppInfo.TITLE,
version=AppInfo.VERSION,
description=AppInfo.DESCRIPTION,
contact={
"name": AppInfo.CONTACT_NAME,
Expand Down
3 changes: 3 additions & 0 deletions Backend/app/common/app_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class AppInfo:
CONTACT_EMAIL = "antoniomartinezfernandez17@gmail.com"
LICENSE_INFO_NAME = "Attribution-NonCommercial-ShareAlike 4.0 International"
LICENSE_INFO_URL = "https://creativecommons.org/licenses/by-nc-sa/4.0/deed.es"
SERVER = [
{"url": "http://127.0.0.1:8000"}
] # may cause CORS on local development when using swagger


class AppConfig:
Expand Down
4 changes: 2 additions & 2 deletions Backend/app/exceptions/base_exceptions_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def __init__(self, message: str):
class BadParameterException(SpotifyElectronException):
"""Exception for bad parameter"""

def __init__(self, parameter_name: str):
def __init__(self, parameter_name: str | None = None):
self._set_parameter_name(parameter_name)
super().__init__(self.error)

def _set_parameter_name(self, item_name: str) -> None:
def _set_parameter_name(self, item_name: str | None) -> None:
self.error = f"Bad parameter: {item_name}"


Expand Down
4 changes: 2 additions & 2 deletions Backend/app/middleware/CheckJwtAuthMiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ async def _handle_jwt_validation(
----
jwt (str): the jwt token
request (Request): the incoming request
call_next (_type_): the method for continuing the workflow
call_next (Callable[[Any], Any]): the method for continuing the workflow
Returns:
-------
Response: the Response thats gonna be sended to the client,\
Response: the Response that's gonna be sended to the client,\
HTTP_403_FORBIDDEN if jwt is not valid
"""
Expand Down
1 change: 1 addition & 0 deletions Backend/app/resources/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ artist.bad.name = Artist with invalid name
song.not.found = Song was not found
song.bad.name = Song with invalid name
song.bad.file = Song with invalid file
song.already.exists = Song already exists
song.create.unauthorized.user = Song cannot be created by a user

[TOKEN]
Expand Down
4 changes: 2 additions & 2 deletions Backend/app/spotify_electron/playlist/playlist_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_playlist(
name: str,
token: Annotated[TokenData, Depends(JWTBearer())],
) -> Response:
"""Get playlsit
"""Get playlist
Args:
name (str): playlist name
Expand Down Expand Up @@ -207,7 +207,7 @@ def delete_playlist(name: str) -> Response:

@router.get("/")
def get_playlists(token: Annotated[TokenData, Depends(JWTBearer())]) -> Response:
"""Return all playlists"""
"""Get all playlists"""
try:
playlists = playlist_service.get_all_playlist()
playlist_json = json_converter_utils.get_json_with_iterable_field_from_model(
Expand Down
2 changes: 1 addition & 1 deletion Backend/app/spotify_electron/search/search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def search_by_name(name: str) -> SearchResult:
Raises:
BadParameterException: if the name is invalid
SearchServiceException: if unexpected error getting items by name
SearchServiceException: unexpected error getting items by name
Returns:
SearchResult: the items that partially match the name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import app.spotify_electron.song.aws.serverless_function.song_serverless_function_api as song_serverless_function_api # noqa: E501
import app.spotify_electron.song.base_song_repository as base_song_repository
import app.spotify_electron.user.artist.artist_service as artist_service
import app.spotify_electron.user.validations.base_user_service_validations as base_user_service
import app.spotify_electron.user.validations.base_user_service_validations as base_user_service_validations # noqa: E501
from app.auth.auth_schema import (
TokenData,
UserUnauthorizedException,
Expand All @@ -27,6 +27,7 @@
validate_song_deleting_streaming_response,
)
from app.spotify_electron.song.base_song_schema import (
SongAlreadyExistsException,
SongBadNameException,
SongNotFoundException,
SongRepositoryException,
Expand All @@ -38,7 +39,7 @@
validate_song_should_exists,
validate_song_should_not_exists,
)
from app.spotify_electron.user.artist.validations.artist_repository_validations import (
from app.spotify_electron.user.artist.validations.artist_service_validations import (
validate_user_should_be_artist,
)
from app.spotify_electron.user.user.user_schema import (
Expand Down Expand Up @@ -150,12 +151,10 @@ async def create_song( # noqa: C901

try:
validate_song_name_parameter(name)
base_user_service.validate_user_name_parameter(artist)
base_user_service_validations.validate_user_name_parameter(artist)
Genre.check_valid_genre(genre.value)

validate_song_should_not_exists(name)
base_user_service.validate_user_should_exists(artist)

validate_user_should_be_artist(artist)

song_duration = get_song_duration_seconds(name, file)
Expand All @@ -173,7 +172,7 @@ async def create_song( # noqa: C901
duration=song_duration,
genre=genre,
)
artist_service.add_song_artist(artist, name)
artist_service.add_song_to_artist(artist, name)
except GenreNotValidException as exception:
song_service_logger.exception(f"Bad genre provided {genre}")
raise GenreNotValidException from exception
Expand All @@ -189,6 +188,9 @@ async def create_song( # noqa: C901
except SongBadNameException as exception:
song_service_logger.exception(f"Bad Song Name Parameter: {name}")
raise SongBadNameException from exception
except SongAlreadyExistsException as exception:
song_service_logger.exception(f"Song already exists: {name}")
raise SongAlreadyExistsException from exception
except UserUnauthorizedException as exception:
song_service_logger.exception(
f"User {artist} cannot create song {name} because hes not artist"
Expand Down Expand Up @@ -234,7 +236,7 @@ def delete_song(name: str) -> None:

artist_name = base_song_repository.get_artist_from_song(name=name)

base_user_service.validate_user_should_exists(artist_name)
base_user_service_validations.validate_user_should_exists(artist_name)

artist_service.delete_song_from_artist(
artist_name,
Expand All @@ -251,6 +253,11 @@ def delete_song(name: str) -> None:
except UserNotFoundException as exception:
song_service_logger.exception(f"User {artist_name} not found")
raise UserNotFoundException from exception
except UserUnauthorizedException as exception:
song_service_logger.exception(
f"User {artist_name} cannot have song {name} removed because he's not an artist"
)
raise SongServiceException from exception
except SongRepositoryException as exception:
song_service_logger.exception(
f"Unexpected error in Song Repository deleting song: {name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def validate_song_creating_streaming_response(name: str, response: Response) ->
"""
if response.status_code != HTTP_201_CREATED:
song_service_logger.error(
f"Error retrieving Streaming url for song {name}"
f"Error retrieving Streaming url for song {name}\n"
f"Request Status {response.status_code} with Content {response.content}"
)
raise SongCreateSongStreamingException
Expand All @@ -50,7 +50,7 @@ def validate_get_song_url_streaming_response(name: str, response: Response) -> N
"""
if response.status_code != HTTP_200_OK:
song_service_logger.error(
f"Error retrieving Streaming url for song {name}"
f"Error retrieving Streaming url for song {name}\n"
f"Request Status {response.status_code} with Content {response.content}"
)
raise SongGetUrlStreamingException
Expand All @@ -68,7 +68,7 @@ def validate_song_deleting_streaming_response(name: str, response: Response) ->
"""
if response.status_code != HTTP_202_ACCEPTED:
song_service_logger.error(
f"Error retrieving Streaming url for song {name}"
f"Error retrieving Streaming url for song {name}\n"
f"Request Status {response.status_code} with Content {response.content}"
)
raise SongDeleteSongStreamingException
2 changes: 1 addition & 1 deletion Backend/app/spotify_electron/song/base_song_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(self):
class SongServiceException(SpotifyElectronException):
"""Exception for Song Service Unexpected Exceptions"""

ERROR = "Error accessing Song SERVICE"
ERROR = "Error accessing Song Service"

def __init__(self):
super().__init__(self.ERROR)
Expand Down
4 changes: 2 additions & 2 deletions Backend/app/spotify_electron/song/base_song_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import app.spotify_electron.song.base_song_repository as base_song_repository
import app.spotify_electron.user.validations.base_user_service_validations as base_user_service
import app.spotify_electron.user.validations.base_user_service_validations as base_user_service_validations # noqa: E501
from app.logging.logging_constants import LOGGING_BASE_SONG_SERVICE
from app.logging.logging_schema import SpotifyElectronLogger
from app.spotify_electron.genre.genre_schema import Genre, GenreNotValidException
Expand Down Expand Up @@ -173,7 +173,7 @@ def get_artist_streams(artist_name: str) -> int:
int: the number of streams for the artists songs
"""
try:
base_user_service.validate_user_should_exists(artist_name)
base_user_service_validations.validate_user_should_exists(artist_name)
return base_song_repository.get_artist_total_streams(artist_name)
except UserNotFoundException as exception:
base_song_service_logger.exception(f"User not found: {artist_name}")
Expand Down
Loading

0 comments on commit 978fc76

Please sign in to comment.