Доработан UI

This commit is contained in:
FrigaT
2026-04-14 14:33:43 +03:00
parent dcb2efbedb
commit 9e8bb0db75
8 changed files with 53 additions and 39 deletions

View File

@@ -1,16 +0,0 @@
using AutoMapper;
using PlaylistShared.Api.Entities;
using PlaylistShared.Shared.Auth;
using PlaylistShared.Shared.Shared;
namespace PlaylistShared.Api.Mapping;
public class AppMappingProfile : Profile
{
public AppMappingProfile()
{
CreateMap<SharedPlaylist, SharedPlaylistDto>()
.ForMember(dest => dest.Creator, opt => opt.MapFrom(src => src.Creator));
CreateMap<ApplicationUser, ApplicationUserDto>();
}
}

View File

@@ -10,7 +10,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper" Version="16.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="10.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.5" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.0.5" />

View File

@@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using PlaylistShared.Api.Data; using PlaylistShared.Api.Data;
using PlaylistShared.Api.Entities; using PlaylistShared.Api.Entities;
using PlaylistShared.Api.Mapping;
using PlaylistShared.Api.Services; using PlaylistShared.Api.Services;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using System.Text; using System.Text;
@@ -89,7 +88,6 @@ public class Program
builder.Services.AddHttpContextAccessor(); builder.Services.AddHttpContextAccessor();
builder.Services.AddAuthorization(); builder.Services.AddAuthorization();
builder.Services.AddAutoMapper(t => t.AddProfile<AppMappingProfile>());
builder.Services.AddScoped<JwtService>(); builder.Services.AddScoped<JwtService>();
builder.Services.AddScoped<UserSessionService>(); builder.Services.AddScoped<UserSessionService>();
builder.Services.AddScoped<YandexMusicService>(); builder.Services.AddScoped<YandexMusicService>();

View File

