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

#227: Add Calculated field/property for artist total streams #241

Conversation

ErikMisencik
Copy link
Contributor

@ErikMisencik ErikMisencik commented Oct 3, 2024

Description

This PR refactor/implements the way total streams are calculated and retrieved for artists. Previously, artist total streams were fetched through a separate query via a dedicated endpoint (/artists/{name}/streams). With this update, total streams are now dynamically calculated as part of the artist data model (ArtistDAO and ArtistDTO) and retrieved directly through the main artist endpoint (/artists/{name}). As a result, redundant logic and endpoints related to fetching artist streams have been removed.
Additionally, the test for retrieving total streams has been updated to work with the new logic, ensuring proper functionality.

Commit type

  • refactor: refactoring production code, eg. renaming a variable

Issue

#227

Solution

Service

The dynamic calculation of total streams for an artist has been implemented within the ArtistDAO. The key changes are:

  • Added total_streams field: This field calculates the total streams from the artist’s uploaded songs dynamically when the artist data is fetched.
  • Updated get_artist_dao_from_document function: This function now calculates total_streams as part of the artist data, removing the need for a separate query or endpoint.
  • Deleted redundant services: Removed the get_artist_streams method from artist_service.py and base_song_service.py as it is no longer needed.

Endpoint

The following changes were made:

  • Removed /artists/{name}/streams endpoint: This API endpoint, which separately fetched an artist's total streams, has been removed as the total streams are now part of the artist data itself.

Tests

Tests have been updated to reflect the new logic for retrieving total streams:

  • Updated test: The test for retrieving an artist’s total streams now works with the new logic of fetching total streams through the main artist endpoint (/artists/{name}).

  • Removed redundant test: Any tests related to the /artists/{name}/streams endpoint were removed.

Proposed Changes

  • artist_service.py: Removed the get_streams_artist function.
  • base_song_service.py: Removed the get_artist_streams function.
  • artist_repository.py: Updated to include the total_streams field dynamically within ArtistDAO.
  • test_artist.py: Updated tests to verify that total_streams is returned correctly as part of the artist data.

Potential Impact

This change simplifies the API by consolidating all artist-related data into a single endpoint, improving both performance and maintainability. Users will no longer use a separate endpoint to fetch total streams.

Screenshots

In the screenshot, the artist "Ade" has two uploaded songs: "era" and "looop", with a total of 6 streams. The total streams are dynamically calculated and retrieved via the /artists/{name} endpoint, summing up streams from all uploaded songs.

{5622BEBC-F097-47E1-88EF-FB357DC84D63}

Additional Tasks

N/A

Assigned

@AntonioMrtz

@ErikMisencik ErikMisencik changed the title feat: Add Calculated field/property for artist total streams | [#227] refactor: Add Calculated field/property for artist total streams | [#227] Oct 3, 2024
@ErikMisencik ErikMisencik changed the title refactor: Add Calculated field/property for artist total streams | [#227] #227: Add Calculated field/property for artist total streams Oct 3, 2024
Copy link
Owner

@AntonioMrtz AntonioMrtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, everything looks good :). Take a look at the minor change I proposed. I have to adapt frontend side of this task, would you mind if I update your existing PR with that code I'm going to implement?

@ErikMisencik
Copy link
Contributor Author

ErikMisencik commented Oct 4, 2024

Hi, everything looks good :). Take a look at the minor change I proposed. I have to adapt frontend side of this task, would you mind if I update your existing PR with that code I'm going to implement?

It's fine, of course if it helps keep things better organized and adding frontend functionality won't take long, I'm fine with that. I like when PRs are completed and merged, at least from my side. @AntonioMrtz

@AntonioMrtz
Copy link
Owner

Hi again @ErikMisencik . Frontend uses get artist streams endpoint so it will break this functionality. I will push frontend changes this afternoon ( probably a one liner)

@AntonioMrtz
Copy link
Owner

Hi @ErikMisencik , I'm done with frontend changes. I also tested the changes with frontend client and everything looks good. Thanks for contributing and sharing your time with the project. I'm adding you into the contributors list in both the docs and readme :). I hope too see you soon in the project, are you looking for other issues to contribute?

@ErikMisencik
Copy link
Contributor Author

Hi @ErikMisencik , I'm done with frontend changes. I also tested the changes with frontend client and everything looks good. Thanks for contributing and sharing your time with the project. I'm adding you into the contributors list in both the docs and readme :). I hope too see you soon in the project, are you looking for other issues to contribute?

Also thank you for opportunity to help and solve issue. Right now i am more focused on University, it's my last year in Master degree. So maybe in future when I'll be less busy. For now I am glad that I could help you with project.

@AntonioMrtz
Copy link
Owner

AntonioMrtz commented Oct 4, 2024

Hi @ErikMisencik , I'm done with frontend changes. I also tested the changes with frontend client and everything looks good. Thanks for contributing and sharing your time with the project. I'm adding you into the contributors list in both the docs and readme :). I hope too see you soon in the project, are you looking for other issues to contribute?

Also thank you for opportunity to help and solve issue. Right now i am more focused on University, it's my last year in Master degree. So maybe in future when I'll be less busy. For now I am glad that I could help you with project.

Thanks a lot @ErikMisencik . Feel free to drop by the project whenever you want :). I wish you the best on your master's degree 👍

@AntonioMrtz AntonioMrtz merged commit ee29db0 into AntonioMrtz:master Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculated field/property for artists total streams
2 participants