Skip to content

Commit

Permalink
add black package for refactoring code, and add to CI/CD too.
Browse files Browse the repository at this point in the history
  • Loading branch information
MafanNam committed Jan 5, 2024
1 parent 962ac2e commit 8894a6d
Show file tree
Hide file tree
Showing 33 changed files with 1,530 additions and 871 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ jobs:
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET: ${{ secrets.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET }}
REDIS_CACHE_LOCATION: ${{ secrets.REDIS_CACHE_LOCATION }}
CELERY_BROKER_URL: ${{ secrets.CELERY_BROKER_URL }}
- name: Format with black
run: |
cd ./clone_sound_cloud
python -m black .
- name: Run Linting
run: |
cd ./clone_sound_cloud
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file docker/backend/Dockerfile --tag clone-cound-cloud:$(date +%s)
run: docker build . --file docker/backend/Dockerfile --tag clone-sound-cloud:$(date +%s)
56 changes: 37 additions & 19 deletions clone_sound_cloud/audio_library/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,64 @@

@admin.register(models.License)
class LicenseAdmin(admin.ModelAdmin):
list_display = ('id', 'user',)
list_display_links = ('user',)
list_filter = ('user',)
list_display = (
"id",
"user",
)
list_display_links = ("user",)
list_filter = ("user",)


@admin.register(models.Genre)
class GenreAdmin(admin.ModelAdmin):
list_display = ('id', 'name',)
list_display_links = ('name',)
list_display = (
"id",
"name",
)
list_display_links = ("name",)


@admin.register(models.Album)
class AlbumAdmin(admin.ModelAdmin):
list_display = ('id', 'user', 'name')
list_display_links = ('user',)
list_filter = ('user',)
list_display = ("id", "user", "name")
list_display_links = ("user",)
list_filter = ("user",)


@admin.register(models.Track)
class TrackAdmin(admin.ModelAdmin):
list_display = ('id', 'user', 'title', 'create_at')
list_display_links = ('user',)
list_filter = ('genre', 'create_at')
search_fields = ('user__email', 'user__user_profile__display_name', 'genre__name')
list_display = ("id", "user", "title", "create_at")
list_display_links = ("user",)
list_filter = ("genre", "create_at")
search_fields = ("user__email", "user__user_profile__display_name", "genre__name")


@admin.register(models.Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ('id', 'user', 'track')
list_display_links = ('user',)
list_display = ("id", "user", "track")
list_display_links = ("user",)


@admin.register(models.Playlist)
class PlaylistAdmin(admin.ModelAdmin):
list_display = ('id', 'user', 'title',)
list_display_links = ('user',)
search_fields = ('user__email', 'user__user_profile__display_name', 'track__title')
list_display = (
"id",
"user",
"title",
)
list_display_links = ("user",)
search_fields = ("user__email", "user__user_profile__display_name", "track__title")


@admin.register(models.PlayedUserTrack)
class PlayedUserTrackAdmin(admin.ModelAdmin):
list_display = ('id', 'user', 'track', 'played_at',)
list_display_links = ('id', 'user',)
list_display = (
"id",
"user",
"track",
"played_at",
)
list_display_links = (
"id",
"user",
)
60 changes: 50 additions & 10 deletions clone_sound_cloud/audio_library/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,31 @@ class BaseSerializer(serializers.ModelSerializer):
class GenreSerializer(BaseSerializer):
class Meta:
model = models.Genre
fields = ('id', 'name',)
fields = (
"id",
"name",
)


class LicenseSerializer(BaseSerializer):
class Meta:
model = models.License
fields = ('id', 'text',)
fields = (
"id",
"text",
)


class AlbumSerializer(BaseSerializer):
class Meta:
model = models.Album
fields = ('id', 'name', 'description', 'cover', 'private',)
fields = (
"id",
"name",
"description",
"cover",
"private",
)

def update(self, instance, validated_data):
delete_old_file(instance.cover.path)
Expand All @@ -39,11 +51,23 @@ class CreateAuthorTrackSerializer(BaseSerializer):
class Meta:
model = models.Track
fields = (
'id', 'title', 'license', 'genre', 'album', 'link_of_author',
'file', 'private', 'cover', 'create_at', 'plays_count', 'likes_count',
'download', 'user')
"id",
"title",
"license",
"genre",
"album",
"link_of_author",
"file",
"private",
"cover",
"create_at",
"plays_count",
"likes_count",
"download",
"user",
)
extra_kwargs = {
'likes_count': {'read_only': True},
"likes_count": {"read_only": True},
}

def update(self, instance, validated_data):
Expand All @@ -62,7 +86,12 @@ class AuthorTrackSerializer(CreateAuthorTrackSerializer):
class CreatePlayListSerializer(BaseSerializer):
class Meta:
model = models.Playlist
fields = ('id', 'title', 'cover', 'tracks',)
fields = (
"id",
"title",
"cover",
"tracks",
)

def update(self, instance, validated_data):
delete_old_file(instance.cover.path)
Expand All @@ -78,13 +107,24 @@ class CommentAuthorSerializer(serializers.ModelSerializer):