@@ -1,7 +1,7 @@
using AutoMapper; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using PlaylistShared.Api.Data; using PlaylistShared.Api.Data;
using PlaylistShared.Api.Entities; using PlaylistShared.Api.Entities;
using PlaylistShared.Shared.Auth;
using PlaylistShared.Shared.Enums; using PlaylistShared.Shared.Enums;
using PlaylistShared.Shared.Playlist; using PlaylistShared.Shared.Playlist;
using PlaylistShared.Shared.Shared; using PlaylistShared.Shared.Shared;
@@ -11,13 +11,11 @@ namespace PlaylistShared.Api.Services;
public class SharedPlaylistService public class SharedPlaylistService
{ {
private readonly ApplicationDbContext _db; private readonly ApplicationDbContext _db;
private readonly IMapper _mapper;
private readonly TrackAdditionLogService _trackLogService; private readonly TrackAdditionLogService _trackLogService;
public SharedPlaylistService(ApplicationDbContext db, IMapper mapper, TrackAdditionLogService trackLogService) public SharedPlaylistService(ApplicationDbContext db, TrackAdditionLogService trackLogService)
{ {
_db = db; _db = db;
_mapper = mapper;
_trackLogService = trackLogService; _trackLogService = trackLogService;
} }
@@ -42,7 +40,7 @@ public class SharedPlaylistService
}; };
_db.SharedPlaylists.Add(entity); _db.SharedPlaylists.Add(entity);
await _db.SaveChangesAsync(); await _db.SaveChangesAsync();
return _mapper.Map<SharedPlaylistDto>(entity); return MapToDto(entity);
} }
public async Task<SharedPlaylistDto?> GetByTokenAsync(string token) public async Task<SharedPlaylistDto?> GetByTokenAsync(string token)
@@ -50,7 +48,7 @@ public class SharedPlaylistService
var entity = await _db.SharedPlaylists var entity = await _db.SharedPlaylists
.Include(sp => sp.Creator) .Include(sp => sp.Creator)
.FirstOrDefaultAsync(sp => sp.ShareToken == token && !sp.IsDeleted); .FirstOrDefaultAsync(sp => sp.ShareToken == token && !sp.IsDeleted);
return entity == null ? null : _mapper.Map<SharedPlaylistDto>(entity); return entity == null ? null : MapToDto(entity);
} }
public async Task<SharedPlaylist?> GetEntityByTokenAsync(string token) public async Task<SharedPlaylist?> GetEntityByTokenAsync(string token)
@@ -70,7 +68,7 @@ public class SharedPlaylistService
entity.RemovePermission = dto.RemovePermission; entity.RemovePermission = dto.RemovePermission;
entity.UpdatedAt = DateTime.UtcNow; entity.UpdatedAt = DateTime.UtcNow;
await _db.SaveChangesAsync(); await _db.SaveChangesAsync();
return _mapper.Map<SharedPlaylistDto>(entity); return MapToDto(entity);
} }
public async Task<bool> DeleteAsync(Guid playlistId) public async Task<bool> DeleteAsync(Guid playlistId)
@@ -144,4 +142,36 @@ public class SharedPlaylistService
.Where(sp => sp.CreatorUserId == userId && !sp.IsDeleted) .Where(sp => sp.CreatorUserId == userId && !sp.IsDeleted)
.ToListAsync(); .ToListAsync();
} }
// Ручное маппинг сущности в DTO
private SharedPlaylistDto MapToDto(SharedPlaylist entity)
{
return new SharedPlaylistDto
{
Id = entity.Id,
CreatorUserId = entity.CreatorUserId,
YandexPlaylistUuid = entity.YandexPlaylistUuid,
YandexPlaylistKind = entity.YandexPlaylistKind,
YandexPlaylistOwnerUid = entity.YandexPlaylistOwnerUid,
Title = entity.Title,
Description = entity.Description,
CoverUrl = entity.CoverUrl,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
IsDeleted = entity.IsDeleted,
ShareToken = entity.ShareToken,
ViewPermission = entity.ViewPermission,
PlayPermission = entity.PlayPermission,
AddPermission = entity.AddPermission,
RemovePermission = entity.RemovePermission,
Creator = entity.Creator != null ? new ApplicationUserDto
{
Id = entity.Creator.Id,
UserName = entity.Creator.UserName ?? string.Empty,
Email = entity.Creator.Email,
YandexId = entity.Creator.YandexId,
DisplayName = entity.Creator.UserName
} : null
};
}
} }

View File

