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

Add first playlist challenge to entity manager #3736

Merged
merged 2 commits into from
Aug 22, 2022
Merged
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
21 changes: 21 additions & 0 deletions discovery-provider/src/tasks/entity_manager/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime
from typing import Dict, Set

from src.challenges.challenge_event import ChallengeEvent
from src.challenges.challenge_event_bus import ChallengeEventBus
from src.models.playlists.playlist import Playlist
from src.tasks.entity_manager.utils import (
PLAYLIST_ID_OFFSET,
Expand Down Expand Up @@ -79,6 +81,20 @@ def create_playlist(params: ManageEntityParameters):
)
params.add_playlist_record(playlist_id, create_playlist_record)

if tracks:
dispatch_challenge_playlist_upload(
params.challenge_bus, params.block_number, create_playlist_record
)


def dispatch_challenge_playlist_upload(
bus: ChallengeEventBus, block_number: int, playlist_record: Playlist
):
# Adds challenge for creating your first playlist and adding a track to it.
bus.dispatch(
ChallengeEvent.first_playlist, block_number, playlist_record.playlist_owner_id
)


def update_playlist(params: ManageEntityParameters):
validate_playlist_tx(params)
Expand All @@ -105,6 +121,11 @@ def update_playlist(params: ManageEntityParameters):
)
params.add_playlist_record(playlist_id, updated_playlist)

if updated_playlist.playlist_contents["track_ids"]:
dispatch_challenge_playlist_upload(
params.challenge_bus, params.block_number, updated_playlist
)


def delete_playlist(params: ManageEntityParameters):
validate_playlist_tx(params)
Expand Down