class Meta:
model = models.Comment
fields = ('id', 'text', 'track',)
fields = (
"id",
"text",
"track",
)


class CommentSerializer(serializers.ModelSerializer):
"""Comment serialize"""

user = AuthorSerializer(many=False)

class Meta:
model = models.Comment
fields = ('id', 'text', 'user', 'track', 'create_at',)
fields = (
"id",
"text",
"user",
"track",
"create_at",
)
134 changes: 85 additions & 49 deletions clone_sound_cloud/audio_library/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,91 @@

from . import views

app_name = 'audio'
app_name = "audio"

urlpatterns = [
path('genre/', views.GenreView.as_view(), name='genre'),

path('license/', views.LicenseView.as_view(
{'get': 'list', 'post': 'create'}), name='license'),
path('license/<int:pk>', views.LicenseView.as_view(
{'put': 'update', 'delete': 'destroy'}), name='license_detail'),

path('album/', views.AlbumView.as_view(
{'get': 'list', 'post': 'create'}), name='album'),
path('album/<int:pk>/', views.AlbumView.as_view(
{'put': 'update', 'delete': 'destroy'}), name='album_detail'),

path('author-album/<int:pk>/', views.PublicAlbumView.as_view(),
name='author_album'),

path('track/', views.TrackView.as_view(
{'get': 'list', 'post': 'create'}), name='track'),
path('track/<int:pk>/', views.TrackView.as_view({
'put': 'update', 'delete': 'destroy'}), name='track_detail'),
path('track/<int:pk>/like/', views.TrackLikeView.as_view(),
name='track_like'),
path('track/recently-played/', views.TrackRecentlyPlayedView.as_view(),
name='tracks_recently_played'),

path('stream-track/<int:pk>/', views.StreamingFileView.as_view(),
name='stream_track'),
path('stream-author-track/<int:pk>/', views.StreamingFileAuthorView.as_view(),
name='stream_author_track'),
path('download-track/<int:pk>/', views.DownloadTrackView.as_view(),
name='download_track'),

path('track-list/', views.TrackListView.as_view(), name='track_list'),
path('author-track-list/<int:pk>/', views.AuthorTrackListView.as_view(),
name='author_track_list'),

path('comments/', views.CommentAuthorView.as_view(
{'get': 'list', 'post': 'create'}), name='comments'),
path('comments/<int:pk>/', views.CommentAuthorView.as_view({
'put': 'update', 'delete': 'destroy'}), name='comments_detail'),

path('comments-by-track/<int:pk>/', views.CommentView.as_view(
{'get': 'list'}), name='comments_by_track'),

path('playlist/', views.PlayListView.as_view(
{'get': 'list', 'post': 'create'}), name='playlist'),
path('playlist/<int:pk>/', views.PlayListView.as_view(
{'put': 'update', 'delete': 'destroy'}), name='playlist_detail'),

path("genre/", views.GenreView.as_view(), name="genre"),
path(
"license/",
views.LicenseView.as_view({"get": "list", "post": "create"}),
name="license",
),
path(
"license/<int:pk>",
views.LicenseView.as_view({"put": "update", "delete": "destroy"}),
name="license_detail",
),
path(
"album/",
views.AlbumView.as_view({"get": "list", "post": "create"}),
name="album",
),
path(
"album/<int:pk>/",
views.AlbumView.as_view({"put": "update", "delete": "destroy"}),
name="album_detail",
),
path(
"author-album/<int:pk>/", views.PublicAlbumView.as_view(), name="author_album"
),
path(
"track/",
views.TrackView.as_view({"get": "list", "post": "create"}),
name="track",
),
path(
"track/<int:pk>/",
views.TrackView.as_view({"put": "update", "delete": "destroy"}),
name="track_detail",
),
path("track/<int:pk>/like/", views.TrackLikeView.as_view(), name="track_like"),
path(
"track/recently-played/",
views.TrackRecentlyPlayedView.as_view(),
name="tracks_recently_played",
),
path(
"stream-track/<int:pk>/", views.StreamingFileView.as_view(), name="stream_track"
),
path(
"stream-author-track/<int:pk>/",
views.StreamingFileAuthorView.as_view(),
name="stream_author_track",
),
path(
"download-track/<int:pk>/",
views.DownloadTrackView.as_view(),
name="download_track",
),
path("track-list/", views.TrackListView.as_view(), name="track_list"),
path(
"author-track-list/<int:pk>/",
views.AuthorTrackListView.as_view(),
name="author_track_list",
),
path(
"comments/",
views.CommentAuthorView.as_view({"get": "list", "post": "create"}),
name="comments",
),
path(
"comments/<int:pk>/",
views.CommentAuthorView.as_view({"put": "update", "delete": "destroy"}),
name="comments_detail",
),
path(
"comments-by-track/<int:pk>/",
views.CommentView.as_view({"get": "list"}),
name="comments_by_track",
),
path(
"playlist/",
views.PlayListView.as_view({"get": "list", "post": "create"}),
name="playlist",
),
path(
"playlist/<int:pk>/",
views.PlayListView.as_view({"put": "update", "delete": "destroy"}),
name="playlist_detail",
),
]
Loading

0 comments on commit 8894a6d

Please sign in to comment.