@@ -2,18 +2,23 @@
<AuthorizeView> <AuthorizeView>
<Authorized> <Authorized>
<MudText Typo="Typo.body2" Class="d-inline mr-2">Здравствуйте, @context.User.Identity?.Name!</MudText> <MudMenu Label="@context.User.Identity?.Name" Variant="Variant.Text" Color="Color.Inherit" Class="user-menu">
<MudButton Variant="Variant.Text" Color="Color.Inherit" OnClick="BeginLogOut">Выйти</MudButton> <MudMenuItem OnClick="GoToProfile">Профиль</MudMenuItem>
<MudMenuItem OnClick="BeginLogOut">Выйти</MudMenuItem>
</MudMenu>
</Authorized> </Authorized>
<NotAuthorized> <NotAuthorized>
<MudLink Href="/login" Color="Color.Inherit" Underline="Underline.Hover" Typo="Typo.body2">Вход</MudLink> <MudLink Href="/login" Color="Color.Inherit" Underline="Underline.Hover" Typo="Typo.body2">Вход</MudLink>
<MudText Class="d-inline mx-1">|</MudText>
<MudLink Href="/register" Color="Color.Inherit" Underline="Underline.Hover" Typo="Typo.body2">Регистрация</MudLink>
</NotAuthorized> </NotAuthorized>
</AuthorizeView> </AuthorizeView>
@code { @code {
public void BeginLogOut() private void GoToProfile()
{
Navigation.NavigateTo("/profile");
}
private void BeginLogOut()
{ {
Navigation.NavigateTo("/logout"); Navigation.NavigateTo("/logout");
} }

View File

@@ -4,7 +4,7 @@
<Authorized> <Authorized>
<MudNavLink Href="/profile" Icon="@Icons.Material.Filled.Person">Профиль</MudNavLink> <MudNavLink Href="/profile" Icon="@Icons.Material.Filled.Person">Профиль</MudNavLink>
<MudNavLink Href="/my-playlists" Icon="@Icons.Material.Filled.QueueMusic">Мои плейлисты</MudNavLink> <MudNavLink Href="/my-playlists" Icon="@Icons.Material.Filled.QueueMusic">Мои плейлисты</MudNavLink>
<MudNavLink Href="/favorites" Icon="@Icons.Material.Filled.Favorite">Избранное</MudNavLink> <MudNavLink Href="/favorites" Icon="@Icons.Material.Filled.Star">Избранное</MudNavLink>
</Authorized> </Authorized>
</AuthorizeView> </AuthorizeView>
</MudNavMenu> </MudNavMenu>

View File

@@ -1,6 +1,6 @@
@page "/favorites" @page "/favorites"
@using PlaylistShared.Shared.Shared
@attribute [Authorize] @attribute [Authorize]
@using PlaylistShared.Shared.DTO
@inject HttpClient Http @inject HttpClient Http
@inject ISnackbar Snackbar @inject ISnackbar Snackbar
@inject NavigationManager Navigation @inject NavigationManager Navigation
@@ -33,7 +33,6 @@
<HeaderContent> <HeaderContent>
<MudTh>Название</MudTh> <MudTh>Название</MudTh>
<MudTh>Владелец</MudTh> <MudTh>Владелец</MudTh>
<MudTh>Треков</MudTh>
<MudTh></MudTh> <MudTh></MudTh>
</HeaderContent> </HeaderContent>
<RowTemplate> <RowTemplate>
@@ -43,7 +42,6 @@
</MudLink> </MudLink>
</MudTd> </MudTd>
<MudTd DataLabel="Владелец">@context.Creator?.UserName</MudTd> <MudTd DataLabel="Владелец">@context.Creator?.UserName</MudTd>
<MudTd DataLabel="Треков">@context.TrackCount</MudTd>
<MudTd DataLabel=""> <MudTd DataLabel="">
<MudIconButton Icon="@Icons.Material.Filled.Delete" <MudIconButton Icon="@Icons.Material.Filled.Delete"
Color="Color.Error" Color="Color.Error"

View File

@@ -31,13 +31,13 @@
} }
<div> <div>
<div style="display: flex; align-items: center; gap: 8px;"> <div style="display: flex; align-items: center; gap: 8px;">
<MudLink Href="@($"https://music.yandex.ru/playlists/{_playlist.YandexPlaylistUuid}")" Target="_blank" Underline="Underline.Hover"> <MudLink Href="@($"https://music.yandex.ru/playlists/{_playlist.YandexPlaylistUuid}")" Typo="Typo.h5" Target="_blank" Underline="Underline.Hover">
@_playlist.Title @_playlist.Title
<MudIcon Icon="@Icons.Material.Filled.OpenInNew" Size="Size.Small" Class="ml-1" /> <MudIcon Icon="@Icons.Material.Filled.OpenInNew" Size="Size.Small" Class="ml-1" />
</MudLink> </MudLink>
<MudIconButton Icon="@(_isFavorite? Icons.Material.Filled.Favorite : Icons.Material.Outlined.FavoriteBorder)" <MudIconButton Icon="@(_isFavorite? Icons.Material.Filled.Star : Icons.Material.Outlined.StarBorder)"
Color="Color.Error" Color="Color.Warning"
OnClick="ToggleFavorite" OnClick="ToggleFavorite"
Disabled="_favoriteLoading" Disabled="_favoriteLoading"
Size="Size.Medium" /> Size="Size.Medium" />